0

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?

Meraj Rasool
  • 170
  • 1
  • 1
  • 6
  • Sorry, I don't understand the issue here. When monitored port is reachable, Monit reports it as connection succeeded. When monitored port is not reachable, Monit reports a failure then trigger the action "start" as defined in the rule. So what is the issue ? – DevOps Aug 10 '18 at 15:25
  • The issue is when 4000 port is not reach-able, then it attempts to start the service but fails with the error I mentioned in question. (also edited the question to make this more clear) – Meraj Rasool Aug 13 '18 at 07:15
  • Sorry, maybe I misunderstand but what is the error returned when Monit try to start the service with the command "/meraj/app/ex_app/check_port.sh start" ? The "failed protocot test" is a Message from Monit when Monit report the test as failing and it is before trying to start the service. – DevOps Aug 13 '18 at 10:50
  • Unfortunately monit doesn't show any other message in logs except the one I mentioned and that's what was making me confused. – Meraj Rasool Aug 13 '18 at 11:17

0 Answers0