linuxsystemdwatchdog

Why is setting 'echo V > /dev/watchdog1' not working when inside a 'systemd' service?


If I manually stop my service and then execute echo V > /dev/watchdog1, the watchdog stops properly.

If I do the same echo command in my systemd service, I get:

watchdog did not stop!

ExecStopPost=echo V > /dev/watchdog1

Why is the behavior not the same?


Solution

  • This does not work for the same reason mentioned in this post: Execute multiple commands with && in systemd service ExecStart on RedHat 7.9

    The commands from inside a systemd service are not executed in a proper shell environment. Even so, I do not have some kind of source that explicitly states this. From experience, the capabilities of a single systemd exec are the following: Run one command with parameters (not multiple commands, no output redirection, etc.).

    Just like in the referenced post, the solution could be writing it as follows:

    ExecStopPost=/bin/bash -c 'echo V > /dev/watchdog1'