Difference between revisions of "Linux systemd"

From Ever changing code
Jump to navigation Jump to search
Line 18: Line 18:
</source>
</source>


== Is it running? ==
== Is systemd running? ==
# ps -eaf | grep [s]ystemd
<source lang=bash>
ps -eaf | grep [s]ystemd
</source>


== Analyze ==
== Analyze ==

Revision as of 13:56, 27 July 2019

Manage Systemd Services and Units using Systemctl

Systemctl is a systemd utility which is responsible for Controlling the systemd system and service manager.

Systemd is a collection of system management daemons, utilities and libraries which serves as a replacement of System V init daemon. Systemd functions as central management and configuration platform for UNIX like system.

In the Linux Ecosystem Systemd has 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.


Check versions, binaries and libraries

$ systemd --version #Ubuntu 18.04
systemd 237
+PAM +AUDIT +SELINUX +IMA +APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD -IDN2 +IDN -PCRE2 default-hierarchy=hybrid
$ whereis systemd
systemd: /usr/lib/systemd /bin/systemd /etc/systemd /lib/systemd /usr/share/systemd /usr/share/man/man1/systemd.1.gz
$ whereis systemctl
systemctl: /bin/systemctl /usr/share/man/man1/systemctl.1.gz

Is systemd running?

ps -eaf | grep [s]ystemd

Analyze

Analyze systemd boot process

# systemd-analyze

Analyze time taken by each process at boot

# systemd-analyze blame

Analyze critical chain at boot

# systemd-analyze critical-chain

Important: Systemctl accepts services (.service), mount point (.mount), sockets (.socket) and devices (.device) as units

List units

List all the available units

# systemctl list-unit-files

List all running units

# systemctl list-units

List all failed units

# systemctl --failed

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

# systemctl is-enabled crond.service

Check whether a Unit or Service is running or not?

# systemctl status firewalld.service

Control and Manage Services Using Systemctl

List all services (including enabled and disabled)

systemctl list-unit-files --type=service


How do I start, restart, stop, reload and check the status of a service (httpd.service) in Linux

systemctl start   httpd.service
systemctl restart httpd.service
systemctl stop    httpd.service
systemctl reload  httpd.service
systemctl status  httpd.service


Note: When we use commands like start, restart, stop and reload with systemctl, we will not get any output on the terminal, only status command will print the output

How to active a service and enable or disable a service at boot time (auto start service at system boot)

systemctl is-active httpd.service
systemctl enable  httpd.service
systemctl disable httpd.service


How to mask (making it impossible to start) or unmask a service (httpd.service)

systemctl mask   httpd.service
systemctl unmask httpd.service


How to a Kill a service using systemctl command

systemctl kill   httpd
systemctl status httpd

Control and Manage Mount Points using Systemctl

List all system mount points

# systemctl list-unit-files --type=mount

How do I mount, unmount, remount, reload system mount points and also check the status of mount points on the system

# systemctl start tmp.mount
# systemctl stop tmp.mount
# systemctl restart tmp.mount
# systemctl reload tmp.mount
# systemctl status tmp.mount

How to active, enable or disable a mount point at boot time (auto mount at system boot)

# systemctl is-active tmp.mount
# systemctl enable tmp.mount
# systemctl disable  tmp.mount

How to mask (making it impossible to start) or unmask a mount points in Linux

# systemctl mask tmp.mount
# systemctl unmask tmp.mount

Control and Manage Sockets using Systemctl

List all available system sockets

# systemctl list-unit-files --type=socket

How do I start, restart, stop, reload and check the status of a socket (example: cups.socket) in Linux

# systemctl start cups.socket
# systemctl restart cups.socket
# systemctl stop cups.socket
# systemctl reload cups.socket
# systemctl status cups.socket

How to active a socket and enable or disable at boot time (auto start socket at system boot)

# systemctl is-active cups.socket
# systemctl enable cups.socket
# systemctl disable cups.socket

How to mask (making it impossible to start) or unmask a socket (cups.socket)

# systemctl mask cups.socket
# systemctl unmask cups.socket

... stopped on page2

Special services

# Restart networking
systemctl restart systemd-networkd

References