Systemd
Systemd reminder
Command line
Common
The --user
option limit command on the user scope
The --system
option do the same but for the system and is the default.
The user systemd unit file can be found in :
- ~/.local/share/systemd/user/
- ~/.config/systemd/user/
Get system status
$ systemctl status
List all units in running state
$ systemctl list-units --state running
List all failed units
$ systemctl --failed
Get a list of all installed units
$ systemctl list-unit-files
Get unit status
$ systemctl status $(UNIT_NAME)
Start unit
$ systemctl start $(UNIT_NAME)
Stop unit
$ systemctl stop $(UNIT_NAME)
Restart unit
$ systemctl restart $(UNIT_NAME)
Reload unit
$ systemctl reload $(UNIT_NAME)
Check if unit is enabled
$ systemctl is-enabled $(UNIT_NAME)
Enable unit at boot
$ systemctl enable $(UNIT_NAME)
Disable unit
$ systemctl disable $(UNIT_NAME)
Mask a given unit
$ systemctl mask $(UNIT_NAME)
Unmask a given unit
$ systemctl unmask $(UNIT_NAME)
List all timer
$ systemctl list-timers
Reload the systemd manager configuration
Usefull when you change or create an unit file
$ systemctl daemon-reload
Show cgroups ressources usage
$ systemd-cgtop
Show ressources of given cgroup
$ systemd-cgls $(CGROUP)
Systemd unit management
Create service unit
-------------------
The unit name must be finish by .service for example : **my-greatest-unit.service**.
The units path location are in **/etc/systemd/system/** or **/lib/systemd/system/**.
For new units **/etc/systemd/system/** is the better location.
```bash
[Unit]
Description=$(UNIT_DESCRIPTION)
After=$(AFTER_WHICH_TARGET)
[Service]
Type=$(SYSTEMD_TYPE)
User=$(USER)
ExecStartPre=$(PRE_EXEC)
ExecStart=$(EXEC_COMMAND)
ExecStop=$(EXEC_COMMAND)
Restart=$(RESTART POLICY)
```
Types :
* ``simple``
* ``forking``
* ``oneshot``
* ``dbus``
* ``notify``
* ``idle``