Through the systemctl command, we can easily manage the systemd system and services.

Possible Directories for Daemons

  • /etc/systemd/system/*
  • /run/systemd/system/*
  • /usr/lib/systemd/system/*

Service Daemon Types

Here are some types for system service:

Option Description
.service Specify the services of the system.
.socket Socket files used for inter-process communication. There must be corresponding service files.
.snapshot System snapshots.
.device Devices that are recognized by the kernel under the /sys or /dev directory.
.mount Mount points where the file systems are mounted.
.automount Automatic mount point of file system controlled by systemd.
.swap Swap devices or in-memory paging files controlled by systemd.
.target Target units simply combine an existing set of units and dependencies, and they do not provide additional functionality by themselves. They are more flexible than SysV runlevels in the classic SysV init system.
.path Path for path-based activation controlled by systemd.

Frequently Used Commands for Systemctl

General Commands

Here are some commands for systemctl command:

Command Description
start PATTERN… Activate(s) the specified daemon(s).
stop PATTERN… Deactivate(s) the specified daemon(s).
reload PATTERN… Kill(s) the specified daemon(s) and restart it after reloading its configuration file.
restart PATTERN… Stop(s) the specified daemon(s) and restart it.
try-restart PATTERN… If the specified daemon is running, stop and restart it.
reload-or-restart PATTERN… Reload(s) or restart(s) the specified running daemon(s) and start the stopped daemon(s) if it is not started.
try-reload-or-restart Reload(s) or restart(s) the specified running daemon(s).
isolate Can only be used when the AllowIsolate attribute in the daemon configuration file is specified as true.
is-active Check(s) the specified daemon(s) to see if it is active.
status Show(s) brief status information for the daemon(s).
list-dependencies Show other daemons on which the specified daemon(s) depend(s).

Unit File Commands

Here are some file related commands for systemctl command:

Command Description
enable Start(s) the specified daemon(s) at the same time as the system is started.
disable Do(es) not start the specified daemon(s) at the same time as the system is started.
is-enabled Check to see if there are daemon files in the active state.
mask Prevent(s) the daemon(s) from starting in any way.
unmask Cancels the mask effect.
get-default Starts the default target linked by default.target.
set-default Sets the default target for the default.target link.

Manager Lifecycle Commands

Here are some daemon lifecycle related commands for systemctl command:

Command Description
daemon-reload Rerun all generators, reload all daemon files and recreate the full dependency tree.

System Commands

Here are some system related commands for systemctl command:

Command Description
rescue Enter rescue mode and send messages to all users.
emergency Enter emergency mode and send messages to all users.
poweroff Shut down the system.
reboot Restart the system.
suspend Pause the system.
hibernate Leave the system dormant.
hybrid-sleep Put the system in a paused and dormant state.

Runlevels

Here are some runlevel targets for systemctl command:

Runlevel Target
0 poweroff.target
1 rescue.target
2, 3, 4 multi-user.target
5 graphical.target
6 reboot.target

Daemon Configuration File

[UNIT] Section Options

Here are some unit section fields for daemon configuration file:

Field Description
Description= The name of the daemon.
Requires= Other daemons on which the daemon depends.
Wants= Other daemons on which the daemon depends. (Recommended)
Conflicts= Daemons that conflict with the current daemon.
Before, After= Daemons that start before or after the current daemon starts.

[SERVICE] Section Options

Here are some service section fields for daemon configuration file:

Field Description
Type= Daemon startup type. Available types are: simple, forking, oneshot, dbus, notify, idle.
ExecStart= Commands executed when the daemon is started.
ExecStartPrec=, ExecStartPost= Commands executed before or after the execution ExecStart commands.
ExecStop= Commands executed before the end of the daemon.
Restart= Whether the daemon should be allowed to restart after exiting, stopped, or timed out.

[INSTALL] Section Options

Here are some install section fields for daemon configuration file:

Field Description
Alias= Additional names of daemons.
WantedBy=, RequiresBy= Other daemons on which the daemon depends.

References SYSTEMD(1), SYSTEMD.SPECIAL(7), SYSTEMD.UNIT(5), SYSTEMD.SERVICE(5), SYSTEMD.SOCKET(5), SYSTEMD.SNAPSHOT(5), SYSTEMD.DEVICE(5), SYSTEMD.MOUNT(5), SYSTEMD.AUTOMOUNT(5), SYSTEMD.SWAP(5), SYSTEMD.TARGET(5), SYSTEMD.PATH(5), SYSTEMCTL(1), RUNLEVEL(8)

Buy me a coffeeBuy me a coffee