2

I am currently considering moving from Supervisor to Monit in order to monitor a Laravel queue worker. Main reason is the ability to monitor CPU, Memory, and set email alerts (afaik with Supervisor I must install another package) since I will want to monitor other things soon such as Redis and perhaps the overall stability and performance of the web server.

To my limited knowledge in process monitoring, Monit is more robust and suitable for the job.

All the documentation that I could find about Laravel and Queue/Job monitoring refer to using Supervisor and, when trying to set it up manually I got stuck with setting up the pid file for the queue listener (I am not a sysadmin).

Is there a reason for Laravel to endorse only Supervisor and not mention Monit at all? (https://laravel.com/docs/5.3/queues#queue-workers-and-deployment)

If not - can someone help with how the setup of the Monit configuration will be per a Laravel queue worker?

Assuming I have a project under /var/www/html/laravel and I would want the process monitored to be /var/www/html/laravel/artisan queue:work --daemon

I tried following this question but without much success.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
dev7
  • 6,259
  • 6
  • 32
  • 65

1 Answers1

4

In case you still need an answer:

Is certainly possible to setup Monit to control your queue with a little caveat (as mentioned in their FAQ); you need to wrap your command in a shell script.

In Monit config file (on Ubuntu 14.04 /etc/monit/monitrc) you can add:

    # beanstalk
    check process beanstalkd with pidfile /var/run/beanstalkd.pid
    start program = "/etc/init.d/beanstalkd start"
    stop program = "/etc/init.d/beanstalkd stop"
    if failed host 127.0.0.1 port 11300 then restart
    if 15 restarts within 15 cycles then timeout
    # beanstalk-queue
    check process beanstalk-queue with pidfile /var/run/beanstalk-queue.pid
    start = "YOUR_CHOSEN_PATH/beanstalk-queue.sh start"
    stop = "YOUR_CHOSEN_PATH/beanstalk-queue.sh stop"

Then create the script beanstalk-queue.sh in YOUR_CHOSEN_PATH:

    #!/bin/bash
    case $1 in
            start)
                    echo $$ > /var/run/beanstalk-queue.pid;
                    exec 2>&1 php /PATH_TO_YOUR_LARAVEL_INSTALLATION/artisan queue:work --daemon 1>/tmp/beanstalk-queue.out
                    ;;
            stop)  
                    kill `cat /var/run/beanstalk-queue.pid` ;;
            *)  
                    echo "usage: beanstalk-queue.sh {start|stop}" ;;
    esac
    exit 0

give it executable permissions and that's it!

PS Directories I used are for Ubuntu 14.04, check for other distros.

mur762
  • 110
  • 2
  • 9