Linux serverlinux web serverNETWORK ADMINISTRATIONS

Systemd Useless Machine

Hands on video for linux systemd service manager. Learn how to create new linux service and how to control it.

Used commands:
systemctl daemon-reload – reload sysdemd after configuration files are changed
systemctl start alert-me.service – start service called alert-me
systemctl stop alert-me.service – stop service called alert-me
systemctl enable alert-me.service – enable service called alert-me for startup at boot time
tail -f /var/log/syslog – watch for changes a file named syslog in /var/log directory
udevadm monitor –property – monitor udev for device changes

source

by DevOps Undefined

linux web server

One thought on “Systemd Useless Machine

  • A few remarks.

    You should not use "systemctl status" for checking a service state via the exit code. That's what "systemctl is-active" is for.

    You do not need the shell loop for checking whether a service is running. You can just run "sleep {forever…}" in the unit and add "Upholds=nginx.service". If the restart shall not be conditional on another service/unit being active then the restart can be handled with "Restart=…" and the related directives in the nginx.service unit file itself.

    Checking with a "ps | grep | grep" pipeline for something that only(?) Systemd is assumed to have started is a bit strange in a Systemd video… This would be handled by putting the "ffplay" call in a separate service unit (burp.service); starting it several times "simultaneously" does not do any harm. The "Upholds=…" directive would not be used on nginx.service directly (because there is no hook for a restart) but on a helper unit (keep-nginx-running.service). keep-nginx-running.service would have a "BindsTo=nginx.service" and a "Wants=burp.service". If you want burp.service started only on nginx restarts (but not on regular starts) then I guess you need an "ExecStartPre=systemctl –quiet is-active nginx.service"; it seems there is no negative equivalent to "Requisite=" and no "Condition…" or "Assert…" that could check for units.

    Unrelated to Systemd: When you are looking for running processes then rather use pgrep than "ps | grep"; it never reports itself. If you "must" use "ps | grep" then a simple work-around is "grep [f]oo" because that will only match "foo" but not "[f]oo".

    You do not need the shell pipeline in alertme.service. You can just use "ExecStart=systemd-cat …" in combination with "StandardInputText=Ooooops…"

Comments are closed.