• Categories
    Category
  • Categories
    Category
  • News
  • Tutorials
  • Forums
  • Tags
  • Users
Tutorial Comments FAQ Related Articles

How to Manage Systemd Services and Units Using systemctl

761

To Manage Systemd Services and Units in Linux Using Systemctl

A collection of system management utilities, daemons, and libraries are called Systemd, that acts as a replacement of System V init daemon. To Manage Systemd Services and Units in Linux Using Systemctl is illustrated in this article.

Basics of Systemtd and Systemctl

To install systemctl and check version

Install systemctl on your system and know the version of presently installed Systemctl by using the following command.

[root@linuxhelp1 ~]# systemctl --version
systemd 208
+PAM +LIBWRAP +AUDIT +SELINUX +IMA +SYSVINIT +LIBCRYPTSETUP +GCRYPT +ACL +XZ

To Check the installation of libraries and binaries

Check the installation of libraries and binaries of systemctl and systemd.

[root@linuxhelp1 ~]# whereis systemd
systemd: /usr/lib/systemd /etc/systemd /usr/share/systemd /usr/share/man/man1/systemd.1.gz

[root@linuxhelp1 ~]# whereis systemctl
systemctl: /usr/bin/systemctl /usr/share/man/man1/systemctl.1.gz

To Check the execution of systemd

Execute the following command to check the execution of systemd

[root@linuxhelp1 ~]# ps -eaf | grep [s]ystemd
root         1     0  0 10:30 ?        00:00:02 /usr/lib/systemd/systemd --switched-root --system --deserialize 23
root       490     1  0 10:30 ?        00:00:00 /usr/lib/systemd/systemd-journald
root       524     1  0 10:30 ?        00:00:00 /usr/lib/systemd/systemd-udevd
root       667     1  0 10:30 ?        00:00:00 /usr/lib/systemd/systemd-logind
dbus       678     1  0 10:30 ?        00:00:00 /bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation
root      5104     1  0 10:31 ?        00:00:00 /usr/lib/systemd/systemd-localed
root     11685     1  0 10:32 ?        00:00:00 /usr/lib/systemd/systemd-hostnamed

To Analyze boot process of systemd with the following command.

[root@linuxhelp1 ~]# systemd-analyze 
Startup finished in 1.111s (kernel) + 3.632s (initrd) + 1min 54.534s (userspace) = 1min 59.278s

To Analyze the time span of every process at boot.

[root@linuxhelp1 ~]# systemd-analyze blame
    1min 33.336s kdump.service
         10.622s firstboot-graphical.service
          9.430s httpd.service
.
.
.
21ms sys-fs-fuse-connections.mount
            11ms sys-kernel-config.mount
            11ms systemd-update-utmp-runlevel.service

To Analyze complicated chain at boot

[root@linuxhelp1 ~]# systemd-analyze critical-chain
The time after the unit is active or started is printed after the " @"  character.
The time the unit takes to start is printed after the " +"  character.

graphical.target @1min 54.521s
??multi-user.target @1min 54.520s
  ??httpd.service @21.496s +9.430s
    ??network.target @21.182s
      ??network.service @19.135s +2.044s
        ??NetworkManager.service @18.223s +911ms
          ??firewalld.service @10.708s +7.512s
            ??basic.target @10.676s
              ??sockets.target @10.675s
                ??dbus.socket @10.674s
                  ??sysinit.target @10.554s
                    ??systemd-update-utmp.service @10.469s +25ms
                      ??systemd-tmpfiles-setup.service @10.006s +460ms
                        ??local-fs.target @10.000s
                          ??boot.mount @8.305s +1.693s
                            ??systemd-fsck@dev-disk-byx2duuid-d60ac2f0x2db83ex2d4cb2x2d9258x2db36698044a98.service @8.034s +268ms
                              ??dev-disk-byx2duuid-d60ac2f0x2db83ex2d4cb2x2d9258x2db36698044a98.device @8.028s

To list All the available units

All the available units are listed as follows

[root@linuxhelp1 ~]# systemctl list-unit-files
UNIT FILE                                   STATE   
proc-sys-fs-binfmt_misc.automount           static  
dev-hugepages.mount                         static  
dev-mqueue.mount                            static  
.
.
.
vsftpd.target                               disabled
systemd-readahead-done.timer                static  
systemd-tmpfiles-clean.timer                static

All running units are listed as follows,

[root@linuxhelp1 ~]# systemctl list-units
UNIT                                                      LOAD   ACTIVE SUB       DESCRIPTION
proc-sys-fs-binfmt_misc.automount                         loaded active waiting   Arbitrary Executable File Formats File System Automount Po
sys-devices-pci000...target1:0:0-1:0:0:0-block-sr0.device loaded active plugged   VMware_Virtual_IDE_CDROM_Drive
sys-devices-pci000...t2:0:0-2:0:0:0-block-sda-sda1.device loaded active plugged   VMware_Virtual_S
sys-devices-pci000...t2:0:0-2:0:0:0-block-sda-sda2.device loaded active plugged   VMware_Virtual_S
.
.
.
systemd-tmpfiles-clean.timer                              loaded active waiting   Daily Cleanup of Temporary Directories

LOAD   = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB    = The low-level unit activation state, values depend on unit type.

138 loaded units listed. Pass --all to see loaded but inactive units, too.

All failed units are listed as follows,

[root@linuxhelp1 ~]# systemctl --failed
UNIT                        LOAD   ACTIVE SUB    DESCRIPTION
firstboot-graphical.service loaded failed failed firstboot configuration program (graphical mode)
kdump.service               loaded failed failed Crash recovery kernel arming
rngd.service                loaded failed failed Hardware RNG Entropy Gatherer Daemon

LOAD   = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB    = The low-level unit activation state, values depend on unit type.

3 loaded units listed. Pass --all to see loaded but inactive units, too.

Check whether a Unit (cron.service) is enabled or not.

[root@linuxhelp1 ~]# systemctl is-enabled crond.service
enabled

Check if a Unit or Service is executing or not.

[root@linuxhelp1 ~]# systemctl status firewalld.service
firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service  enabled)
   Active: active (running) since Mon 2016-06-06 10:30:33 IST  18min ago
 Main PID: 636 (firewalld)
   CGroup: /system.slice/firewalld.service
           ??636 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid

Jun 06 10:30:33 linuxhelp systemd[1]: Started firewalld - dynamic firewall daemon.
[section label=" Management and Control of Services Using Systemctl" ]

Management and Control of Services Using Systemctl

All services are listed as follows (including enabled and disabled).

[root@linuxhelp1 ~]# systemctl list-unit-files --type=service
UNIT FILE                                   STATE   
abrt-ccpp.service                           enabled 
abrt-oops.service                           enabled 
abrt-pstoreoops.service                     disabled
.
.
.
wacom-inputattach@.service                  static  
wpa_supplicant.service                      disabled

225 unit files listed.

Starting, restarting, stopping, reloading and checking the status of an apache service.

[root@linuxhelp1 ~]# systemctl start httpd.service
[root@linuxhelp1 ~]# systemctl restart httpd.service
[root@linuxhelp1 ~]# systemctl stop httpd.service
[root@linuxhelp1 ~]# systemctl reload httpd.service
[root@linuxhelp1 ~]# systemctl status httpd.service
httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service  enabled)
   Active: active (running) since Mon 2016-06-06 10:52:32 IST  16s ago
     Docs: man:httpd(8)
           man:apachectl(8)
  Process: 12524 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=0/SUCCESS)
  Process: 12581 ExecReload=/usr/sbin/httpd $OPTIONS -k graceful (code=exited, status=0/SUCCESS)
 Main PID: 12569 (httpd)
   Status: " Total requests: 0  Current requests/sec: 0  Current traffic:   0 B/sec" 
   CGroup: /system.slice/httpd.service
           ??12569 /usr/sbin/httpd -DFOREGROUND
           ??12587 /usr/sbin/httpd -DFOREGROUND
           ??12588 /usr/sbin/httpd -DFOREGROUND
           ??12589 /usr/sbin/httpd -DFOREGROUND
           ??12590 /usr/sbin/httpd -DFOREGROUND
           ??12591 /usr/sbin/httpd -DFOREGROUND

Jun 06 10:52:32 linuxhelp1 systemd[1]: Starting The Apache HTTP Server...
Jun 06 10:52:32 linuxhelp1 systemd[1]: Started The Apache HTTP Server.
Jun 06 10:52:39 linuxhelp1 systemd[1]: Reloading The Apache HTTP Server.
Jun 06 10:52:39 linuxhelp1 systemd[1]: Reloaded The Apache HTTP Server.

Activation and enabling or disabling apache service at boot time.

[root@linuxhelp1 ~]# systemctl is-active httpd.service
active
[root@linuxhelp1 ~]# systemctl enable httpd.service
[root@linuxhelp1 ~]# systemctl disable httpd.service
rm ' /etc/systemd/system/multi-user.target.wants/httpd.service' 

Masking or unmasking apache service.

[root@linuxhelp1 ~]# systemctl mask httpd.service
ln -s ' /dev/null'  ' /etc/systemd/system/httpd.service' 
[root@linuxhelp1 ~]# systemctl unmask httpd.service
rm ' /etc/systemd/system/httpd.service' 

Killing a service with systemctl command

[root@linuxhelp1 ~]# systemctl kill httpd
[root@linuxhelp1 ~]# systemctl status httpd
httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service  disabled)
   Active: inactive (dead)
     Docs: man:httpd(8)
           man:apachectl(8)

Jun 06 10:52:08 linuxhelp1 systemd[1]: Starting The Apache HTTP Server...
Jun 06 10:52:09 linuxhelp1 systemd[1]: Started The Apache HTTP Server.
Jun 06 10:52:14 linuxhelp1 systemd[1]: Stopping The Apache HTTP Server...
Jun 06 10:52:15 linuxhelp1 systemd[1]: Stopped The Apache HTTP Server.
Jun 06 10:52:32 linuxhelp1 systemd[1]: Starting The Apache HTTP Server...
Jun 06 10:52:32 linuxhelp1 systemd[1]: Started The Apache HTTP Server.
Jun 06 10:52:39 linuxhelp1 systemd[1]: Reloading The Apache HTTP Server.
Jun 06 10:52:39 linuxhelp1 systemd[1]: Reloaded The Apache HTTP Server.
Jun 06 10:54:16 linuxhelp1 systemd[1]: httpd.service: Got notification message from PID 12569, but reception is disabled.
Jun 06 10:54:16 linuxhelp1 systemd[1]: httpd.service: Got notification message from PID 12569, but reception is disabled.

Management and Control of Mount Points using Systemctl

All system mount points are listed as follows.

[root@linuxhelp1 ~]# systemctl list-unit-files --type=mount
UNIT FILE                     STATE   
dev-hugepages.mount           static  
dev-mqueue.mount              static  
proc-fs-nfsd.mount            static  
proc-sys-fs-binfmt_misc.mount static  
sys-fs-fuse-connections.mount static  
sys-kernel-config.mount       static  
sys-kernel-debug.mount        static  
tmp.mount                     disabled
var-lib-nfs-rpc_pipefs.mount  static  

9 unit files listed.

Mounting, remounting, unmounting, and reloading system mount points and checking the status of system mount points.

[root@linuxhelp1 ~]# systemctl start tmp.mount
[root@linuxhelp1 ~]# systemctl stop tmp.mount
[root@linuxhelp1 ~]# systemctl restart tmp.mount
[root@linuxhelp1 ~]# systemctl reload tmp.mount
[root@linuxhelp1 ~]# systemctl status tmp.mount
tmp.mount - Temporary Directory
   Loaded: loaded (/usr/lib/systemd/system/tmp.mount  disabled)
   Active: active (mounted) since Mon 2016-06-06 10:57:00 IST  17s ago
    Where: /tmp
     What: tmpfs
     Docs: man:hier(7)
           http://www.freedesktop.org/wiki/Software/systemd/APIFileSystems
  Process: 12867 ExecRemount=/bin/mount tmpfs /tmp -t tmpfs -o remount,mode=1777,strictatime (code=exited, status=0/SUCCESS)
  Process: 12860 ExecMount=/bin/mount tmpfs /tmp -t tmpfs -o mode=1777,strictatime (code=exited, status=0/SUCCESS)

Jun 06 10:57:00 linuxhelp1 systemd[1]: Mounting Temporary Directory...
Jun 06 10:57:00 linuxhelp1 systemd[1]: tmp.mount: Directory /tmp to mount over is not empty, mounting anyway.
Jun 06 10:57:00 linuxhelp1 systemd[1]: Mounted Temporary Directory.
Jun 06 10:57:08 linuxhelp1 systemd[1]: Reloading Temporary Directory.
Jun 06 10:57:08 linuxhelp1 systemd[1]: Reloaded Temporary Directory.

Activating, enabling or disabling a mount point at boot time.

[root@linuxhelp1 ~]# systemctl is-active tmp.mount
active
[root@linuxhelp1 ~]# systemctl enable tmp.mount
ln -s ' /usr/lib/systemd/system/tmp.mount'  ' /etc/systemd/system/local-fs.target.wants/tmp.mount' 
[root@linuxhelp1 ~]# systemctl disable  tmp.mount
rm ' /etc/systemd/system/local-fs.target.wants/tmp.mount' 

Masking or unmasking mount points using systemctl

[root@linuxhelp1 ~]# systemctl unmask tmp.mount
rm ' /etc/systemd/system/tmp.mount' 

Management and Control of Sockets using Systemctl

All available system sockets are listed as follows.

[root@linuxhelp1 ~]# systemctl list-unit-files --type=socket
UNIT FILE                    STATE   
avahi-daemon.socket          enabled 
cups.socket                  enabled 
dbus.socket                  static  
dm-event.socket              enabled 
iscsid.socket                enabled 
iscsiuio.socket              enabled 
lvm2-lvmetad.socket          enabled 
rpcbind.socket               enabled 
rsyncd.socket                disabled
sshd.socket                  disabled
syslog.socket                static  
systemd-initctl.socket       static  
systemd-journald.socket      static  
systemd-shutdownd.socket     static  
systemd-udevd-control.socket static  
systemd-udevd-kernel.socket  static  
virtlockd.socket             disabled

17 unit files listed.

Starting, restarting, stopping, reloading and checking the socket status using Systemctl.

[root@linuxhelp1 ~]# systemctl start cups.socket
[root@linuxhelp1 ~]# systemctl stop cups.socket
[root@linuxhelp1 ~]# systemctl status cups.socket
cups.socket - CUPS Printing Service Sockets
   Loaded: loaded (/usr/lib/systemd/system/cups.socket  enabled)
   Active: inactive (dead) since Mon 2016-06-06 11:04:04 IST  6s ago
   Listen: /var/run/cups/cups.sock (Stream)

Jun 06 10:30:23 linuxhelp systemd[1]: Listening on CUPS Printing Service Sockets.
Jun 06 11:03:56 linuxhelp1 systemd[1]: Listening on CUPS Printing Service Sockets.
Jun 06 11:04:04 linuxhelp1 systemd[1]: Stopping CUPS Printing Service Sockets.
Jun 06 11:04:04 linuxhelp1 systemd[1]: Closed CUPS Printing Service Sockets.

Activation, enabling or disabling of a socket at boot time.

[root@linuxhelp1 ~]# systemctl is-active cups.socket
inactive
[root@linuxhelp1 ~]# systemctl enable cups.socket
[root@linuxhelp1 ~]# systemctl disable cups.socket
rm ' /etc/systemd/system/sockets.target.wants/cups.socket' 

Masking or unmasking a socket (cups.socket)

[root@linuxhelp1 ~]# systemctl mask cups.socket
ln -s ' /dev/null'  ' /etc/systemd/system/cups.socket' 
[root@linuxhelp1 ~]# systemctl unmask cups.socket
rm ' /etc/systemd/system/cups.socket' 

To get the current CPU shares of a service

[root@linuxhelp1 ~]# systemctl show -p CPUShares httpd.service
CPUShares=1024

To limit the CPU process

[root@linuxhelp1 ~]# systemctl set-property httpd.service CPUShares=4000
[root@linuxhelp1 ~]# systemctl show -p CPUShares httpd.service
CPUShares=4000

To Check configuration details of the service

[root@linuxhelp1 ~]# systemctl show httpd
Id=httpd.service
Names=httpd.service
Requires=basic.target
Wants=system.slice
.
.
.
xecMainPID=14055
ExecMainCode=0
ExecMainStatus=0

Analyze critical chain of the service

[root@linuxhelp1 ~]# systemd-analyze critical-chain httpd.service
The time after the unit is active or started is printed after the " @"  character.
The time the unit takes to start is printed after the " +"  character.

httpd.service +188ms
??network.target @21.182s
  ??network.service @19.135s +2.044s
    ??NetworkManager.service @18.223s +911ms
      ??firewalld.service @10.708s +7.512s
        ??basic.target @10.676s
          ??sockets.target @10.675s
            ??dbus.socket @10.674s
              ??sysinit.target @10.554s
                ??systemd-update-utmp.service @10.469s +25ms
                  ??systemd-tmpfiles-setup.service @10.006s +460ms
                    ??local-fs.target @10.000s
                      ??boot.mount @8.305s +1.693s
                        ??systemd-fsck@dev-disk-byx2duuid-d60ac2f0x2db83ex2d4cb2x2d9258x2db36698044a98.service @8.034s +268ms
                          ??systemd-fsck-root.service @4.754s +660ms
                            ??systemd-journald.socket
                              ??-.mount
                                ??system.slice
                                  ??-.slice 

To list dependencies for a service

[root@linuxhelp1 ~]# systemctl list-dependencies httpd.service
httpd.service
??system.slice
??basic.target
  ??alsa-restore.service
  ??alsa-state.service
  ??firewalld.service
  ??microcode.service
  ??rhel-autorelabel-mark.service
  ??rhel-autorelabel.service
  ??rhel-configure.service
.
.
.
? ??local-fs.target
  ? ? ??-.mount
  ? ? ??boot.mount
  ? ? ??rhel-import-state.service
  ? ? ??rhel-readonly.service
  ? ? ??systemd-fsck-root.service
  ? ? ??systemd-remount-fs.service
  ? ??swap.target
  ?   ??dev-disk-byx2dpath-pcix2d0000:00:10.0x2dscsix2d0:0:0:0x2dpart2.swap
  ?   ??dev-disk-byx2duuid-56594f7ex2de6bex2d49fdx2db0b3x2d2230651f1c3e.swap
  ?   ??dev-disk-byx2duuid-56594f7ex2de6bex2d49fdx2db0b3x2d2230651f1c3e.swap
  ?   ??dev-sda2.swap
  ??timers.target
    ??systemd-tmpfiles-clean.timer

List control group hierarchically

[root@linuxhelp1 ~]# systemd-cgls
??1 /usr/lib/systemd/systemd --switched-root --system --deserialize 23
??user.slice
? ??user-0.slice
?   ??session-1.scope
?     ??11154 gdm-session-worker [pam/gdm-password]
?     ??11163 /usr/bin/gnome-keyring-daemon --daemonize &ndash login
.
.
.
??iprdump.service
  ? ??729 /sbin/iprdump --daemon
  ??iprupdate.service
    ??713 /sbin/iprupdate &ndash daemon

To list control group according to CPU, memory, input and output

[root@linuxhelp1 ~]# systemd-cgtop
Path                                              Tasks  %CPU   Memory  Input/s Output/s

/                                                 283    20.6   665.1M   -        -
/system.slice                                     -      4.7    -        -        -
/system.slice/gdm.service                         3      4.6    -        -        -
/system.slice/vmtoolsd.service                    1      0.1    -        -        -
/system.slice/mariadb.service                     2      0.0    -        -        -
.
.
.
/system.slice/ksmtuned.service                    2      -      -        -        -
/system.slice/libstoragemgmt.service              1      -      -        -        -
/system.slice/libvirtd.service                    1      -      -        -        -

Control System Runlevels

To start system rescue mode

[root@linuxhelp1 ~]# systemctl rescue 

system rescue mode
To enter into emergency mode

[root@linuxhelp1 ~]# systemctl emergency

emergency mode

List current run level

[root@linuxhelp1 ~]# systemctl get-default
graphical.target

To start multiuser mode

[root@linuxhelp1 ~]# systemctl isolate runlevel3.target

multi-user mode
To start graphical mode

[root@linuxhelp1 ~]# systemctl isolate runlevel5.target

graphical mode

To set multiuser mode and graphical mode as default runlevel

[root@linuxhelp1 ~]# systemctl set-default graphical.target
[root@linuxhelp1 ~]# systemctl set-default multi-user.target

How to reboot, halt, suspend, hibernate or to put system in hybrid-sleep

[root@linuxhelp1 ~]# systemctl reboot
[root@linuxhelp1 ~]# systemctl halt
[root@linuxhelp1 ~]# systemctl suspend
[root@linuxhelp1 ~]#systemctl hibernate
[root@linuxhelp1 ~]# systemctl hybrid-sleep

Tags:
isaac
Author: 

Comments ( 0 )

No comments available

Add a comment

Frequently asked questions ( 5 )

Q

how to solve the following error?
" new service it's seems not working"

A

use the following command
" # systemctl daemon-reload" after creating new service

Q

which command to see all running services in linux?

A

use the following command to see the running services
# systemctl list-units

Q

what is the command to get list of failed services in linux?

A

use the following command to see failed services
# systemctl --failed

Q

How to Analyze the time span of every process at boot?

A

you can try the following command to analyze the time span
# systemd-analyze blame

Q

what command to list All the available units in linux?

A

use the following command to list all the available units
# systemctl list-unit-files

Related Tutorials in How to Manage Systemd Services and Units Using systemctl

Related Tutorials in How to Manage Systemd Services and Units Using systemctl

How to Manage Systemd Services and Units Using systemctl
How to Manage Systemd Services and Units Using systemctl
Jun 11, 2016
How to Create and Execute New Service in SystemD - Shell Script
How to Create and Execute New Service in SystemD - Shell Script
May 5, 2016
How To Configure and setup Systemd Service on Linux Mint 20.3
How To Configure and setup Systemd Service on Linux Mint 20.3
May 2, 2022

Related Forums in How to Manage Systemd Services and Units Using systemctl

Related Forums in How to Manage Systemd Services and Units Using systemctl

systemd
jacob class=
How could we allow non-root users to control a systemd service
Feb 7, 2020
Back To Top!
Rank
User
Points

Top Contributers

userNamenaveelansari
135850

Top Contributers

userNameayanbhatti
92510

Top Contributers

userNamehamzaahmed
32150

Top Contributers

1
userNamelinuxhelp
31040

Top Contributers

userNamemuhammadali
24500
Can you help Owen ?
How to add SSH key to my Gitlab account

I need to add the SSH key in my gitlab account. How to do so ????

Networking
  • Routing
  • trunk
  • Netmask
  • Packet Capture
  • domain
  • HTTP Proxy
Server Setup
  • NFS
  • KVM
  • Memory
  • Sendmail
  • WebDAV
  • LXC
Shell Commands
  • Cloud commander
  • Command line archive tools
  • last command
  • Shell
  • terminal
  • Throttle
Desktop Application
  • Linux app
  • Pithos
  • Retrospect
  • Scribe
  • TortoiseHg
  • 4Images
Monitoring Tool
  • Monit
  • Apache Server Monitoring
  • EtherApe 
  • Arpwatch Tool
  • Auditd
  • Barman
Web Application
  • Nutch
  • Amazon VPC
  • FarmWarDeployer
  • Rukovoditel
  • Mirror site
  • Chef
Contact Us | Terms of Use| Privacy Policy| Disclaimer
© 2025 LinuxHelp.com All rights reserved. Linux™ is the registered trademark of Linus Torvalds. This site is not affiliated with linus torvalds in any way.