2

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
  • 2
    Also see [How to use Shellcheck](https://github.com/koalaman/shellcheck), [How to debug a bash script?](https://unix.stackexchange.com/q/155551/56041) (U&L.SE), [How to debug a bash script?](https://stackoverflow.com/q/951336/608639) (SO), [How to debug bash script?](https://askubuntu.com/q/21136) (AskU), [Debugging Bash scripts](http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_02_03.html), etc. – jww Aug 01 '18 at 00:56

0 Answers0