I have a custom process (an elixir application) running. I want to setup monit for it. I am setting up the monit check in /etc/monit.d as the following:
set daemon 30
check host meraj-pc with address 192.168.3.124
start program = "/meraj/app/ex_app/check_port.sh start"
stop program = "/meraj/app/ex_app/check_port.sh stop"
if failed port 4000 type tcp protocol http then start
And check_port.sh file is:
case $1 in
start)
sh /meraj/app/ex_app/startup.sh & echo $! > /var/run/ex_app.pid ;
;;
stop)
pkill -F /var/run/ex_app.pid ;;
*)
echo "usage: checkport {start|stop}" ;;
esac
exit 0
While the startup.sh file contains the actual startup command for elixir app e.g. mix clean && mix compile && iex -S mix phx.server
Now when monit is started, it continues to give me this error (at that time my service at 4000 port is not running):
Aug 10 10:40:48 meraj monit[28316]: 'meraj-pc' failed protocol test [HTTP] at [192.168.3.124]:4000 [TCP/IP] -- Connection refused Aug 10 10:40:48 meraj monit[28316]: 'meraj-pc' start: '/meraj/app/ex_app/check_port.sh start'
If the application is running on 4000, it show this message in monit logs:
Aug 10 10:43:19 meraj monit[28316]: 'meraj-pc' connection succeeded to [192.168.3.124]:4000 [TCP/IP]
I don't know why it is not able to execute the start process in failed state as expected. Can anyone review this and let me know if I am missing anything?