description "uWSGI server instance configured to serve cloudsupervisor_lk_rest"
author      "CarbonSoft"

start on runlevel [2345]
stop on runlevel [06]
respawn

env PYTHONENCODING=utf-8
env LANG="en_US.utf8"
env LC_ALL="en_US.UTF-8"
env LC_LANG="en_US.UTF-8"

exec {{PROJECT_PATH}}/lib/uwsgi/uwsgi-2.0.15/uwsgi --chdir {{PROJECT_PATH}} --plugin {{PROJECT_PATH}}/uwsgi-2.0.15/python34_plugin.so -s {{PROJECT_PATH}}/uwsgi.sock --wsgi-file manage.py --pyargv "uwsgi" &>> /var/log/{{PROJECT_NAME}}_uwsgi.log

pre-start script
    echo "[`date`] Execd Starting" >> /var/log/{{PROJECT_NAME}}_uwsgi.log
end script

post-start script
    x=0
    while [ ! -S {{PROJECT_PATH}}/uwsgi.sock -a $x -le 10 ]; do
        sleep 1
	x="$((x+1))"
    done
    chown nginx:nginx {{PROJECT_PATH}}/uwsgi.sock
end script

pre-stop script
    rm /var/run/{{PROJECT_NAME}}_uwsgi.pid
    echo "[`date`] Execd Stopping" >> /var/log/{{PROJECT_NAME}}_uwsgi.log
end script

post-stop script
    rm {{PROJECT_PATH}}/uwsgi.sock
end script

