Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 908
zeros-and-ones Avatar asked Feb 24 '15 17:02

zeros-and-ones


People also ask

How do I enable services in Amazon Linux?

Enter the command “systemctl enable httpd” and then “systemctl start httpd” on AmazonLinux2. Now you can access the app on boot rather than running the app again and again. You are complete.

Why is my AWS instance not connecting?

The following are common reasons why EC2 Instance Connect might not work as expected: EC2 Instance Connect doesn't support the OS distribution. The EC2 Instance Connect package isn't installed on the instance. There are missing or incorrect AWS Identity and Access Management (IAM) policies or permissions.

How do I run a supervisor in Linux?

To start supervisorctl, run $BINDIR/supervisorctl. A shell will be presented that will allow you to control the processes that are currently managed by supervisord. Type “help” at the prompt to get information about the supported commands.

What package manager does Amazon Linux use?

Amazon Linux instances manage their software using the yum package manager. The yum package manager can install, remove, and update software, as well as manage all of the dependencies for each package.


2 Answers

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
like image 138
zeros-and-ones Avatar answered Oct 17 '22 21:10

zeros-and-ones


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.

like image 35
tedder42 Avatar answered Oct 17 '22 20:10

tedder42