linux systemd common commands using systemctl

I first used slackware Linux in the early 90s, possibly, and have used Linux quite extensively since then.

The init/service management has changed a lot over that time, from editing /etc/rc.d now to systemd. I have struggled to keep up. So here is a terse set of commands to help me when I come to add or manage services on a Linux box that uses systemd

List all the systemd units ( no need to run as root )

systemctl

List all systemd units, type that have exited

systemctl list-units –type=service –all –state=exited

Show the status of a unit ( you can start, stop, restart, refresh instead of status )

sudo systemctl status owfs

To add a unit:

There seems to be two places that the systemd UNIT files exist.

System installed files are in /lib/systemd/system

User installed files are in /etc/systemd/system

..and there are sometimes symlinks from one to another

to create a new systemd unit called j2

sudo systemctl edit j2.service –force

UNIT file layout

[Unit]
Description=1-wire filesystem FUSE mount
Documentation=man:owfs(1
)

[Service]
Type=notify
NotifyAccess=all
ExecStart=/usr/bin/owfs -c /etc/owfs.conf –allow_other %t/owfs
ExecStop=/usr/bin/umount %t/owfs
RuntimeDirectory=owfs

[Install]
WantedBy=multi-user.target

Enabling your new systemd unit

sudo systemctl enable j2

Leave a Reply

Your email address will not be published. Required fields are marked *