如何通过.ebextension在Elastic Beanstalk中安装supervisor?

问题描述 投票:4回答:1

我可以知道如何通过.ebextension将管理程序安装到Elastic Beanstalk中吗?如何通过.ebextension执行supervisor命令?

amazon-web-services elastic-beanstalk supervisor
1个回答
4
投票

Supervisorctl和supervisord已存在于/ usr / local / bin目录中的elasticbeanstalk实例上。您可以使用ebextensions加载超级用户配置文件并以守护进程模式运行超级用户。

在.ebextensions文件夹中创建一个文件002_supervisor.config

这个文件做了三件事:

  1. 在弹性beanstalk实例上的/ usr / local / etc中创建一个supervisor.conf文件。
  2. 创建一个init.d脚本,以便在系统启动时将supervisor作为守护程序运行
  3. 部署应用程序时,在超级用户上重新启动
files:
   /usr/local/etc/supervisord.conf:
    mode: "000755"
    owner: root
    group: root
    content: |
        [unix_http_server]
        file=/tmp/supervisor.sock   ; (the path to the socket file)

        [supervisord]
        logfile=/tmp/supervisord.log ; (main log file;default $CWD/supervisord.log)
        logfile_maxbytes=50MB        ; (max main logfile bytes b4 rotation;default 50MB)
        logfile_backups=10           ; (num of main logfile rotation backups;default 10)
        loglevel=info                ; (log level;default info; others: debug,warn,trace)
        pidfile=/tmp/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
        nodaemon=false               ; (start in foreground if true;default false)
        minfds=1024                  ; (min. avail startup file descriptors;default 1024)
        minprocs=200                 ; (min. avail process descriptors;default 200)

        [rpcinterface:supervisor]
        supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

        [supervisorctl]
        serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL  for a unix socket

        [include]
        files = /usr/local/etc/*.conf

        [inet_http_server]
        port = 127.0.0.1:9001
   /etc/init.d/supervisord:
    mode: "000755"
    owner: root
    group: root
    content: |
        #!/bin/bash

        # 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 /usr/local/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

commands:
  01_start_supervisor:
    command: '/etc/init.d/supervisord restart'
    leader_only: true

希望这可以帮助!

© www.soinside.com 2019 - 2024. All rights reserved.