Skip to main content

Systemd

To add a new to systemd service you can do:

 systemctl edit foo.service --force

The edit --force will create a file in /etc/systemd/system/ called foo.service, you can also just use vim

[Unit]
Description=foo

[Service]
ExecStart=/bin/bash echo "Hello World!"

[Install]
WantedBy=multi-user.target
systemctl start foo

You can also use systemctl cat nginx.service to simply view how the init script starts the service

To enable and start a service in the same line you can do

systemctl enable --now foo.service

To check the services that start with the OS in order you can do

systemctl list-dependencies multi-user.target

gnome-shell-screenshot-DIY83Y.png

Journalctl

To filter only 1 service you will need to use the flag -u

journalctl -u nginx.service

To have live logs on a service you can do

journalctl -f _SYSTEMD_UNIT=nginx.service

To have live-tail logs for 2 services example nginx and ssh

journalctl -f _SYSTEMD_UNIT=nginx.service + _SYSTEMD_UNIT=sshd.service

To check logs since the latest boot:

journalctl -b

To get the data from yesterday

journalctl --since yesterday

#orjournalctl#or
journalctl -u nginx.service --since today

To view kernel messages

journalctl -k