systemctl command examples

systemctl command is the central management tool for controlling the init system. It is widely used and has become the new standard for Linux distributions. Before you see some systemctl command examples, you can read more about systemd service and Units here

systemctl command examples

Let’s start with learning some systemctl commands examples.

To reboot the server
$ systemctl reboot
To shut down your computer
$ systemctl poweroff
To switch to rescue mode
$ systemctl rescue
List all the services on the server.

Many times you wish to see all the information about a service running on your server, then you can use the command below.

$ systemctl list-units --type=service
Output

Below is the expected output you should receive.

  UNIT                                                                                      LOAD   ACTIVE SUB     DESCRIPTION
  auditd.service                                                                            loaded active running Security Auditing Service
  chronyd.service                                                                           loaded active running NTP client/server
  crond.service                                                                             loaded active running Command Scheduler
  dbus.service                                                                              loaded active running D-Bus System Message Bus
  firewalld.service                                                                         loaded active running firewalld - dynamic firewall daemon
  [email protected]                                                                        loaded active running Getty on tty1
● kdump.service                                                                             loaded failed failed  Crash recovery kernel arming
  kmod-static-nodes.service                                                                 loaded active exited  Create list of required static device nodes for the current kernel
  lvm2-monitor.service                                                                      loaded active exited  Monitoring of LVM2 mirrors, snapshots etc. using dmeventd or progress polling
  network.service                                                                           loaded active exited  LSB: Bring up/down networking
  NetworkManager-wait-online.service                                                        loaded active exited  Network Manager Wait Online
See active service

If you want to see only active service then you use the command below.

$ systemctl list-units --type=service --state=active

You can use running, stopped, enabled, disabled and failed for the service. Another example is to list the units.

$ systemctl list-units --type=service --state=failed

  UNIT          LOAD   ACTIVE SUB    DESCRIPTION
● kdump.service loaded failed failed Crash recovery kernel arming

You can also list all the services, using the command below

$ systemctl list-units
See failed service

You can also list all failed units by the command.

$ systemctl list-units --failed
Starting a service

To start a service, you can use the command.

$ systemctl start {servicename}
Stopping a service

Similarly to stop the service you can use

$ systemctl stop {servicename}
Restarting a service

To restart the service you can use.

$ systemctl restart {servicename}
Enabling and disabling service

All the above commands, related to starting and stopping services were for the current runtime. However, in many situations, you don’t want to start the service automatically when the system boots. In that case, you will need to disable the service at the system boot.

To disable the service when the server boots

$ systemctl disable {servicename}

To make sure that the service starts every time when the server boots, you need to use the below command.

$ systemctl enable {serivcename}

To check the current status of the service you can use the command below.

$ systemctl is-enabled network.service

You should get a similar output as below.

network.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig network --level=5
disabled

Hope you have liked this post about systemctl command examples and if you want to add more to this post you can let me know in the comment, section or use the contact page.

If you have missed the post about git command examples do have a look.

Leave a Comment