[systemd-devel] Health check for a service managed by systemd
Lennart Poettering
lennart at poettering.net
Mon Jul 29 12:28:39 UTC 2019
On Fr, 26.07.19 19:07, Debraj Manna (subharaj.manna at gmail.com) wrote:
> Thanks Reindl for replying.
>
> Can we make use of the watchdog & systemd-notify functionality of systemd?
> I mean something like this.
>
> [Unit]
> Description=Test service
> After=network.target
>
> [Service]
> Type=notify
> # test.sh wrapper script to call the service
> ExecStart=/opt/test/test.sh
> Restart=always
> RestartSec=1
> TimeoutSec=5
> WatchdogSec=5
>
> [Install]
> WantedBy=multi-user.target
>
> Then in test.sh can we do something like
>
> #!/bin/bash
> trap 'kill $(jobs -p)' EXIT
>
> # Start the actual service
> /opt/test/service &
> PID=$!
>
> /bin/systemd-notify --ready
> while(true); do
> FAIL=0
> kill -0 $PID
> if [[ $? -ne 0 ]]; then FAIL=1; fi
>
> # curl http://localhost/test/
> # if [[ $? -ne 0 ]]; then FAIL=1; fi
>
> if [[ $FAIL -eq 0 ]]; then /bin/systemd-notify WATCHDOG=1; fi
>
> sleep 1
> done
Hmm, I am not sure how I feel about such uses for WATCHDOG=1. The
assumpion is always that his comes from the app itself as a hang
check. But this isn't really like that, hence I'd advise against this,
but of course, it's up to you how you solve this...
Lennart
--
Lennart Poettering, Berlin
More information about the systemd-devel
mailing list