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


On Fri, Jul 26, 2019 at 12:27 AM Reindl Harald <[email protected]>
wrote:

>
>
> Am 25.07.19 um 20:38 schrieb Debraj Manna:
> > I have a service on a Ubuntu 16.04 which I use systemctl start, stop,
> > restart and status to control.
> >
> > One time the systemctl status returned active, but the application
> > "behind" the service responded http code different from 200.
> >
> > So I would like to restart the service when the http code is not 200.
> > Can some one let me know is there a way to achieve the same via systemd?
>
> nope, just write a seperate service with a little curl magic and
> "systemctl condrestart" and remember that you have to avoid premature
> restarts just because of a little load peak
> _______________________________________________
> systemd-devel mailing list
> [email protected]
> https://lists.freedesktop.org/mailman/listinfo/systemd-devel
_______________________________________________
systemd-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/systemd-devel

Reply via email to