<div dir="ltr"><div dir="ltr">On Fri, Jul 26, 2019 at 4:37 PM Debraj Manna <<a href="mailto:subharaj.manna@gmail.com">subharaj.manna@gmail.com</a>> wrote:</div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Can we make use of the <font face="courier new, monospace">watchdog</font> & <span style="background-color:rgb(249,242,244);font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:12.6px"><font color="#000000">systemd-notify</font></span><span style="background-color:rgb(249,242,244);color:rgb(199,37,78);font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:12.6px"> </span>functionality of systemd? I mean something like this. </div><div><br></div><div><font face="courier new, monospace">[Unit]<br>Description=Test service<br>After=network.target<br><br>[Service]<br>Type=notify</font></div><div><font face="courier new, monospace"># test.sh wrapper script to call the service<br>ExecStart=/opt/test/test.sh<br>Restart=always<br>RestartSec=1<br>TimeoutSec=5<br>WatchdogSec=5<br><br>[Install]<br>WantedBy=multi-user.target</font><br></div><div><br></div><div>Then in <font face="courier new, monospace">test.sh</font> can we do something like </div><div><br></div><div><font face="courier new, monospace">#!/bin/bash<br>trap 'kill $(jobs -p)' EXIT</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"># Start the actual service<br>/opt/test/service &<br>PID=$!<br><br>/bin/systemd-notify --ready<br>while(true); do<br>    FAIL=0<br>    kill -0 $PID<br>    if [[ $? -ne 0 ]]; then FAIL=1; fi<br><br>#    curl <a href="http://localhost/test/" target="_blank">http://localhost/test/</a><br>#    if [[ $? -ne 0 ]]; then FAIL=1; fi<br><br>if [[ $FAIL -eq 0 ]]; then /bin/systemd-notify WATCHDOG=1; fi<br><br>    sleep 1<br>done</font></div></div></blockquote><div><br></div><div>That doesn't look nice; it might technically work but it isn't any better than a standalone periodic check script. On top of that, the script calls --ready without knowing whether the service is ready; /bin/systemd-notify as an external binary doesn't work very well; and the way you implement PID existence check means even a completely crashed/exited daemon won't get restarted until watchdog timeout expires...</div><div><br></div><div>Consider something already made for this purpose, such as Monit.</div><div><br></div></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr">Mantas Mikulėnas</div></div></div>