I have service named "router" that is able to receive http requests.
I decided to write sh script that will periodically check health of router service.
if something is wrong then it will restart it.
The problem:
if router was started with this script, then if this script is terminated, then router service is also terminated.
strange thing is that simple one-line sh script that simply does "service router restart" - works fine (so it restarts the service and closes immediately and everything is fine)
i suppose the reason is somewhere in loop or some bash if things.
script code attached...
Thanks for help!
#!/bin/bash
while :
do
STATUS=$(curl --silent localhost:80/test)
if [ "$STATUS" != "OK" ]
then
echo "problems: $STATUS".
service router restart
fi
sleep 5
done