Advertisement
Guest User

initD

a guest
May 18th, 2015
481
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1.  
  2. #!/bin/bash
  3. # myapp daemon
  4. # chkconfig: 345 20 80
  5. # description: xyz python daemon
  6. # processname: xyz
  7.  
  8. # Source function library.
  9. . /etc/rc.d/init.d/functions
  10.  
  11. DIR=/opt/mount/xyz/current/src
  12. DAEMON=$DIR/main.py
  13. DAEMON_NAME=xyz
  14. PYTHON=/usr/local/bin/python2.7
  15. DAEMON_OPTS="--port=8080 --debug --log_file_prefix=/opt/mount/xyz/logs/xyz --log_file_max_size=1000000 --env=stage"
  16. DAEMON_USER=python
  17. LOGFILE="/opt/mount/xyz/logs/error.log"
  18. LOGPATH=$(dirname $LOGFILE)
  19. PIDFILE=/var/run/$DAEMON_NAME.pid
  20.  
  21.  
  22. case "$1" in
  23. start)
  24. printf "%-50s" "Starting $DAEMON_NAME..."
  25. cd $DIR
  26. [ -d $LOGPATH ] || mkdir $LOGPATH
  27. [ -f $LOGFILE ] || su $DAEMON_USER -c 'touch $LOGFILE'
  28. PID=`$PYTHON $DAEMON $DAEMON_OPTS > $LOGFILE 2>&1 & echo $!`
  29. #echo "Saving PID" $PID " to " $PIDFILE
  30. if [ -z $PID ]; then
  31. printf "%s\n" "Fail"
  32. else
  33. echo $PID > $PIDFILE
  34. printf "%s\n" "Ok"
  35. fi
  36. ;;
  37. status)
  38. printf "%-50s" "Checking $DAEMON_NAME..."
  39. if [ -f $PIDFILE ]; then
  40. PID=`cat $PIDFILE`
  41. if [ -z "`ps axf | grep ${PID} | grep -v grep`" ]; then
  42. printf "%s\n" "Process dead but pidfile exists"
  43. else
  44. echo "Running"
  45. fi
  46. else
  47. printf "%s\n" "Service not running"
  48. fi
  49. ;;
  50. stop)
  51. printf "%-50s" "Stopping $DAEMONNAME"
  52. PID=`cat $PIDFILE`
  53. cd $DIR
  54. if [ -f $PIDFILE ]; then
  55. kill -HUP $PID
  56. printf "%s\n" "Ok"
  57. rm -f $PIDFILE
  58. else
  59. printf "%s\n" "pidfile not found"
  60. fi
  61. ;;
  62.  
  63. restart)
  64. $0 stop
  65. $0 start
  66. ;;
  67.  
  68. *)
  69. echo "Usage: $0 {status|start|stop|restart}"
  70. exit 1
  71. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement