systemctl services
This is about working with services. Other aspects of systemctl.
Show Services
Show the running services:
systemctl list-units --type=service | grep running
or:
systemctl list-units --type=service --state=running
Show the units which failed to start:
systemctl list-units --state=failed
To list all the service units installed in the file system, not only the loaded:
sudo systemctl list-unit-files --type=service
To list only enabled service units:
systemctl list-unit-files --type=service --state=enabled
Show Service Status
systemctl status _service-name_
View Service Properties
systemctl show _service-name_
To display a single property, use the ā-pā flag with the property name:
systemctl show sshd.service -p ControlGroup
ControlGroup=/system.slice/sshd.service
View Service Dependencies
systemctl list-dependencies _service-name_
Show Service Log
Use journalctl:
journalctl --no-pager -u _service-name_
Service Management
Service actions:
- Boot-time:
enable
anddisable
, used to control the service at boot time. - Run-time:
start
,stop
,restart
, andreload
, used to control the service on-demand.
Start Service
sudo systemctl start _service_name_
Stop Service
sudo systemctl stop _service_name_
Restart Service
sudo systemctl restart UNIT_NAME.service
Reload Service
You may need to reload the service while making changes to the configuration file, which will bring up new parameters that you added.
sudo systemctl reload UNIT_NAME.service
Enable the Service
To start services automatically at boot, run:
sudo systemctl enable UNIT_NAME.service
This will create a symlink from either
/usr/lib/systemd/system/UNIT_NAME.service
or
/etc/systemd/system/UNIT_NAME.service
to the
/etc/systemd/system/SOME_TARGET.target.wants/UNIT_NAME.service
.
You can check that the service is enabled by:
systemctl is-enabled UNIT_NAME.service
Disable the Service
To disable the service at boot, run:
sudo systemctl disable UNIT_NAME.service
This will remove the symlink that has created earlier for the service unit.
systemd unit file
There are three main directories where unit files are stored:
/usr/lib/systemd/system/
- for files dropped when the package is installed;/run/systemd/system/
- for files created at run time;/etc/systemd/system/
- for files created bysystemctl enable
command as well as unit files added for extending a service.
Show the unit file
$ systemctl cat acpid.service
# /lib/systemd/system/acpid.service
[Unit]
Description=ACPI event daemon
Requires=acpid.socket
ConditionVirtualization=!container
Documentation=man:acpid(8)
[Service]
StandardInput=socket
EnvironmentFile=/etc/default/acpid
ExecStart=/usr/sbin/acpid $OPTIONS
[Install]
WantedBy=multi-user.target
Create the unit file
Create systemd service unit file.
Extending the unit file
To extend the default unit file with additional configuration options:
sudo systemctl edit _service_
This creates an override /etc/systemd/system/_service_.d/override.conf
and
opens it in your text editor. Add new parameters to the unit file and the new
parameters will be added to the existing service file when the file saved.
To apply changes made to the unit:
sudo systemctl daemon-reload
This reloads all unit files and recreates the entire dependency tree. To restart the service alone:
sudo systemctl restart _service_
If you change /lib/systemd/system/<servicename>.service
and restart the
service via
systemctl restart <servicename>.service
it will not load the new settings unless you do:
systemctl daemon-reload
Overriding the default unit configuration
If you want to keep the changes after updating the package that provides the unit file, edit the full unit file:
sudo systemctl edit --full _service_
This will load the current unit file into the editor. When the file is saved,
systemctl will create a file /etc/systemd/system/_service_.service
.
Any unit file in /etc/systemd/system
will override the corresponding file in
/lib/systemd/system
.
systemd-delta
man systemd-delta. To show all the overrides:
systemd-delta