-1

Im trying to monitor laravel-websocket with monit instead of supervisord because of more options it provides So In my /home/rabter/laravelwebsocket.sh :

#!/bin/bash
case $1 in
        start)
                echo $$ > /var/run/laravelwebsocket.pid;
                exec 2>&1 php /home/rabter/core/artisan websockets:serve  1>/tmp/laravelwebsocket.out
                ;;
        stop)  
                kill `cat /var/run/laravelwebsocket.pid` ;;
        *)  
                echo "usage: laravelwebsocket.sh {start|stop}" ;;
esac
exit 0

And in etc/monit.d I made a file named cwp.laravelwebsocket with code

check process laravelwebsocket with pidfile /var/run/laravelwebsocket.pid
start program "/bin/bash -c  /home/rabter/laravelwebsocket.sh start"
stop program "/bin/bash -c  /home/rabter/laravelwebsocket.sh stop"
if failed port 6001 then restart
if 4 restarts within 8 cycles then timeout

unfortunately with I run monit everything starts to get monitord but laravel websocket, and it does not start once and in monit table infront I see Process - laravelwebsocket Execution failed | Does not exist How can I make monit monitor and start laravel-websocket on startup and on fails or errors or crashes?

I have looked into Monitor a Laravel Queue Worker with Monit but no luck!

Pc Monk
  • 75
  • 2
  • 4
  • 24

1 Answers1

1

Your bash script inserts its own pid into your pid file. Additionally, the php process should be send to background if using monit, because monit is a monitoring tool, rather then a supervisor.

#!/usr/bin/env bash

case $1 in
    start)
        php /home/rabter/core/artisan websockets:serve & 2>&1 >/tmp/laravelwebsocket.out
        echo $! > /var/run/laravelwebsocket.pid;
        ;;
    stop)
        kill $(cat /var/run/laravelwebsocket.pid) ;;
    *)
        echo "usage: $(basename $0) {start|stop}" ;;
    esac
exit 0

Then make that file executable with chmod +x FILEPATH.

This should now work:

check process laravelwebsocket with pidfile /var/run/laravelwebsocket.pid
    start program "/home/rabter/laravelwebsocket.sh start"
    stop program "/home/rabter/laravelwebsocket.sh stop"

    if failed port 6001 then restart
    if 4 restarts within 8 cycles then timeout

Do you use monit as init-system for a container? If so, please let me know. Then a few more details apply.

boppy
  • 1,753
  • 12
  • 10
  • unfortunately in monit under status I still see `Execution failed | Does not exist` After replacing your scripts with mine and what do you mean by using monit as init-system ? – Pc Monk Mar 06 '20 at 07:24
  • `Does not exist` points to two possible problems: (1) The file does not exist, (2) The file is not executable. Could you `ls -l /home/rabter/laravelwebsocket.sh` to ensure the file is present? The line should start with `-rwx`. Regarding init-system: You can run monit inside a container as main service. If you just use monit in addition to an init-service (like initd, systemd, etc.) there's not problem here... ;) – boppy Mar 06 '20 at 08:42
  • -rwxr-xr-x 1 root root 342 Mar 6 10:51 laravelwebsocket.sh this is the response of the command and yes I do use it with systemd. – Pc Monk Mar 06 '20 at 12:16