systemctl Command Examples in Linux

Linux distributions are moving away from their old System V-style startup processes to a newer mechanism, the systemd daemon, and its associated systemctl command-line tool. Services managed by systemd/systemctl require, at a minimum, a configuration file that defines startup and shutdown processes, a type definition that controls how those processes will be handled by the OS, and whatever executables are needed to start or stop the service processes.

On most new distributions that use the system, we would manage processes using the systemctl command. The Linux developers have also left support for the service command; if we try to terminate a process using the service command, then we will see that it is actually going to redirect our request to the systemctl command.

Configuration Files

  • /usr/lib/systemd/system/: It contains system default unit files.
  • /etc/systemd/system: It contains system-specific parameters to modify the default behavior of systemd.
  • /run/systemd/system/: It contains the runtime configuration of unit files.

systemctl Command Examples

1. Viewing states of service with systemctl:

# systemctl status sshd.service
Status Description
Loaded Unit configuration file is processed successfully
Active (running) Running with one or more active processes
Active (exited) Successfully completed a one-time configuration
Active (waiting) Running and waiting for an event to take place
Inactive Not running currently
Enabled Will get started at boot time
Disabled Will not get started at boot time
Static Cannot be enabled directly, but may be started by another enabled unit automatically

2. Displays the state of all the different units that are active and loaded on startup:

# systemctl

3. Displays the state of only service units that are active:

# systemctl --type=service 

or

# systemctl list-units --type=service

4. Displays the state of all service units loaded, whether active or inactive:

# systemctl --type=service –all 

or

# systemctl list-units --type=service --all

5. Displays all services that failed:

# systemctl --failed --type=service

6. Displays whether the particular service is currently active or not:

# systemctl is-active sshd

7. Displays whether the particular service in enabled to start at boot time or not:

# systemctl is-enabled sshd

8. Displays the enabled, disabled, or static settings of all units of the specified type:

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

9. Displays detailed status information about the specified service:

# systemctl status sshd.service -l
Related Post