【问题标题】:Setting up Supervisord on a AWS AMI Linux Server [closed]在 AWS AMI Linux 服务器上设置 Supervisord [关闭]
【发布时间】:2015-04-26 11:43:06
【问题描述】:

我正在努力让主管工作以确保我的队列系统始终在运行。

以下是我从各种来源拼凑而成的步骤: (以 root 或超级用户身份运行)

1) $ easy_install 主管

2) $ echo_supervisord_conf > /etc/supervisord.conf

3) $ sudo vi supervisord.conf

4) 将以下内容粘贴到文件末尾:

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

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

6) $supervisorctl

7) 主管> 状态

主管>

它不显示任何东西。

【问题讨论】:

  • 这很难,Ubuntu更容易。

标签: amazon-web-services supervisord amazon-ami amazon-linux


【解决方案1】:

这是我采用的解决方案。 AWS AMI 包括用于安装 Python 应用程序的 pip。以下是设置命令:

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

安装 supervisor 后,您需要手动构建启动脚本来打开和关闭服务。

这会因您的 Linux 发行版而异,Ubuntu 会在您安装时为您创建一个初始化脚本,而其他发行版(如 AMI)则不会。这是各种 Linux 发行版初始化脚本的绝佳资源:

https://github.com/Supervisor/initscripts

然后您可以将主管添加到 chkconfig 以在系统重新启动时自动启动。

这是一个适合我的:

路径

/etc/init.d/supervisord

AWS-AMI 或 RedHat Linux 的示例初始化脚本

#!/bin/bash
#
# supervisord   Startup script for the Supervisor process control system
#
# Author:       Mike McGrath <mmcgrath@redhat.com> (based off yumupdatesd)
#               Jason Koppe <jkoppe@indeed.com> adjusted to read sysconfig,
#                   use supervisord tools to start/stop, conditionally wait
#                   for child processes to shutdown, and startup later
#               Erwan Queffelec <erwan.queffelec@gmail.com>
#                   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

关闭并保存后,让所有用户都可以执行:

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

【讨论】:

  • 我创建了“/etc/init.d/supervisord”文件,然后运行“sudo service supervisord start”,但收到“env: /etc/init.d/supervisord: Permission denied”。 ... 任何想法?我正在使用 ec2 Amazon AIM 和 centos 7
  • chmod a+x /etc/init.d/supervisord 使其可执行是这个非常详细的答案中缺少的一步:)
  • 谢谢 Filipe,我会更新答案。
  • @llioor 尝试 chowning /tmp/supervisor.sock
【解决方案2】:

主管不知道您添加了一个程序。 This is answered on serverfault,请执行以下操作:

supervisorctl reread
supervisorctl update

顺便说一句,使用conf.d 语法维护配置文件更容易。换句话说,创建一个名为/etc/supervisor/conf.d/artisan.conf 的文件。其他一切都相同,但更容易对配置文件进行版本控制并将它们同步到设置的机器上。

【讨论】:

  • 您好,感谢您的快速回复!我迫不及待地想下车测试一下!
  • 我试过了,但有一些错误。我注意到我无法启动主管,当以 su $ service supervisord start 运行时,我得到主管:无法识别的服务。我需要这样的启动脚本吗? translate.google.com/translate?hl=en&sl=ja&u=http://…
  • 你是如何安装supervisor的?我假设您在 AWS Linux AMI 上? (编辑您的原始问题,添加内容,然后在此处添加评论。我会尝试重现。)
猜你喜欢
  • 1970-01-01
  • 2021-01-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多