How to Manage ‘Systemd’ Services and Units Using ‘Systemctl’ in Linux

CPU Utilization (Shares) of a Service

25. Get the current CPU Shares of a Service (say httpd).

# systemctl show -p CPUShares httpd.service


Note: The default each service has a CPUShare = 1024. You may increase/decrease the CPU share of a process.

26. Limit the CPU Share of a service (httpd.service) to 2000 CPUShares/

# systemctl set-property httpd.service CPUShares=2000
# systemctl show -p CPUShares httpd.service


Note: When you set CPUShare for a service, a directory with the name of service is created (httpd.service.d) which contains a file 90-CPUShares.conf which contains the CPUShare Limit information. You may view the file as:

# vi /etc/systemd/system/httpd.service.d/90-CPUShares.conf 


27. Check all the configuration details of a service.

# systemctl show httpd

Wants=system.slice systemd-journald.socket system.slice
Description=The Apache HTTP Server

28. Analyze critical chain for a service (httpd).

# 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 +142ms
└─ @11.168s
  └─network.service @9.456s +1.712s
    └─NetworkManager.service @8.858s +596ms
      └─firewalld.service @4.931s +3.926s
        └─ @4.916s
          └─ @4.916s
            └─dbus.socket @4.916s
              └─ @4.905s
                └─systemd-update-utmp.service @4.864s +39ms
                  └─auditd.service @4.563s +301ms
                    └─systemd-tmpfiles-setup.service @4.485s +69ms
                      └─rhel-import-state.service @4.342s +142ms
                        └─ @4.324s
                          └─boot.mount @4.286s +31ms
                            └─[email protected]\x2duuid-79f594ad\x2da332\x2d4730\x2dbb5f\x2d85d196080964.service @4.092s +149ms
                              └─dev-disk-by\x2duuid-79f594ad\x2da332\x2d4730\x2dbb5f\x2d85d196080964.device @4.092s

29. Get a list of dependencies for a service (httpd).

# systemctl list-dependencies httpd.service

  │ ├─-.slice
  │ └─system.slice
  │ ├─dbus.socket

30. List control groups hierarchically.

# systemd-cgls

├─1 /usr/lib/systemd/systemd --switched-root --system --deserialize 23
│ └─user-0.slice
│   └─session-1.scope
│     ├─2498 sshd: [email protected]/0    
│     ├─2500 -bash
│     ├─4521 systemd-cgls
│     └─4522 systemd-cgls
  │ ├─4440 /usr/sbin/httpd -DFOREGROUND
  │ ├─4442 /usr/sbin/httpd -DFOREGROUND
  │ ├─4443 /usr/sbin/httpd -DFOREGROUND
  │ ├─4444 /usr/sbin/httpd -DFOREGROUND
  │ ├─4445 /usr/sbin/httpd -DFOREGROUND
  │ └─4446 /usr/sbin/httpd -DFOREGROUND
  │ └─721 /usr/lib/polkit-1/polkitd --no-debug

31. List control group according to CPU, memory, Input, and Output.

# systemd-cgtop

Path                                                              Tasks   %CPU   Memory  Input/s Output/s

/                                                                    83    1.0   437.8M        -        -
/system.slice                                                         -    0.1        -        -        -
/system.slice/mariadb.service                                         2    0.1        -        -        -
/system.slice/tuned.service                                           1    0.0        -        -        -
/system.slice/httpd.service                                           6    0.0        -        -        -
/system.slice/NetworkManager.service                                  1      -        -        -        -
/system.slice/atop.service                                            1      -        -        -        -
/system.slice/atopacct.service                                        1      -        -        -        -
/system.slice/auditd.service                                          1      -        -        -        -
/system.slice/crond.service                                           1      -        -        -        -
/system.slice/dbus.service                                            1      -        -        -        -
/system.slice/firewalld.service                                       1      -        -        -        -
/system.slice/lvm2-lvmetad.service                                    1      -        -        -        -
/system.slice/polkit.service                                          1      -        -        -        -
/system.slice/postfix.service                                         3      -        -        -        -
/system.slice/rsyslog.service                                         1      -        -        -        -
/system.slice/system-getty.slice/[email protected]                   1      -        -        -        -
/system.slice/systemd-journald.service                                1      -        -        -        -
/system.slice/systemd-logind.service                                  1      -        -        -        -
/system.slice/systemd-udevd.service                                   1      -        -        -        -
/system.slice/webmin.service                                          1      -        -        -        -
/user.slice/user-0.slice/session-1.scope                              3      -        -        -        -

Control System Runlevels

32. How to start a system rescue mode.

# systemctl rescue

Broadcast message from [email protected] on pts/0 (Wed 2015-04-29 11:31:18 IST):

The system is going down to rescue mode NOW!

33. How to enter into emergency mode.

# systemctl emergency

Welcome to emergency mode! After logging in, type "journalctl -xb" to view
system logs, "systemctl reboot" to reboot, "systemctl default" to try again
to boot into default mode.

34. List current run levels in use.

# systemctl get-default

35. How to start Runlevel 5 aka graphical mode.

# systemctl isolate
# systemctl isolate

36. How to start Runlevel 3 aka multiuser mode (command line).

# systemctl isolate
# systemctl isolate

36. How to set multiuser mode or graphical mode as default run level.

# systemctl set-default

# systemctl set-default

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

# systemctl reboot

# systemctl halt

# systemctl suspend

# systemctl hibernate

# systemctl hybrid-sleep

For those who may not be aware of run levels and what it does.

  1. Runlevel 0 : Shut down and Power off the system.
  2. Runlevel 1 : Rescue?Maintainance Mode.
  3. Runlevel 3 : multiuser, no-graphic system.
  4. Runlevel 4 : multiuser, no-graphic system.
  5. Runlevel 5 : multiuser, graphical system.
  6. Runlevel 6 : Shutdown and Reboot the machine.

That’s all for now. Keep connected! Keep commenting. Don’t forget to provide us with your valuable feedback in the comments below. Like and share us and help us get spread.

If you liked this article, then do subscribe to email alerts for Linux tutorials. If you have any questions or doubts? do ask for help in the comments section.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

21 thoughts on “How to Manage ‘Systemd’ Services and Units Using ‘Systemctl’ in Linux”

    • @Mohamed amine TLILI: This was mentioned in an earlier comment (May 28, 2015, by McBuhl) along with the suggestion to make the correction in the blog post.

      I don’t know how long it normally takes to make corrections to a blog post here, but the good news is that we’re now 5 years closer to seeing the correction made.

  1. Superb pots. I would just like to add that all those system services also generate logs. With systemd, these logs can be managed centrally with another component called journalctl. The main configuration file is in /etc/systemd/journald.conf.
    Fear that you could dedicate another magnificent pots. Thanks a lot.

  2. I would like to know about the relationship of numbering of files such as this in your teachings:

    I used a similar scheme with a .network file as seen in some tutorials. For Example:
    My belief is that the lower number .network file starts first?? Are these just arbitrary numbers? Could I use in the same fashion?? 99-* seems to be the last number called up.

    Also these numbers schemes look like what I see in UDEV as well…

    Keep up the great work

  3. Really useful guide.
    Keep up the great work.
    I see one command not covered that I use alot.
    systemctl reenable
    This allows the unit file to reload and writes a new symbolic link to /usr/lib/

    I have also found the systemctl edit –full allows you to edit the unit control file in /etc/systemd/system folder. Helpful for setting the After= setting for controlling the startup order of services.

    • @Frank,

      Thanks for appreciating our work and giving us valuable tip, we’ve will check and add to the list as per your suggestions.

      • Thank You
        Just to be clear the “systemctl edit –full” needs a service to work on. For example:
        systemctl edit –full hostapd

        To this file I add-
        To have hostapd wait for dnsmasq to start first.

        It saves the file with an odd file extension that is actually the unit file. Just edit and save(ignore name). Another advantage with this method is that it reloads and reenables the service thus writing the needed symbolic links for you with a single swoop.

  4. Nice and extensive overview of available commands.

    Question: For controlling our applications we use supervisord, which allows one-shot commands as you present here, but also provides interactive shell, where one can call commands like “start svcA”, “restart svcB”, “tail svcA”, or even “follow mode” “tail -f svcA”. The interactive mode is very handy as it does not require typing so long commands.

    Question: is there any interactive console controlling systemd defined services?

    • @Jan,

      Thanks for the tips, never ever heard about supervisord, let me check how it works and also to be fact I really don’t have any idea in controlling systemd via interactive shell, let me check and get back to you..

      • I’d thank you even more if yo’d correct it in the blog post – as I had the same error as CertDepot
        + copy-pasting runs into error, too, because “–” is altered into a long “-“: Failed to find executable –version: No such file or directory

        • I love the conciseness of how-to posts like this one. But yeah, fast-forward 3 yrs and ‘systemd –version’ is still in the blog post. If one needs to read comments to get the correct info, then that whole conciseness thing goes out the window.


Leave a Reply to Ravi Saive Cancel reply

Have a question or suggestion? Please leave a comment to start the discussion. Please keep in mind that all comments are moderated and your email address will NOT be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.