以下是我采用的解决方案。AWS AMI 包含了 pip,可用于安装 Python 应用程序。以下是设置命令:
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
安装完Supervisor后,您需要手动构建启动脚本以打开和关闭服务。这将因Linux发行版而异,Ubuntu在安装时会为您创建一个init脚本,而像AMI这样的其他发行版则不会。这是适用于各种Linux发行版init-up脚本的一个很好的资源:
https://github.com/Supervisor/initscripts。
然后,您可以将supervisor添加到chkconfig中,以便在系统重新启动时自动启动。这是适用于我的脚本之一:
路径
/etc/init.d/supervisord
AWS-AMI或RedHat Linux的示例初始化脚本
#!/bin/bash
. /etc/rc.d/init.d/functions
if [ -f /etc/sysconfig/supervisord ]; then
. /etc/sysconfig/supervisord
fi
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
在关闭并保存后,将其设置为所有用户可执行:
chmod a+x /etc/init.d/supervisord
你接下来需要确认 supervisord 进程是否在运行,可以通过运行以下命令进行确认:
ps -fe | grep supervisor
如果您没有看到 /usr/bin/supervisord 作为正在运行的进程,则需要手动启动它:
sudo service supervisord start
每当服务器重新启动时,都需要启动Supervisord。这可以类似于使用chkconfig在重启后启动apache。
首先将其添加到chkconfig中,您的启动进程列表中。
sudo chkconfig --add supervisord
然后告诉chkconfig在启动后将其打开
sudo chkconfig supervisord on