Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # myapp daemon
- # chkconfig: 345 20 80
- # description: xyz python daemon
- # processname: xyz
- # Source function library.
- . /etc/rc.d/init.d/functions
- DIR=/opt/mount/xyz/current/src
- DAEMON=$DIR/main.py
- DAEMON_NAME=xyz
- PYTHON=/usr/local/bin/python2.7
- DAEMON_OPTS="--port=8080 --debug --log_file_prefix=/opt/mount/xyz/logs/xyz --log_file_max_size=1000000 --env=stage"
- DAEMON_USER=python
- LOGFILE="/opt/mount/xyz/logs/error.log"
- LOGPATH=$(dirname $LOGFILE)
- PIDFILE=/var/run/$DAEMON_NAME.pid
- case "$1" in
- start)
- printf "%-50s" "Starting $DAEMON_NAME..."
- cd $DIR
- [ -d $LOGPATH ] || mkdir $LOGPATH
- [ -f $LOGFILE ] || su $DAEMON_USER -c 'touch $LOGFILE'
- PID=`$PYTHON $DAEMON $DAEMON_OPTS > $LOGFILE 2>&1 & echo $!`
- #echo "Saving PID" $PID " to " $PIDFILE
- if [ -z $PID ]; then
- printf "%s\n" "Fail"
- else
- echo $PID > $PIDFILE
- printf "%s\n" "Ok"
- fi
- ;;
- status)
- printf "%-50s" "Checking $DAEMON_NAME..."
- if [ -f $PIDFILE ]; then
- PID=`cat $PIDFILE`
- if [ -z "`ps axf | grep ${PID} | grep -v grep`" ]; then
- printf "%s\n" "Process dead but pidfile exists"
- else
- echo "Running"
- fi
- else
- printf "%s\n" "Service not running"
- fi
- ;;
- stop)
- printf "%-50s" "Stopping $DAEMONNAME"
- PID=`cat $PIDFILE`
- cd $DIR
- if [ -f $PIDFILE ]; then
- kill -HUP $PID
- printf "%s\n" "Ok"
- rm -f $PIDFILE
- else
- printf "%s\n" "pidfile not found"
- fi
- ;;
- restart)
- $0 stop
- $0 start
- ;;
- *)
- echo "Usage: $0 {status|start|stop|restart}"
- exit 1
- esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement