useful command for systemd

During current session

# during current session
sudo systemctl start app.service # start a systemd service
sudo systemctl start app
sudo systemctl stop app.service

sudo systemctl restart app.service
sudo systemctl reload app.service # reload the configuration
sudo systemctl reload-or-restart app.service

at boot

This will createa a symbolic link from system’s copy of the service file (usually /lib/systemd/system or /etc/systemd/system) into the location on disk where systemd looks for autostart file (usually /etc/systemd/system/some_target.target.wants).

sudo systemctl enable app.service
sudo systemctl disable app.service

Check

systemctl status app.service
systemctl is-active app.serivce
systemctl is-enabled app.service
systemctl is-failed app.service

Overview

systemctl list-units
systemctl list-units --all
systemctl list-units --all --state=inacitve
systemctl list-units --type=service

systemctl list-unit-files

Unit management

systemctl cat app.serivce
systemctl list-dependencies app.service
systemctl show app.service

Mask units

mark a unit as completely unstartable

sudo systemctl mask app.service
sudo systemctl unmask app.service

Edit file

sudo systemctl edit app.service
sudo systemctl edit --full app.service
sudo systemctl rm /etc/systemd/system/app.service.d
sudo systemctl daemon-reload

Target

systemctl get-default
sudo systemctl set-default algorithm.target
systemctl list-unit-files --type=format
systemctl list-units --type=target

systemctl list-denpendecies multi-user.target
sudo systemctl isolate multi-user.target

Shortcuts

sudo systemctl rescue
sudo systemctl halt
sudo systemctl poweroff
sudo systemctl reboot