Hqman

supervisor gunicorn 小计

pyramid 真实环境部署

1:gunicorn: gunicorn_paster [opts]  -D

怎么管理 gunicorn 进程?

方法1: shell

#!/bin/bash

### BEGIN INIT INFO

# Provides: manage process gunicorn_paster

# Required-Start: $local_fs $remote_fs $network

# Required-Stop: $local_fs $remote_fs $network

# Should-Start: $gunicorn_paster

# Should-Stop: $gunicorn_paster

# Default-Start: 2 3 4 5

# Default-Stop: 0 1 6

# Short-Description: Start gunicorn_paster.

# Description: Start gunicorn_paster.

### END INIT INFO


BASE_PATH='/home/hqman/projects/pydev'

NAME='meside'

APP_HOME=$BASE_PATH/$NAME

APP_BIN=$BASE_PATH/bin

DAEMON=$APP_BIN/gunicorn_paster

PIDFILE=$APP_HOME/$NAME.pid


#need sudo user

#if [ `id -u` -ne 0 ]; then

# echo "You need root or sudo privileges to run this script"

# exit 1

#fi


start_app() {

    if [ -e $PIDFILE ]; then

        echo "meside is running"

        return 1

    fi

    cd $BASE_PATH

    source bin/activate

    echo "start $NAME"

start-stop-daemon --start --pidfile $PIDFILE --exec $DAEMON -- -b 127.0.0.1:8000 -D $APP_HOME/development.ini -p $PIDFILE

}



stop_app() {


    echo "stop meside"

    if [ -f $PIDFILE ]; then

echo "Killing $NAME"

kill $(cat $PIDFILE )

fi


}


case "$1" in

        start)

                start_app

        ;;

        stop)

                stop_app

        ;;

        restart)

                stop_app

                sleep 2

                start_app

        ;;

        *)

                echo ' * Usage: gunicornctl {start|stop|restart}'

                exit 1

        ;;

esac



这个方法 方便 启动 重启 关闭 gunicorn 进程


方法2: 采用supervisor 来管理


1:下载 sudo apt-get install supervisor


2: 编写配置文件

[unix_http_server]

file=%(here)s/supervisor.sock   ; (the path to the socket file)


[supervisord]

logfile=%(here)s/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=%(here)s/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://%(here)s/supervisor.sock ; use a unix:// URL  for a unix socket


[program:meside]

command=%(here)s/../../bin/gunicorn_paster  --log-file=%(here)s/xxx.log %(here)s/../production.ini

directory=%(here)s/../

user=xxx

autostart=true

autorestart=true

redirect_stderr=false

environment=PATH=%(here)s/../../bin


3:启动 supervisor   supervisord -c xx.conf 

4: 通过 supervisorctl  restart start stop  app


参考 http://blog.yangyubo.com/2009/05/14/supervisor-introduce/

上一篇 下一篇

© Hqman | Powered by LOFTER