Created
July 30, 2015 06:12
-
-
Save scythargon/382ea24d8c85ef5f4a5e to your computer and use it in GitHub Desktop.
run script
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/bash | |
# chkconfig: 345 96 4 | |
NAME=uwsgi | |
DESC=uwsgi | |
PIDFILE=/home/aviasales/.uwsgi.pid | |
USER=aviasales | |
# Source function library. | |
. /etc/init.d/functions | |
# NewRelic | |
NEW_RELIC_CONFIG_FILE=config/newrelic.ini | |
export NEW_RELIC_CONFIG_FILE | |
NEW_RELIC_ENVIRONMENT=beta | |
export NEW_RELIC_ENVIRONMENT | |
get_pid() { | |
if [ -f $PIDFILE ]; then | |
echo `cat $PIDFILE` | |
fi | |
} | |
is_uwsgi() { | |
PID=$(get_pid) | |
check=$(readlink -f /proc/$PID/exe | egrep "\/uwsgi$") | |
return $? | |
} | |
status() { | |
is_running=$(is_uwsgi) | |
if [ $? -gt 0 ]; then | |
echo "Not running." | |
return 0 | |
else | |
echo "Running" | |
exit 0 | |
fi | |
} | |
start() { | |
is_running=$(is_uwsgi) | |
if [ $? -gt 0 ]; then | |
echo -n "Starting $DESC: " | |
su $USER -c ". /home/aviasales/Envs/jetradar/bin/activate && newrelic-admin run-program uwsgi --ini /home/aviasales/jr-content/nginx/uwsgi.ini --pidfile $PIDFILE" | |
return 0 | |
else | |
echo "Already running" | |
exit 0 | |
fi | |
} | |
stop() { | |
echo -n "Shutting down $DESC: " | |
PID=$(get_pid) | |
[ ! -z "$PID" ] && kill -s 15 $PID &> /dev/null | |
if [ $? -gt 0 ]; then | |
echo "was not running" | |
exit 1 | |
else | |
echo "stopped." | |
rm -f $PIDFILE &> /dev/null | |
fi | |
return 0 | |
} | |
case "$1" in | |
start) | |
start | |
;; | |
stop) | |
stop | |
;; | |
status) | |
status | |
;; | |
restart) | |
stop | |
sleep 1 | |
start | |
;; | |
*) | |
echo "Usage: /etc/init.d/$NAME {start|stop|status|restart}" | |
exit 1 | |
;; | |
esac | |
exit $? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment