Last active
August 29, 2015 14:26
-
-
Save ianfitzpatrick/f6f83ddde3124fe3d8fa to your computer and use it in GitHub Desktop.
Debian init script for running New Relic Python wrapper w/ uWSGI + Virtualenv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
### BEGIN INIT INFO | |
# Provides: uwsgi | |
# Required-Start: $local_fs $network | |
# Required-Stop: $local_fs | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: uwsgi wrapped by new relic | |
# Description: Support for uwsgi with new relic and virtualenv | |
### END INIT INFO | |
# Quick start-stop-daemon example, derived from Debian /etc/init.d/ssh | |
set -e | |
# Specify username. Run command under user's UID | |
USER=www-data | |
#This is the command to be run, give the full pathname | |
NAME=uwsgi | |
DAEMON=/home/$USER/.virtualenvs/myvirtualenv/bin/newrelic-admin | |
DAEMON_OPTS="run-program /home/$USER/.virtualenvs/myvirtualenv/bin/uwsgi --ini /etc/uwsgi/apps-enabled/uwsgi.ini" | |
# New Relic Settings | |
NR_CONFIG_FILE=/var/www/myproject/newrelic.ini | |
NR_STARTUP_DEBUG=true | |
export PATH="${PATH:+$PATH:}/usr/sbin:/sbin" | |
case "$1" in | |
start) | |
echo -n "Starting daemon: "$NAME | |
export NEW_RELIC_CONFIG_FILE=$NR_CONFIG_FILE | |
export NEW_RELIC_STARTUP_DEBUG=$NR_STARTUP_DEBUG | |
start-stop-daemon --start --quiet --chuid $USER --exec $DAEMON -- $DAEMON_OPTS | |
echo "." | |
;; | |
stop) | |
echo -n "Stopping daemon: "$NAME | |
start-stop-daemon --stop --quiet --chuid $USER --oknodo --signal 9 | |
echo "." | |
;; | |
restart) | |
echo -n "Restarting daemon: "$NAME | |
start-stop-daemon --stop --chuid $USER --oknodo --signal 9 --retry 30 | |
start-stop-daemon --start --chuid $USER --exec $DAEMON -- $DAEMON_OPTS | |
echo "." | |
;; | |
*) | |
echo "Usage: "$1" {start|stop|restart}" | |
exit 1 | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A few notes:
plugin = python
in youruwsgi.ini
file, comment it out.module = <module_name>.wsgi:application
(notmodule = django.core.wsgi:get_wsgi_application()
) inuwsgi.ini