I have the following configuration in my monitrc file.
check process api-gateway with pidfile /var/run/apigateway.pid
start program = "/bin/bash -c '/apigateway/gatewayscript start'"
stop program = "/bin/bash -c '/apigateway/gatewayscript stop'"
This is the script I'm using to start/stop my process:
#!/bin/bash
case $1 in
start)
exec 2>&1 /apigateway/./api-gateway &
echo $$ > /var/run/apigateway.pid ;
;;
stop)
kill `cat /var/run/apigateway.pid` ;;
*)
echo "usage: gatewayscript {start|stop}" ;;
esac
exit 0
The script executes successfully when I run it separately. But monit gives me the following error:
[Jul 31 18:46:25] error : 'api-gateway' process is not running
[Jul 31 18:46:25] info : 'api-gateway' trying to restart
[Jul 31 18:46:25] info : 'api-gateway' start: '/bin/bash -c /apigateway/gatewayscript start'
[Jul 31 18:46:55] error : 'api-gateway' failed to start (exit status 0) -- no output