Setting up Supervisord on a AWS AMI Linux Server [closed]
Asked Answered
P

2

24

I'm trying to get supervisor working to make sure my queue system is always running.

Here are the steps I took, which I pieced together from various sources: (Ran as root or super user)

1) $ easy_install supervisor

2) $ echo_supervisord_conf > /etc/supervisord.conf

3) $ sudo vi supervisord.conf

4) Pasted the following to end of file:

command=/usr/bin/php /path/to/AppName/artisan --env=production --timeout=240 queue:listen

5) $ supervisord -c /etc/supervisord.conf

6) $ supervisorctl

7) supervisor> status

supervisor>

It does not display anything.

Parr answered 24/2, 2015 at 17:50 Comment(1)
It is difficult, Ubuntu is easier.Garnierite
P
51

Here is the solution I went with. AWS AMI includes pip for installing Python applications. Here are the setup commands:

$ sudo pip install supervisor
$ echo_supervisord_conf
$ sudo su -
$ echo_supervisord_conf > /etc/supervisord.conf

After you install supervisor you will need to manually build your start-up script to turn the service on and off.

This will vary with your Linux distro, Ubuntu will create an init script for you when you install, other distros like AMI will not. Here is a great resource for various Linux distro init-up scripts:

https://github.com/Supervisor/initscripts

You can then add supervisor to chkconfig to get started automatically on system reboot.

Here is one that works for me:

Path

/etc/init.d/supervisord

Example Init Script for AWS-AMI or RedHat Linux

#!/bin/bash
#
# supervisord   Startup script for the Supervisor process control system
#
# Author:       Mike McGrath <[email protected]> (based off yumupdatesd)
#               Jason Koppe <[email protected]> adjusted to read sysconfig,
#                   use supervisord tools to start/stop, conditionally wait
#                   for child processes to shutdown, and startup later
#               Erwan Queffelec <[email protected]>
#                   make script LSB-compliant
#
# chkconfig:    345 83 04
# description: Supervisor is a client/server system that allows \
#   its users to monitor and control a number of processes on \
#   UNIX-like operating systems.
# processname: supervisord
# config: /etc/supervisord.conf
# config: /etc/sysconfig/supervisord
# pidfile: /var/run/supervisord.pid
#
### BEGIN INIT INFO
# Provides: supervisord
# Required-Start: $all
# Required-Stop: $all
# Short-Description: start and stop Supervisor process control system
# Description: Supervisor is a client/server system that allows
#   its users to monitor and control a number of processes on
#   UNIX-like operating systems.
### END INIT INFO

# Source function library
. /etc/rc.d/init.d/functions

# Source system settings
if [ -f /etc/sysconfig/supervisord ]; then
    . /etc/sysconfig/supervisord
fi

# Path to the supervisorctl script, server binary,
# and short-form for messages.
supervisorctl=/usr/local/bin/supervisorctl
supervisord=${SUPERVISORD-/usr/local/bin/supervisord}
prog=supervisord
pidfile=${PIDFILE-/tmp/supervisord.pid}
lockfile=${LOCKFILE-/var/lock/subsys/supervisord}
STOP_TIMEOUT=${STOP_TIMEOUT-60}
OPTIONS="${OPTIONS--c /etc/supervisord.conf}"
RETVAL=0

start() {
    echo -n $"Starting $prog: "
    daemon --pidfile=${pidfile} $supervisord $OPTIONS
    RETVAL=$?
    echo
    if [ $RETVAL -eq 0 ]; then
        touch ${lockfile}
        $supervisorctl $OPTIONS status
    fi
    return $RETVAL
}

stop() {
    echo -n $"Stopping $prog: "
    killproc -p ${pidfile} -d ${STOP_TIMEOUT} $supervisord
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && rm -rf ${lockfile} ${pidfile}
}

reload() {
    echo -n $"Reloading $prog: "
    LSB=1 killproc -p $pidfile $supervisord -HUP
    RETVAL=$?
    echo
    if [ $RETVAL -eq 7 ]; then
        failure $"$prog reload"
    else
        $supervisorctl $OPTIONS status
    fi
}

restart() {
    stop
    start
}

case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    status)
        status -p ${pidfile} $supervisord
        RETVAL=$?
        [ $RETVAL -eq 0 ] && $supervisorctl $OPTIONS status
        ;;
    restart)
        restart
        ;;
    condrestart|try-restart)
        if status -p ${pidfile} $supervisord >&/dev/null; then
          stop
          start
        fi
        ;;
    force-reload|reload)
        reload
        ;;
    *)
        echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|reload}"
        RETVAL=2
    esac

    exit $RETVAL

After you close and save, make it executable by all users:

chmod a+x /etc/init.d/supervisord

You would next want to confirm that the supervisord process is in fact running by running the following command:

 ps -fe | grep supervisor

If you don't see /usr/bin/supervisord as a running process then you need to start it up manually:

sudo service supervisord start

Supervisord needs to be started up anytime that the server is rebooted. This can be done similar to how apache is turned on after reboot using chkconfig.

First add it to chkconfig, your start up process list

sudo chkconfig --add supervisord

Then tell chkconfig to turn it on after boot

sudo chkconfig supervisord on
Parr answered 23/7, 2015 at 0:55 Comment(4)
I created the "/etc/init.d/supervisord" file and then run "sudo service supervisord start" but I received "env: /etc/init.d/supervisord: Permission denied".... any idea? I'm using ec2 Amazon AIM with centos 7Ikeikebana
chmod a+x /etc/init.d/supervisord to make it executable was a missing step in this very detailed answer :)Westcott
Thanks Filipe, I'll update the answer.Parr
@ llioor try chowning /tmp/supervisor.sockParr
H
7

supervisor doesn't know that you have added a program. This is answered on serverfault, do the following:

supervisorctl reread
supervisorctl update

By the way, it's easier to maintain configuration files using the conf.d syntax. In other words, create a file called /etc/supervisor/conf.d/artisan.conf. Everything else is the same, but it's easier to version control your configuration files and sync them to machines on setup.

Hyrax answered 24/2, 2015 at 18:49 Comment(3)
Hey thanks for your quick reply! I can't wait to get off and test this out!Parr
I tried that and had some errors. I noticed that I cannot get supervisor to start, when running as su $ service supervisord start I get supervisor: unrecognized service. Do I need a startup script like this? translate.google.com/translate?hl=en&sl=ja&u=http://…Parr
how did you install supervisor? I assume you are on the AWS Linux AMI? (edit your original question, add that stuff, then add a comment here. I'll try to reproduce.)Hyrax

© 2022 - 2024 — McMap. All rights reserved.