Skip to content

Instantly share code, notes, and snippets.

@chengdh
Forked from shrkw/gunicorn_with_virtualenv
Last active December 31, 2015 11:48
Show Gist options
  • Select an option

  • Save chengdh/7981572 to your computer and use it in GitHub Desktop.

Select an option

Save chengdh/7981572 to your computer and use it in GitHub Desktop.

Revisions

  1. chengdh revised this gist Dec 26, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gunicorn_with_virtualenv
    Original file line number Diff line number Diff line change
    @@ -25,7 +25,7 @@ gunicorn_home=/home/openerp/gunicorn
    APP_HOME=/home/openerp/openerp/openobject-server
    APP_ROOT=$APP_HOME/current
    UNICORN_CONF=$APP_ROOT/newtime-wsgi.py
    lockfile=${LOCKFILE-$APP_HOME/shared/system/lock/gunicorn}
    lockfile=${LOCKFILE-$APP_HOME/shared/system/gunicorn.lock}
    pidfile=$APP_HOME/shared/pids/gunicorn.pid
    pidfile_old=${pidfile}.oldbin
    RETVAL=0
  2. chengdh revised this gist Dec 26, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gunicorn_with_virtualenv
    Original file line number Diff line number Diff line change
    @@ -43,7 +43,7 @@ virtualenv_dir=/home/openerp/openerp/openobject-server/shared/virtualenv
    start() {
    echo -n $"Starting $prog: "
    cd $APP_ROOT
    source $virtualenv_dir/bin/activate
    . $virtualenv_dir/bin/activate
    gunicorn --config $UNICORN_CONF --pid $pidfile --daemon -w $gunicorn_workers --access-logfile $accesslog --log-level $loglevel -b $gunicorn_bind $gunicorn_wsgi_app
    RETVAL=$?
    echo -n
  3. chengdh revised this gist Dec 26, 2013. 1 changed file with 8 additions and 7 deletions.
    15 changes: 8 additions & 7 deletions gunicorn_with_virtualenv
    Original file line number Diff line number Diff line change
    @@ -22,27 +22,28 @@
    prog=gunicorn
    gunicorn_home=/home/openerp/gunicorn

    APP_ROOT=/home/openerp/openerp7/openobject-server
    APP_HOME=/home/openerp/openerp/openobject-server
    APP_ROOT=$APP_HOME/current
    UNICORN_CONF=$APP_ROOT/newtime-wsgi.py
    lockfile=${LOCKFILE-$gunicorn_home/var/lock/gunicorn}
    pidfile=$gunicorn_home/var/run/gunicorn_sr.pid
    lockfile=${LOCKFILE-$APP_HOME/shared/system/lock/gunicorn}
    pidfile=$APP_HOME/shared/pids/gunicorn.pid
    pidfile_old=${pidfile}.oldbin
    RETVAL=0

    ##gunicorn config###
    gunicorn_wsgi_app=openerp:service.wsgi_server.application
    gunicorn_bind=0.0.0.0:8069
    gunicorn_workers=4
    errorlog=$gunicorn_home/var/logs/gunicorn-error.log
    accesslog=$gunicorn_home/var/logs/gunicorn-access.log
    errorlog=$APP_ROOT/log/gunicorn-error.log
    accesslog=$APP_ROOT/log/gunicorn-access.log
    loglevel=debug
    timeout=50000
    virtualenv_dir=OPENERP
    virtualenv_dir=/home/openerp/openerp/openobject-server/shared/virtualenv

    start() {
    echo -n $"Starting $prog: "
    cd $APP_ROOT
    . $virtualenv_dir/bin/activate
    source $virtualenv_dir/bin/activate
    gunicorn --config $UNICORN_CONF --pid $pidfile --daemon -w $gunicorn_workers --access-logfile $accesslog --log-level $loglevel -b $gunicorn_bind $gunicorn_wsgi_app
    RETVAL=$?
    echo -n
  4. chengdh revised this gist Dec 20, 2013. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions gunicorn_with_virtualenv
    Original file line number Diff line number Diff line change
    @@ -53,26 +53,26 @@ start() {

    stop() {
    echo -n $"Stopping $prog: "
    pkill -p ${pidfile} ${prog} -QUIT
    kill -QUIT $(cat ${pidfile})
    RETVAL=$?
    echo
    [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
    }

    restart() {
    echo -n $"Restarting $prog: "
    pkill -p ${pidfile} ${prog} -USR2
    kill -USR2 $(cat ${pidfile})
    RETVAL=$?
    echo
    echo -n $"Stopping old $prog: "
    pkill -p ${pidfile_old} ${prog} -QUIT
    kill -QUIT $(cat ${pidfile_old})
    RETVAL=$?
    echo
    }

    reload() {
    echo -n $"Reloading $prog: "
    pkill -p ${pidfile} ${prog} -HUP
    kill -HUP $(cat ${pidfile})
    RETVAL=$?
    echo
    }
  5. chengdh revised this gist Dec 20, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gunicorn_with_virtualenv
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@
    # chkconfig: - 86 14
    # processname: gunicorn
    # pidfile:
    # description: Python application server
    # description: Python application server in ubuntu
    #
    ### BEGIN INIT INFO
    # Provides: gunicorn_sr
  6. chengdh revised this gist Dec 20, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gunicorn_with_virtualenv
    Original file line number Diff line number Diff line change
    @@ -53,7 +53,7 @@ start() {

    stop() {
    echo -n $"Stopping $prog: "
    killproc -p ${pidfile} ${prog} -QUIT
    pkill -p ${pidfile} ${prog} -QUIT
    RETVAL=$?
    echo
    [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
  7. chengdh revised this gist Dec 20, 2013. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions gunicorn_with_virtualenv
    Original file line number Diff line number Diff line change
    @@ -61,18 +61,18 @@ stop() {

    restart() {
    echo -n $"Restarting $prog: "
    killproc -p ${pidfile} ${prog} -USR2
    pkill -p ${pidfile} ${prog} -USR2
    RETVAL=$?
    echo
    echo -n $"Stopping old $prog: "
    killproc -p ${pidfile_old} ${prog} -QUIT
    pkill -p ${pidfile_old} ${prog} -QUIT
    RETVAL=$?
    echo
    }

    reload() {
    echo -n $"Reloading $prog: "
    killproc -p ${pidfile} ${prog} -HUP
    pkill -p ${pidfile} ${prog} -HUP
    RETVAL=$?
    echo
    }
  8. chengdh revised this gist Dec 20, 2013. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion gunicorn_with_virtualenv
    Original file line number Diff line number Diff line change
    @@ -20,6 +20,8 @@
    #. /etc/rc.d/init.d/functions

    prog=gunicorn
    gunicorn_home=/home/openerp/gunicorn

    APP_ROOT=/home/openerp/openerp7/openobject-server
    UNICORN_CONF=$APP_ROOT/newtime-wsgi.py
    lockfile=${LOCKFILE-$gunicorn_home/var/lock/gunicorn}
    @@ -28,7 +30,6 @@ pidfile_old=${pidfile}.oldbin
    RETVAL=0

    ##gunicorn config###
    gunicorn_home=/home/openerp/gunicorn
    gunicorn_wsgi_app=openerp:service.wsgi_server.application
    gunicorn_bind=0.0.0.0:8069
    gunicorn_workers=4
  9. chengdh revised this gist Dec 20, 2013. 1 changed file with 5 additions and 6 deletions.
    11 changes: 5 additions & 6 deletions gunicorn_with_virtualenv
    Original file line number Diff line number Diff line change
    @@ -22,23 +22,22 @@
    prog=gunicorn
    APP_ROOT=/home/openerp/openerp7/openobject-server
    UNICORN_CONF=$APP_ROOT/newtime-wsgi.py
    lockfile=${LOCKFILE-/var/lock/gunicorn}
    pidfile=/var/run/gunicorn_sr.pid
    lockfile=${LOCKFILE-$gunicorn_home/var/lock/gunicorn}
    pidfile=$gunicorn_home/var/run/gunicorn_sr.pid
    pidfile_old=${pidfile}.oldbin
    RETVAL=0

    ##gunicorn config###
    gunicorn_home=/home/openerp/gunicorn
    gunicorn_wsgi_app=openerp:service.wsgi_server.application
    gunicorn_bind=0.0.0.0:8069
    gunicorn_workers=4
    errorlog=/var/logs/gunicorn-error.log
    accesslog=/var/logs/gunicorn-access.log
    errorlog=$gunicorn_home/var/logs/gunicorn-error.log
    accesslog=$gunicorn_home/var/logs/gunicorn-access.log
    loglevel=debug
    timeout=50000
    virtualenv_dir=OPENERP



    start() {
    echo -n $"Starting $prog: "
    cd $APP_ROOT
  10. chengdh revised this gist Dec 20, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gunicorn_with_virtualenv
    Original file line number Diff line number Diff line change
    @@ -22,7 +22,7 @@
    prog=gunicorn
    APP_ROOT=/home/openerp/openerp7/openobject-server
    UNICORN_CONF=$APP_ROOT/newtime-wsgi.py
    lockfile=${LOCKFILE-/var/lock/subsys/gunicorn}
    lockfile=${LOCKFILE-/var/lock/gunicorn}
    pidfile=/var/run/gunicorn_sr.pid
    pidfile_old=${pidfile}.oldbin
    RETVAL=0
  11. chengdh revised this gist Dec 20, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gunicorn_with_virtualenv
    Original file line number Diff line number Diff line change
    @@ -43,7 +43,7 @@ start() {
    echo -n $"Starting $prog: "
    cd $APP_ROOT
    . $virtualenv_dir/bin/activate
    gunicorn --config $gunicorn_wsgi_app --pid $pidfile --daemon -w $gunicorn_workers --access-logfile $accesslog --log-level $loglevel -b $gunicorn_bind
    gunicorn --config $UNICORN_CONF --pid $pidfile --daemon -w $gunicorn_workers --access-logfile $accesslog --log-level $loglevel -b $gunicorn_bind $gunicorn_wsgi_app
    RETVAL=$?
    echo -n
    [ $RETVAL = 0 ] && echo -e '[\e[32m OK \e[m]'
  12. chengdh revised this gist Dec 20, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gunicorn_with_virtualenv
    Original file line number Diff line number Diff line change
    @@ -17,7 +17,7 @@
    ### END INIT INFO

    # Source function library.
    . /etc/rc.d/init.d/functions
    #. /etc/rc.d/init.d/functions

    prog=gunicorn
    APP_ROOT=/home/openerp/openerp7/openobject-server
  13. chengdh revised this gist Dec 20, 2013. 1 changed file with 8 additions and 8 deletions.
    16 changes: 8 additions & 8 deletions gunicorn_with_virtualenv
    Original file line number Diff line number Diff line change
    @@ -28,14 +28,14 @@ pidfile_old=${pidfile}.oldbin
    RETVAL=0

    ##gunicorn config###
    gunicorn_wsgi_app = "openerp:service.wsgi_server.application"
    gunicorn_bind = "0.0.0.0:8069"
    gunicorn_workers = 4
    errorlog = /var/logs/gunicorn-error.log
    accesslog = /var/logs/gunicorn-access.log
    loglevel = 'debug'
    timeout = '50000'
    virtualenv_dir = OPENERP
    gunicorn_wsgi_app=openerp:service.wsgi_server.application
    gunicorn_bind=0.0.0.0:8069
    gunicorn_workers=4
    errorlog=/var/logs/gunicorn-error.log
    accesslog=/var/logs/gunicorn-access.log
    loglevel=debug
    timeout=50000
    virtualenv_dir=OPENERP



  14. chengdh revised this gist Dec 20, 2013. 1 changed file with 15 additions and 5 deletions.
    20 changes: 15 additions & 5 deletions gunicorn_with_virtualenv
    Original file line number Diff line number Diff line change
    @@ -20,20 +20,30 @@
    . /etc/rc.d/init.d/functions

    prog=gunicorn
    APP_ROOT=/PATH/TO/APP
    UNICORN_CONF=$APP_ROOT/gunicorn.py
    APP_ROOT=/home/openerp/openerp7/openobject-server
    UNICORN_CONF=$APP_ROOT/newtime-wsgi.py
    lockfile=${LOCKFILE-/var/lock/subsys/gunicorn}
    pidfile=/var/run/gunicorn_sr.pid
    pidfile_old=${pidfile}.oldbin
    RETVAL=0
    ENV=production

    ##gunicorn config###
    gunicorn_wsgi_app = "openerp:service.wsgi_server.application"
    gunicorn_bind = "0.0.0.0:8069"
    gunicorn_workers = 4
    errorlog = /var/logs/gunicorn-error.log
    accesslog = /var/logs/gunicorn-access.log
    loglevel = 'debug'
    timeout = '50000'
    virtualenv_dir = OPENERP



    start() {
    echo -n $"Starting $prog: "
    cd $APP_ROOT
    . /PATH/TO/YOUR/VIRTUALENV/bin/activate
    gunicorn --config $UNICORN_CONF --pid $pidfile --daemon --paste ${ENV}.ini
    . $virtualenv_dir/bin/activate
    gunicorn --config $gunicorn_wsgi_app --pid $pidfile --daemon -w $gunicorn_workers --access-logfile $accesslog --log-level $loglevel -b $gunicorn_bind
    RETVAL=$?
    echo -n
    [ $RETVAL = 0 ] && echo -e '[\e[32m OK \e[m]'
  15. @shrkw shrkw created this gist Oct 31, 2013.
    104 changes: 104 additions & 0 deletions gunicorn_with_virtualenv
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,104 @@
    #!/bin/sh
    #
    # gunicorn_sr Startup script for gunicorn for sr
    #
    # chkconfig: - 86 14
    # processname: gunicorn
    # pidfile:
    # description: Python application server
    #
    ### BEGIN INIT INFO
    # Provides: gunicorn_sr
    # Required-Start: $local_fs $remote_fs $network
    # Required-Stop: $local_fs $remote_fs $network
    # Default-Start: 3
    # Default-Stop: 0 1 2 4 5 6
    # Short-Description: start and stop gunicorn
    ### END INIT INFO

    # Source function library.
    . /etc/rc.d/init.d/functions

    prog=gunicorn
    APP_ROOT=/PATH/TO/APP
    UNICORN_CONF=$APP_ROOT/gunicorn.py
    lockfile=${LOCKFILE-/var/lock/subsys/gunicorn}
    pidfile=/var/run/gunicorn_sr.pid
    pidfile_old=${pidfile}.oldbin
    RETVAL=0
    ENV=production


    start() {
    echo -n $"Starting $prog: "
    cd $APP_ROOT
    . /PATH/TO/YOUR/VIRTUALENV/bin/activate
    gunicorn --config $UNICORN_CONF --pid $pidfile --daemon --paste ${ENV}.ini
    RETVAL=$?
    echo -n
    [ $RETVAL = 0 ] && echo -e '[\e[32m OK \e[m]'
    [ $RETVAL = 0 ] && touch ${lockfile}
    return $RETVAL
    }

    stop() {
    echo -n $"Stopping $prog: "
    killproc -p ${pidfile} ${prog} -QUIT
    RETVAL=$?
    echo
    [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
    }

    restart() {
    echo -n $"Restarting $prog: "
    killproc -p ${pidfile} ${prog} -USR2
    RETVAL=$?
    echo
    echo -n $"Stopping old $prog: "
    killproc -p ${pidfile_old} ${prog} -QUIT
    RETVAL=$?
    echo
    }

    reload() {
    echo -n $"Reloading $prog: "
    killproc -p ${pidfile} ${prog} -HUP
    RETVAL=$?
    echo
    }

    rh_status() {
    status -p ${pidfile} ${prog}
    }

    # See how we were called.
    case "$1" in
    start)
    rh_status >/dev/null 2>&1 && exit 0
    start
    ;;
    stop)
    stop
    ;;
    restart)
    restart
    ;;
    reload)
    reload
    ;;
    condrestart|try-restart)
    if rh_status >/dev/null 2>&1; then
    stop
    start
    fi
    ;;
    status)
    rh_status
    RETVAL=$?
    ;;
    *)
    echo $"Usage: $prog {start|stop|restart|reload|condrestart|try-restart|status|help}"
    RETVAL=2
    esac

    exit $RETVAL