Linux Systemd/Systemctl quick start guide

Systemd is an init system used by new Linux distributions like Ubuntu 15 and Centos 7. It intends to replace Sysv init (Ubuntu, Centos, etc) and upstart (Ubuntu).

Here are some handy Systemd/systemctl commands:

  1. List units
    $ sudo systemctl list-units ## all loaded units in active state
    $ sudo systemctl list-units -all ## all loaded units in any state
    $ sudo systemctl list-unit-files ## all installed units
    
  2. Check status of a service
    $ sudo systemctl status httpd
    httpd.service - The Apache HTTP Server
       Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled)
       Active: active (running) since Sun 2016-08-21 14:39:03 CEST; 9min ago
         Docs: man:httpd(8)
               man:apachectl(8)
     Main PID: 3095 (httpd)
       Status: "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec"
       CGroup: /system.slice/httpd.service
               ├─3095 /usr/sbin/httpd -DFOREGROUND
               ├─3096 /usr/sbin/httpd -DFOREGROUND
               ├─3097 /usr/sbin/httpd -DFOREGROUND
               ├─3098 /usr/sbin/httpd -DFOREGROUND
               ├─3099 /usr/sbin/httpd -DFOREGROUND
               └─3100 /usr/sbin/httpd -DFOREGROUND
    

    This outcome tells that httpd is currently running and it is active and hence will also start at boot time.

    To just see if service is active

    $ sudo systemctl is-active httpd
    active
    

    To just see if service is enabled (will start at boot time)

    $ sudo systemctl is-enabled httpd
    enabled
    
  3. Start a service
    $ sudo systemctl start httpd
    ## or
    $ sudo systemctl start httpd.service
    
  4. Re-start a service
    $ sudo systemctl restart httpd
    ## or
    $ sudo systemctl restart httpd.service
    
  5. Stop a service
    $ sudo systemctl stop httpd
    ## or
    $ sudo systemctl stop httpd.service
    
  6. Enable a service during boot
    $ sudo systemctl enable httpd
    ln -s '/usr/lib/systemd/system/httpd.service' '/etc/systemd/system/multi-user.target.wants/httpd.service'
    
  7. Disable a service during boot
    $ sudo systemctl disable httpd
    rm '/etc/systemd/system/multi-user.target.wants/httpd.service'
    
Share this article: share on Google+ share on facebook share on linkedin tweet this submit to reddit

Comments

Click here to write/view comments