{"id":13775,"date":"2019-04-06T03:20:24","date_gmt":"2019-04-06T03:20:24","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=13775"},"modified":"2019-04-06T03:20:24","modified_gmt":"2019-04-06T03:20:24","slug":"how-to-manage-systemd-services-and-units-using-systemctl-in-linux","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/06\/how-to-manage-systemd-services-and-units-using-systemctl-in-linux\/","title":{"rendered":"How to Manage \u2018Systemd\u2019 Services and Units Using \u2018Systemctl\u2019 in Linux"},"content":{"rendered":"<p><strong>Systemctl<\/strong>\u00a0is a\u00a0<strong>systemd<\/strong>\u00a0utility which is responsible for Controlling the\u00a0<strong>systemd<\/strong>\u00a0system and service manager.<\/p>\n<p><strong>Systemd<\/strong>\u00a0is a collection of system management daemons, utilities and libraries which serves as a replacement of\u00a0<strong>System V init<\/strong>\u00a0daemon. Systemd functions as central management and configuration platform for UNIX like system.<\/p>\n<p>In the Linux Ecosystem\u00a0<strong>Systemd<\/strong>\u00a0has been implemented on most of the standard Linux Distribution with a few exception. Systemd is the parent Process of all other daemons oftenly but not always.<\/p>\n<div id=\"attachment_13096\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/04\/Manage-Linux-Services-Using-Systemctl.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-13096\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/04\/Manage-Linux-Services-Using-Systemctl.jpg\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/04\/Manage-Linux-Services-Using-Systemctl.jpg 720w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/04\/Manage-Linux-Services-Using-Systemctl-620x297.jpg 620w\" alt=\"Manage Linux Services Using Systemctl\" width=\"620\" height=\"297\" aria-describedby=\"caption-attachment-13096\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-13096\" class=\"wp-caption-text\">Manage Linux Services Using Systemctl<\/p>\n<\/div>\n<p>This article aims at throwing light on \u201c<strong>How to control System and Services<\/strong>\u201d on a system running systemd.<\/p>\n<h3>Starting with Systemtd and Systemctl Basics<\/h3>\n<p><strong>1.<\/strong>\u00a0First check if\u00a0<strong>systemd<\/strong>\u00a0is installed on your system or not and what is the version of currently installed Systemd?<\/p>\n<pre># <strong>systemd --version<\/strong>\r\n\r\nsystemd 215\r\n+PAM +AUDIT +SELINUX +IMA +SYSVINIT +LIBCRYPTSETUP +GCRYPT +ACL +XZ -SECCOMP -APPARMOR\r\n<\/pre>\n<p>It\u2019s clear from the above example, that we have systemd\u00a0<strong>215<\/strong>\u00a0version Installed.<\/p>\n<p><strong>2.<\/strong>\u00a0Check where the binaries and libraries of\u00a0<strong>systemd<\/strong>\u00a0and\u00a0<strong>systemctl<\/strong>\u00a0are installed.<\/p>\n<pre># <strong>whereis systemd <\/strong>\r\nsystemd: \/usr\/lib\/systemd \/etc\/systemd \/usr\/share\/systemd \/usr\/share\/man\/man1\/systemd.1.gz\r\n\r\n\r\n# <strong>whereis systemctl<\/strong>\r\nsystemctl: \/usr\/bin\/systemctl \/usr\/share\/man\/man1\/systemctl.1.gz\r\n<\/pre>\n<p><strong>3.<\/strong>\u00a0Check whether\u00a0<strong>systemd<\/strong>\u00a0is running or not.<\/p>\n<pre># <strong>ps -eaf | grep [s]ystemd<\/strong>\r\n\r\nroot         1     0  0 16:27 ?        00:00:00 \/usr\/lib\/systemd\/systemd --switched-root --system --deserialize 23\r\nroot       444     1  0 16:27 ?        00:00:00 \/usr\/lib\/systemd\/systemd-journald\r\nroot       469     1  0 16:27 ?        00:00:00 \/usr\/lib\/systemd\/systemd-udevd\r\nroot       555     1  0 16:27 ?        00:00:00 \/usr\/lib\/systemd\/systemd-logind\r\ndbus       556     1  0 16:27 ?        00:00:00 \/bin\/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation\r\n<\/pre>\n<p><strong>Notice<\/strong>: systemd is running as parent daemon (<strong>PID=1<\/strong>). In the above command\u00a0<strong>ps<\/strong>\u00a0with (<strong>-e<\/strong>) select all Processes, (<strong>-a<\/strong>) select all processes except session leaders and (<strong>-f<\/strong>) for full format listing (i.e.\u00a0<strong>-eaf<\/strong>).<\/p>\n<p>Also note the square brackets in the above example and rest of the examples to follow. Square Bracket expression is part of grep\u2019s character class pattern matching.<\/p>\n<p><strong>4.<\/strong>\u00a0Analyze systemd boot process.<\/p>\n<pre># <strong>systemd-analyze<\/strong>\r\nStartup finished in 487ms (kernel) + 2.776s (initrd) + 20.229s (userspace) = 23.493s\r\n<\/pre>\n<p><strong>5.<\/strong>\u00a0Analyze time taken by each process at boot.<\/p>\n<pre># <strong>systemd-analyze blame<\/strong>\r\n\r\n8.565s mariadb.service\r\n7.991s webmin.service\r\n6.095s postfix.service\r\n4.311s httpd.service\r\n3.926s firewalld.service\r\n3.780s kdump.service\r\n3.238s tuned.service\r\n1.712s network.service\r\n1.394s lvm2-monitor.service\r\n1.126s systemd-logind.service\r\n....\r\n<\/pre>\n<p><strong>6.<\/strong>\u00a0Analyze critical chain at boot.<\/p>\n<pre># <strong>systemd-analyze critical-chain<\/strong>\r\n\r\nThe time after the unit is active or started is printed after the \"@\" character.\r\nThe time the unit takes to start is printed after the \"+\" character.\r\n\r\nmulti-user.target @20.222s\r\n\u2514\u2500mariadb.service @11.657s +8.565s\r\n  \u2514\u2500network.target @11.168s\r\n    \u2514\u2500network.service @9.456s +1.712s\r\n      \u2514\u2500NetworkManager.service @8.858s +596ms\r\n        \u2514\u2500firewalld.service @4.931s +3.926s\r\n          \u2514\u2500basic.target @4.916s\r\n            \u2514\u2500sockets.target @4.916s\r\n              \u2514\u2500dbus.socket @4.916s\r\n                \u2514\u2500sysinit.target @4.905s\r\n                  \u2514\u2500systemd-update-utmp.service @4.864s +39ms\r\n                    \u2514\u2500auditd.service @4.563s +301ms\r\n                      \u2514\u2500systemd-tmpfiles-setup.service @4.485s +69ms\r\n                        \u2514\u2500rhel-import-state.service @4.342s +142ms\r\n                          \u2514\u2500local-fs.target @4.324s\r\n                            \u2514\u2500boot.mount @4.286s +31ms\r\n                              \u2514\u2500systemd-fsck@dev-disk-by\\x2duuid-79f594ad\\x2da332\\x2d4730\\x2dbb5f\\x2d85d19608096\r\n                                \u2514\u2500dev-disk-by\\x2duuid-79f594ad\\x2da332\\x2d4730\\x2dbb5f\\x2d85d196080964.device @4\r\n<\/pre>\n<p><strong>Important<\/strong>: Systemctl accepts services (<strong>.service<\/strong>), mount point (<strong>.mount<\/strong>), sockets (<strong>.socket<\/strong>) and devices (<strong>.device<\/strong>) as units.<\/p>\n<p><strong>7.<\/strong>\u00a0List all the available units.<\/p>\n<pre># <strong>systemctl list-unit-files<\/strong>\r\n\r\nUNIT FILE                                   STATE   \r\nproc-sys-fs-binfmt_misc.automount           static  \r\ndev-hugepages.mount                         static  \r\ndev-mqueue.mount                            static  \r\nproc-sys-fs-binfmt_misc.mount               static  \r\nsys-fs-fuse-connections.mount               static  \r\nsys-kernel-config.mount                     static  \r\nsys-kernel-debug.mount                      static  \r\ntmp.mount                                   disabled\r\nbrandbot.path                               disabled\r\n.....\r\n<\/pre>\n<p><strong>8.<\/strong>\u00a0List all running units.<\/p>\n<pre># <strong>systemctl list-units<\/strong>\r\n\r\nUNIT                                        LOAD   ACTIVE SUB       DESCRIPTION\r\nproc-sys-fs-binfmt_misc.automount           loaded active waiting   Arbitrary Executable File Formats File Syste\r\nsys-devices-pc...0-1:0:0:0-block-sr0.device loaded active plugged   VBOX_CD-ROM\r\nsys-devices-pc...:00:03.0-net-enp0s3.device loaded active plugged   PRO\/1000 MT Desktop Adapter\r\nsys-devices-pc...00:05.0-sound-card0.device loaded active plugged   82801AA AC'97 Audio Controller\r\nsys-devices-pc...:0:0-block-sda-sda1.device loaded active plugged   VBOX_HARDDISK\r\nsys-devices-pc...:0:0-block-sda-sda2.device loaded active plugged   LVM PV Qzyo3l-qYaL-uRUa-Cjuk-pljo-qKtX-VgBQ8\r\nsys-devices-pc...0-2:0:0:0-block-sda.device loaded active plugged   VBOX_HARDDISK\r\nsys-devices-pl...erial8250-tty-ttyS0.device loaded active plugged   \/sys\/devices\/platform\/serial8250\/tty\/ttyS0\r\nsys-devices-pl...erial8250-tty-ttyS1.device loaded active plugged   \/sys\/devices\/platform\/serial8250\/tty\/ttyS1\r\nsys-devices-pl...erial8250-tty-ttyS2.device loaded active plugged   \/sys\/devices\/platform\/serial8250\/tty\/ttyS2\r\nsys-devices-pl...erial8250-tty-ttyS3.device loaded active plugged   \/sys\/devices\/platform\/serial8250\/tty\/ttyS3\r\nsys-devices-virtual-block-dm\\x2d0.device    loaded active plugged   \/sys\/devices\/virtual\/block\/dm-0\r\nsys-devices-virtual-block-dm\\x2d1.device    loaded active plugged   \/sys\/devices\/virtual\/block\/dm-1\r\nsys-module-configfs.device                  loaded active plugged   \/sys\/module\/configfs\r\n...\r\n<\/pre>\n<p><strong>9.<\/strong>\u00a0List all failed units.<\/p>\n<pre># <strong>systemctl --failed\r\n<\/strong>\r\nUNIT          LOAD   ACTIVE SUB    DESCRIPTION\r\nkdump.service loaded failed failed Crash recovery kernel arming\r\n\r\nLOAD   = Reflects whether the unit definition was properly loaded.\r\nACTIVE = The high-level unit activation state, i.e. generalization of SUB.\r\nSUB    = The low-level unit activation state, values depend on unit type.\r\n\r\n1 loaded units listed. Pass --all to see loaded but inactive units, too.\r\nTo show all installed unit files use 'systemctl list-unit-files'.\r\n<\/pre>\n<p><strong>10.<\/strong>\u00a0Check if a Unit (<strong>cron.service<\/strong>) is enabled or not?.<\/p>\n<pre># <strong>systemctl is-enabled crond.service<\/strong>\r\n\r\nenabled\r\n<\/pre>\n<p><strong>11.<\/strong>\u00a0Check whether a Unit or Service is running or not?.<\/p>\n<pre># <strong>systemctl status firewalld.service<\/strong>\r\n\r\nfirewalld.service - firewalld - dynamic firewall daemon\r\n   Loaded: loaded (\/usr\/lib\/systemd\/system\/firewalld.service; enabled)\r\n   Active: active (running) since Tue 2015-04-28 16:27:55 IST; 34min ago\r\n Main PID: 549 (firewalld)\r\n   CGroup: \/system.slice\/firewalld.service\r\n           \u2514\u2500549 \/usr\/bin\/python -Es \/usr\/sbin\/firewalld --nofork --nopid\r\n\r\nApr 28 16:27:51 tecmint systemd[1]: Starting firewalld - dynamic firewall daemon...\r\nApr 28 16:27:55 tecmint systemd[1]: Started firewalld - dynamic firewall daemon.\r\n<\/pre>\n<h3>Control and Manage Services Using Systemctl<\/h3>\n<p><strong>12.<\/strong>\u00a0List all services (including enabled and disabled).<\/p>\n<pre># <strong>systemctl list-unit-files --type=service<\/strong>\r\n\r\nUNIT FILE                                   STATE   \r\narp-ethers.service                          disabled\r\nauditd.service                              enabled \r\nautovt@.service                             disabled\r\nblk-availability.service                    disabled\r\nbrandbot.service                            static  \r\ncollectd.service                            disabled\r\nconsole-getty.service                       disabled\r\nconsole-shell.service                       disabled\r\ncpupower.service                            disabled\r\ncrond.service                               enabled \r\ndbus-org.fedoraproject.FirewallD1.service   enabled \r\n....\r\n<\/pre>\n<p><strong>13.<\/strong>\u00a0How do I start, restart, stop, reload and check the status of a service (<strong>httpd.service<\/strong>) in Linux.<\/p>\n<pre># <strong>systemctl start httpd.service<\/strong>\r\n# <strong>systemctl restart httpd.service<\/strong>\r\n# <strong>systemctl stop httpd.service<\/strong>\r\n# <strong>systemctl reload httpd.service<\/strong>\r\n# <strong>systemctl status httpd.service<\/strong>\r\n\r\nhttpd.service - The Apache HTTP Server\r\n   Loaded: loaded (\/usr\/lib\/systemd\/system\/httpd.service; enabled)\r\n   Active: <strong>active (running)<\/strong> since Tue 2015-04-28 17:21:30 IST; 6s ago\r\n  Process: 2876 ExecStop=\/bin\/kill -WINCH ${MAINPID} (code=exited, status=0\/SUCCESS)\r\n Main PID: 2881 (httpd)\r\n   Status: \"Processing requests...\"\r\n   CGroup: \/system.slice\/httpd.service\r\n           \u251c\u25002881 \/usr\/sbin\/httpd -DFOREGROUND\r\n           \u251c\u25002884 \/usr\/sbin\/httpd -DFOREGROUND\r\n           \u251c\u25002885 \/usr\/sbin\/httpd -DFOREGROUND\r\n           \u251c\u25002886 \/usr\/sbin\/httpd -DFOREGROUND\r\n           \u251c\u25002887 \/usr\/sbin\/httpd -DFOREGROUND\r\n           \u2514\u25002888 \/usr\/sbin\/httpd -DFOREGROUND\r\n\r\nApr 28 17:21:30 tecmint systemd[1]: Starting The Apache HTTP Server...\r\nApr 28 17:21:30 tecmint httpd[2881]: AH00558: httpd: Could not reliably determine the server's fully q...ssage\r\nApr 28 17:21:30 tecmint systemd[1]: Started The Apache HTTP Server.\r\nHint: Some lines were ellipsized, use -l to show in full.\r\n<\/pre>\n<p><strong>Note:<\/strong>\u00a0When we use commands like\u00a0<strong>start<\/strong>,\u00a0<strong>restart<\/strong>,\u00a0<strong>stop<\/strong>\u00a0and\u00a0<strong>reload<\/strong>\u00a0with systemctl, we will not get any output on the terminal, only\u00a0<strong>status<\/strong>\u00a0command will print the output.<\/p>\n<p><strong>14.<\/strong>\u00a0How to active a service and enable or disable a service at boot time (auto start service at system boot).<\/p>\n<pre># <strong>systemctl is-active httpd.service<\/strong>\r\n# <strong>systemctl enable httpd.service<\/strong>\r\n# <strong>systemctl disable httpd.service<\/strong>\r\n<\/pre>\n<p><strong>15.<\/strong>\u00a0How to mask (making it impossible to start) or unmask a service (<strong>httpd.service<\/strong>).<\/p>\n<pre># <strong>systemctl mask httpd.service<\/strong>\r\nln -s '\/dev\/null' '\/etc\/systemd\/system\/httpd.service'\r\n\r\n# <strong>systemctl unmask httpd.service<\/strong>\r\nrm '\/etc\/systemd\/system\/httpd.service'\r\n<\/pre>\n<p><strong>16.<\/strong>\u00a0How to a Kill a service using systemctl command.<\/p>\n<pre># <strong>systemctl kill httpd<\/strong>\r\n# <strong>systemctl status httpd<\/strong>\r\n\r\nhttpd.service - The Apache HTTP Server\r\n   Loaded: loaded (\/usr\/lib\/systemd\/system\/httpd.service; enabled)\r\n   Active: <strong>failed (Result: exit-code)<\/strong> since Tue 2015-04-28 18:01:42 IST; 28min ago\r\n Main PID: 2881 (code=exited, status=0\/SUCCESS)\r\n   Status: \"Total requests: 0; Current requests\/sec: 0; Current traffic:   0 B\/sec\"\r\n\r\nApr 28 17:37:29 tecmint systemd[1]: httpd.service: Got notification message from PID 2881, but recepti...bled.\r\nApr 28 17:37:29 tecmint systemd[1]: httpd.service: Got notification message from PID 2881, but recepti...bled.\r\nApr 28 17:37:39 tecmint systemd[1]: httpd.service: Got notification message from PID 2881, but recepti...bled.\r\nApr 28 17:37:39 tecmint systemd[1]: httpd.service: Got notification message from PID 2881, but recepti...bled.\r\nApr 28 17:37:49 tecmint systemd[1]: httpd.service: Got notification message from PID 2881, but recepti...bled.\r\nApr 28 17:37:49 tecmint systemd[1]: httpd.service: Got notification message from PID 2881, but recepti...bled.\r\nApr 28 17:37:59 tecmint systemd[1]: httpd.service: Got notification message from PID 2881, but recepti...bled.\r\nApr 28 17:37:59 tecmint systemd[1]: httpd.service: Got notification message from PID 2881, but recepti...bled.\r\nApr 28 18:01:42 tecmint systemd[1]: httpd.service: control process exited, code=exited status=226\r\nApr 28 18:01:42 tecmint systemd[1]: Unit httpd.service entered failed state.\r\nHint: Some lines were ellipsized, use -l to show in full.\r\n\r\n<\/pre>\n<h3>Control and Manage Mount Points using Systemctl<\/h3>\n<p><strong>17.<\/strong>\u00a0List all system mount points.<\/p>\n<pre># <strong>systemctl list-unit-files --type=mount<\/strong>\r\n\r\nUNIT FILE                     STATE   \r\ndev-hugepages.mount           static  \r\ndev-mqueue.mount              static  \r\nproc-sys-fs-binfmt_misc.mount static  \r\nsys-fs-fuse-connections.mount static  \r\nsys-kernel-config.mount       static  \r\nsys-kernel-debug.mount        static  \r\ntmp.mount                     disabled\r\n<\/pre>\n<p><strong>18<\/strong>. How do I mount, unmount, remount, reload system mount points and also check the status of mount points on the system.<\/p>\n<pre># <strong>systemctl start tmp.mount<\/strong>\r\n# <strong>systemctl stop tmp.mount<\/strong>\r\n# <strong>systemctl restart tmp.mount<\/strong>\r\n# <strong>systemctl reload tmp.mount<\/strong>\r\n# <strong>systemctl status tmp.mount<\/strong>\r\n\r\ntmp.mount - Temporary Directory\r\n   Loaded: loaded (\/usr\/lib\/systemd\/system\/tmp.mount; disabled)\r\n   Active: <strong>active (mounted)<\/strong> since Tue 2015-04-28 17:46:06 IST; 2min 48s ago\r\n    Where: \/tmp\r\n     What: tmpfs\r\n     Docs: man:hier(7)\r\n           http:\/\/www.freedesktop.org\/wiki\/Software\/systemd\/APIFileSystems\r\n  Process: 3908 ExecMount=\/bin\/mount tmpfs \/tmp -t tmpfs -o mode=1777,strictatime (code=exited, status=0\/SUCCESS)\r\n\r\nApr 28 17:46:06 tecmint systemd[1]: Mounting Temporary Directory...\r\nApr 28 17:46:06 tecmint systemd[1]: tmp.mount: Directory \/tmp to mount over is not empty, mounting anyway.\r\nApr 28 17:46:06 tecmint systemd[1]: Mounted Temporary Directory.\r\n<\/pre>\n<p><strong>19.<\/strong>\u00a0How to active, enable or disable a mount point at boot time (auto mount at system boot).<\/p>\n<pre># <strong>systemctl is-active tmp.mount<\/strong>\r\n# <strong>systemctl enable tmp.mount<\/strong>\r\n# <strong>systemctl disable  tmp.mount<\/strong>\r\n<\/pre>\n<p><strong>20.<\/strong>\u00a0How to mask (making it impossible to start) or unmask a mount points in Linux.<\/p>\n<pre># <strong>systemctl mask tmp.mount<\/strong>\r\n\r\nln -s '\/dev\/null' '\/etc\/systemd\/system\/tmp.mount'\r\n\r\n# <strong>systemctl unmask tmp.mount<\/strong>\r\n\r\nrm '\/etc\/systemd\/system\/tmp.mount'\r\n<\/pre>\n<h3>Control and Manage Sockets using Systemctl<\/h3>\n<p><strong>21.<\/strong>\u00a0List all available system sockets.<\/p>\n<pre># <strong>systemctl list-unit-files --type=socket<\/strong>\r\n\r\nUNIT FILE                    STATE   \r\ndbus.socket                  static  \r\ndm-event.socket              enabled \r\nlvm2-lvmetad.socket          enabled \r\nrsyncd.socket                disabled\r\nsshd.socket                  disabled\r\nsyslog.socket                static  \r\nsystemd-initctl.socket       static  \r\nsystemd-journald.socket      static  \r\nsystemd-shutdownd.socket     static  \r\nsystemd-udevd-control.socket static  \r\nsystemd-udevd-kernel.socket  static  \r\n\r\n11 unit files listed.\r\n<\/pre>\n<p><strong>22.<\/strong>\u00a0How do I start, restart, stop, reload and check the status of a socket (example:\u00a0<strong>cups.socket<\/strong>) in Linux.<\/p>\n<pre># <strong>systemctl start cups.socket<\/strong>\r\n# <strong>systemctl restart cups.socket<\/strong>\r\n# <strong>systemctl stop cups.socket<\/strong>\r\n# <strong>systemctl reload cups.socket<\/strong>\r\n# <strong>systemctl status cups.socket<\/strong>\r\n\r\ncups.socket - CUPS Printing Service Sockets\r\n   Loaded: loaded (\/usr\/lib\/systemd\/system\/cups.socket; enabled)\r\n   Active: <strong>active (listening)<\/strong> since Tue 2015-04-28 18:10:59 IST; 8s ago\r\n   Listen: \/var\/run\/cups\/cups.sock (Stream)\r\n\r\nApr 28 18:10:59 tecmint systemd[1]: Starting CUPS Printing Service Sockets.\r\nApr 28 18:10:59 tecmint systemd[1]: Listening on CUPS Printing Service Sockets.\r\n<\/pre>\n<p><strong>23.<\/strong>\u00a0How to active a socket and enable or disable at boot time (auto start socket at system boot).<\/p>\n<pre># <strong>systemctl is-active cups.socket<\/strong>\r\n# <strong>systemctl enable cups.socket<\/strong>\r\n# <strong>systemctl disable cups.socket<\/strong>\r\n<\/pre>\n<p><strong>24.<\/strong>\u00a0How to mask (making it impossible to start) or unmask a socket (cups.socket).<\/p>\n<pre># <strong>systemctl mask cups.socket<\/strong>\r\nln -s '\/dev\/null' '\/etc\/systemd\/system\/cups.socket'\r\n\r\n# <strong>systemctl unmask cups.socket<\/strong>\r\nrm '\/etc\/systemd\/system\/cups.socket'<\/pre>\n<h3>CPU Utilization (Shares) of a Service<\/h3>\n<p><strong>25.<\/strong>\u00a0Get the current CPU Shares of a Service (say httpd).<\/p>\n<pre># <strong>systemctl show -p CPUShares httpd.service<\/strong>\r\n\r\nCPUShares=1024\r\n<\/pre>\n<p><strong>Note<\/strong>: The default each service has a CPUShare =\u00a0<strong>1024<\/strong>. You may increase\/decrease CPU share of a process.<\/p>\n<p><strong>26.<\/strong>\u00a0Limit the CPU Share of a service (httpd.service) to\u00a0<strong>2000<\/strong>\u00a0CPUShares\/<\/p>\n<pre># <strong>systemctl set-property httpd.service CPUShares=2000<\/strong>\r\n# <strong>systemctl show -p CPUShares httpd.service<\/strong>\r\n\r\nCPUShares=2000\r\n<\/pre>\n<p><strong>Note<\/strong>: When you set\u00a0<strong>CPUShare<\/strong>\u00a0for a service, a directory with the name of service is created (<strong>httpd.service.d<\/strong>) which contains a file\u00a0<strong>90-CPUShares.conf<\/strong>\u00a0which contains the CPUShare Limit information. You may view the file as:<\/p>\n<pre># <strong>vi \/etc\/systemd\/system\/httpd.service.d\/90-CPUShares.conf<\/strong> \r\n\r\n[Service]\r\nCPUShares=2000        \r\n<\/pre>\n<p><strong>27.<\/strong>\u00a0Check all the configuration details of a service.<\/p>\n<pre># <strong>systemctl show httpd<\/strong>\r\n\r\nId=httpd.service\r\nNames=httpd.service\r\nRequires=basic.target\r\nWants=system.slice\r\nWantedBy=multi-user.target\r\nConflicts=shutdown.target\r\nBefore=shutdown.target multi-user.target\r\nAfter=network.target remote-fs.target nss-lookup.target systemd-journald.socket basic.target system.slice\r\nDescription=The Apache HTTP Server\r\nLoadState=loaded\r\nActiveState=active\r\nSubState=running\r\nFragmentPath=\/usr\/lib\/systemd\/system\/httpd.service\r\n....\r\n<\/pre>\n<p><strong>28.<\/strong>\u00a0Analyze critical chain for a services(httpd).<\/p>\n<pre># <strong>systemd-analyze critical-chain httpd.service<\/strong>\r\n\r\nThe time after the unit is active or started is printed after the \"@\" character.\r\nThe time the unit takes to start is printed after the \"+\" character.\r\n\r\nhttpd.service +142ms\r\n\u2514\u2500network.target @11.168s\r\n  \u2514\u2500network.service @9.456s +1.712s\r\n    \u2514\u2500NetworkManager.service @8.858s +596ms\r\n      \u2514\u2500firewalld.service @4.931s +3.926s\r\n        \u2514\u2500basic.target @4.916s\r\n          \u2514\u2500sockets.target @4.916s\r\n            \u2514\u2500dbus.socket @4.916s\r\n              \u2514\u2500sysinit.target @4.905s\r\n                \u2514\u2500systemd-update-utmp.service @4.864s +39ms\r\n                  \u2514\u2500auditd.service @4.563s +301ms\r\n                    \u2514\u2500systemd-tmpfiles-setup.service @4.485s +69ms\r\n                      \u2514\u2500rhel-import-state.service @4.342s +142ms\r\n                        \u2514\u2500local-fs.target @4.324s\r\n                          \u2514\u2500boot.mount @4.286s +31ms\r\n                            \u2514\u2500systemd-fsck@dev-disk-by\\x2duuid-79f594ad\\x2da332\\x2d4730\\x2dbb5f\\x2d85d196080964.service @4.092s +149ms\r\n                              \u2514\u2500dev-disk-by\\x2duuid-79f594ad\\x2da332\\x2d4730\\x2dbb5f\\x2d85d196080964.device @4.092s\r\n<\/pre>\n<p><strong>29.<\/strong>\u00a0Get a list of dependencies for a services (httpd).<\/p>\n<pre># <strong>systemctl list-dependencies httpd.service<\/strong>\r\n\r\nhttpd.service\r\n\u251c\u2500system.slice\r\n\u2514\u2500basic.target\r\n  \u251c\u2500firewalld.service\r\n  \u251c\u2500microcode.service\r\n  \u251c\u2500rhel-autorelabel-mark.service\r\n  \u251c\u2500rhel-autorelabel.service\r\n  \u251c\u2500rhel-configure.service\r\n  \u251c\u2500rhel-dmesg.service\r\n  \u251c\u2500rhel-loadmodules.service\r\n  \u251c\u2500paths.target\r\n  \u251c\u2500slices.target\r\n  \u2502 \u251c\u2500-.slice\r\n  \u2502 \u2514\u2500system.slice\r\n  \u251c\u2500sockets.target\r\n  \u2502 \u251c\u2500dbus.socket\r\n....\r\n<\/pre>\n<p><strong>30.<\/strong>\u00a0List control groups hierarchically.<\/p>\n<pre># <strong>systemd-cgls<\/strong>\r\n\r\n\u251c\u25001 \/usr\/lib\/systemd\/systemd --switched-root --system --deserialize 23\r\n\u251c\u2500user.slice\r\n\u2502 \u2514\u2500user-0.slice\r\n\u2502   \u2514\u2500session-1.scope\r\n\u2502     \u251c\u25002498 sshd: root@pts\/0    \r\n\u2502     \u251c\u25002500 -bash\r\n\u2502     \u251c\u25004521 systemd-cgls\r\n\u2502     \u2514\u25004522 systemd-cgls\r\n\u2514\u2500system.slice\r\n  \u251c\u2500httpd.service\r\n  \u2502 \u251c\u25004440 \/usr\/sbin\/httpd -DFOREGROUND\r\n  \u2502 \u251c\u25004442 \/usr\/sbin\/httpd -DFOREGROUND\r\n  \u2502 \u251c\u25004443 \/usr\/sbin\/httpd -DFOREGROUND\r\n  \u2502 \u251c\u25004444 \/usr\/sbin\/httpd -DFOREGROUND\r\n  \u2502 \u251c\u25004445 \/usr\/sbin\/httpd -DFOREGROUND\r\n  \u2502 \u2514\u25004446 \/usr\/sbin\/httpd -DFOREGROUND\r\n  \u251c\u2500polkit.service\r\n  \u2502 \u2514\u2500721 \/usr\/lib\/polkit-1\/polkitd --no-debug\r\n....\r\n<\/pre>\n<p><strong>31.<\/strong>\u00a0List control group according to CPU, memory, Input and Output.<\/p>\n<pre># <strong>systemd-cgtop<\/strong>\r\n\r\nPath                                                              Tasks   %CPU   Memory  Input\/s Output\/s\r\n\r\n\/                                                                    83    1.0   437.8M        -        -\r\n\/system.slice                                                         -    0.1        -        -        -\r\n\/system.slice\/mariadb.service                                         2    0.1        -        -        -\r\n\/system.slice\/tuned.service                                           1    0.0        -        -        -\r\n\/system.slice\/httpd.service                                           6    0.0        -        -        -\r\n\/system.slice\/NetworkManager.service                                  1      -        -        -        -\r\n\/system.slice\/atop.service                                            1      -        -        -        -\r\n\/system.slice\/atopacct.service                                        1      -        -        -        -\r\n\/system.slice\/auditd.service                                          1      -        -        -        -\r\n\/system.slice\/crond.service                                           1      -        -        -        -\r\n\/system.slice\/dbus.service                                            1      -        -        -        -\r\n\/system.slice\/firewalld.service                                       1      -        -        -        -\r\n\/system.slice\/lvm2-lvmetad.service                                    1      -        -        -        -\r\n\/system.slice\/polkit.service                                          1      -        -        -        -\r\n\/system.slice\/postfix.service                                         3      -        -        -        -\r\n\/system.slice\/rsyslog.service                                         1      -        -        -        -\r\n\/system.slice\/system-getty.slice\/getty@tty1.service                   1      -        -        -        -\r\n\/system.slice\/systemd-journald.service                                1      -        -        -        -\r\n\/system.slice\/systemd-logind.service                                  1      -        -        -        -\r\n\/system.slice\/systemd-udevd.service                                   1      -        -        -        -\r\n\/system.slice\/webmin.service                                          1      -        -        -        -\r\n\/user.slice\/user-0.slice\/session-1.scope                              3      -        -        -        -\r\n<\/pre>\n<h3>Control System Runlevels<\/h3>\n<p><strong>32.<\/strong>\u00a0How to start system rescue mode.<\/p>\n<pre># <strong>systemctl rescue<\/strong>\r\n\r\nBroadcast message from root@tecmint on pts\/0 (Wed 2015-04-29 11:31:18 IST):\r\n\r\nThe system is going down to rescue mode NOW!\r\n<\/pre>\n<p><strong>33.<\/strong>\u00a0How to enter into emergency mode.<\/p>\n<pre># <strong>systemctl emergency<\/strong>\r\n\r\nWelcome to emergency mode! After logging in, type \"journalctl -xb\" to view\r\nsystem logs, \"systemctl reboot\" to reboot, \"systemctl default\" to try again\r\nto boot into default mode.\r\n<\/pre>\n<p><strong>34.<\/strong>\u00a0List current run levels in use.<\/p>\n<pre># <strong>systemctl get-default<\/strong>\r\n\r\nmulti-user.target\r\n<\/pre>\n<p><strong>35.<\/strong>\u00a0How to start Runlevel 5 aka graphical mode.<\/p>\n<pre># <strong>systemctl isolate runlevel5.target<\/strong>\r\nOR\r\n# <strong>systemctl isolate graphical.target<\/strong>\r\n<\/pre>\n<p><strong>36.<\/strong>\u00a0How to start Runlevel 3 aka multiuser mode (commandline).<\/p>\n<pre># <strong>systemctl isolate runlevel3.target<\/strong>\r\nOR\r\n# <strong>systemctl isolate multiuser.target<\/strong>\r\n<\/pre>\n<p><strong>36.<\/strong>\u00a0How to set multiusermode or graphical mode as default runlevel.<\/p>\n<pre># <strong>systemctl set-default runlevel3.target<\/strong>\r\n\r\n# <strong>systemctl set-default runlevel5.target<\/strong>\r\n<\/pre>\n<p><strong>37.<\/strong>\u00a0How to reboot, halt, suspend, hibernate or put system in hybrid-sleep.<\/p>\n<pre># <strong>systemctl reboot<\/strong>\r\n\r\n# <strong>systemctl halt<\/strong>\r\n\r\n# <strong>systemctl suspend<\/strong>\r\n\r\n# <strong>systemctl hibernate<\/strong>\r\n\r\n# <strong>systemctl hybrid-sleep<\/strong>\r\n<\/pre>\n<p>For those who may not be aware of runlevels and what it does.<\/p>\n<ol>\n<li><strong>Runlevel 0<\/strong>\u00a0: Shut down and Power off the system.<\/li>\n<li><strong>Runlevel 1<\/strong>\u00a0: Rescue?Maintainance Mode.<\/li>\n<li><strong>Runlevel 3<\/strong>\u00a0: multiuser, no-graphic system.<\/li>\n<li><strong>Runlevel 4<\/strong>\u00a0: multiuser, no-graphic system.<\/li>\n<li><strong>Runlevel 5<\/strong>\u00a0: multiuser, graphical system.<\/li>\n<li><strong>Runlevel 6<\/strong>\u00a0: Shutdown and Reboot the machine.<\/li>\n<\/ol>\n<p>That\u2019s all for now. Keep connected! Keep commenting. Don\u2019t forget to provide us with your valuable feedback in the comments below. Like and share us and help us get spread.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/manage-services-using-systemd-and-systemctl-in-linux\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Systemctl\u00a0is a\u00a0systemd\u00a0utility which is responsible for Controlling the\u00a0systemd\u00a0system and service manager. Systemd\u00a0is a collection of system management daemons, utilities and libraries which serves as a replacement of\u00a0System V init\u00a0daemon. Systemd functions as central management and configuration platform for UNIX like system. In the Linux Ecosystem\u00a0Systemd\u00a0has been implemented on most of the standard Linux Distribution with &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/06\/how-to-manage-systemd-services-and-units-using-systemctl-in-linux\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to Manage \u2018Systemd\u2019 Services and Units Using \u2018Systemctl\u2019 in Linux&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-13775","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13775","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=13775"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13775\/revisions"}],"predecessor-version":[{"id":13777,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13775\/revisions\/13777"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=13775"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=13775"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=13775"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}