Created
August 1, 2012 17:22
-
-
Save zodman/3228959 to your computer and use it in GitHub Desktop.
uwsgi init new script
This file contains hidden or 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 | |
# uwsgi - Use uwsgi to run python and wsgi web apps. | |
# | |
# chkconfig: - 85 15 | |
# description: Use uwsgi to run python and wsgi web apps. | |
# processname: uwsgi | |
PATH=/sbin:/bin:/usr/sbin:/usr/bin | |
DAEMON=/usr/local/bin/uwsgi | |
OWNER=root | |
NAME=projectname | |
DESC=projectname | |
LOCALE='en_US.UTF-8' | |
DAEMON="LC_ALL=${LOCALE} LANG=${LOCALE} ${DAEMON}" | |
set -e | |
get_pid() { | |
if [ -f /var/run/$NAME.pid ]; then | |
echo `cat /var/run/$NAME.pid` | |
fi | |
} | |
DAEMON_OPTS=" --uid www-data --gid desarrolloweb -x /export/web/$NAME/uwsgi.xml -d /var/log/uwsgi/$NAME.log --pidfile /var/run/$NAME.pid --socket /tmp/$NAME.sock" | |
case "$1" in | |
start) | |
echo -n "Starting $DESC: " | |
PID=$(get_pid) | |
if [ -z "$PID" ]; then | |
echo "in" | |
[ -f /var/run/$NAME.pid ] && rm -f /var/run/$NAME.pid | |
touch /var/run/$NAME.pid | |
chown $OWNER /var/run/$NAME.pid | |
echo "$DAEMON $DAEMON_OPTS" | |
if ! eval "$DAEMON $DAEMON_OPTS" 2>&1; then | |
echo "uwsgi probleme" | |
else | |
echo "loading $NAME success." | |
fi | |
else | |
echo "..PID $PID exist remove it" | |
fi | |
;; | |
stop) | |
echo -n "Stopping $DESC: " | |
PID=$(get_pid) | |
echo $PID | |
if [ ! -z "$PID" ]; then | |
if ! kill $PID > /dev/null 2>&1; then | |
echo "Could not send SIGTERM to process $PID" >&2 | |
else | |
kill -s 3 $PID &> /dev/null | |
fi | |
fi | |
if [ $? -gt 0 ]; then | |
echo "was not running" | |
exit 1 | |
else | |
echo "$NAME." | |
echo "doing rm to $NAME.pid" | |
rm -f /var/run/$NAME.pid &> /dev/null | |
rm -f /tmp/$NAME.sock &> /dev/null | |
fi | |
;; | |
reload) | |
echo "Reloading $NAME" | |
PID=$(get_pid) | |
[ ! -z "$PID" ] && kill -s 1 $PID &> /dev/null | |
if [ $? -gt 0 ]; then | |
echo "was not running" | |
exit 1 | |
else | |
echo "$NAME." | |
rm -f /var/run/$NAME.pid &> /dev/null | |
rm -f /tmp/$NAME.sock &> /dev/null | |
fi | |
;; | |
force-reload) | |
echo "Reloading $NAME" | |
PID=$(get_pid) | |
[ ! -z "$PID" ] && kill -s 15 $PID &> /dev/null | |
if [ $? -gt 0 ]; then | |
echo "was not running" | |
exit 1 | |
else | |
echo "$NAME." | |
rm -f /var/run/$NAME.pid &> /dev/null | |
rm -f /tmp/$NAME.sock &> /dev/null | |
fi | |
;; | |
restart) | |
$0 stop | |
sleep 2 | |
$0 start | |
;; | |
status) | |
#killall -10 $DAEMON | |
;; | |
*) | |
N=/etc/init.d/$NAME | |
echo "Usage: $N {start|stop|restart|reload|force-reload|status}" >&2 | |
exit 1 | |
;; | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment