Loading

script init linkr

  1. #!/bin/bash
  2.  
  3. if [ true != "$INIT_D_SCRIPT_SOURCED" ] ; then
  4.     set "$0" "$@"; INIT_D_SCRIPT_SOURCED=true . /lib/init/init-d-script
  5. fi
  6. ### BEGIN INIT INFO
  7. # Provides:          linkrd
  8. # Required-Start:    $remote_fs $syslog
  9. # Required-Stop:     $remote_fs $syslog
  10. # Default-Start:     2 3 4 5
  11. # Default-Stop:      0 1 6
  12. # Short-Description: linkr init daemon
  13. # Description:       This file should be used to construct scripts to be
  14. #                    placed in /etc/init.d.  This example start a
  15. #                    single forking daemon capable of writing a pid
  16. #                    file.  To get other behavoirs, implemend
  17. #                    do_start(), do_stop() or other functions to
  18. #                    override the defaults in /lib/init/init-d-script.
  19. ### END INIT INFO
  20.  
  21.  
  22. # chkconfig: 345 20 80
  23.  
  24. DAEMON_PATH="/home/www/linkr"
  25.  
  26. DAEMON=linkr.py
  27. DAEMONOPTS="-my opts"
  28.  
  29. NAME=linkr
  30. DESC="linkr daemon init"
  31. PIDFILE=/var/run/$NAME.pid
  32. SCRIPTNAME=/etc/init.d/$NAME
  33.  
  34. case "$1" in
  35. start)
  36.         printf "%-50s" "Starting $NAME..."
  37.         cd $DAEMON_PATH
  38.         PID=`/home/www/linkr/env/bin/python2 $DAEMON $DAEMONOPTS > /dev/null 2>&1 & echo $!`
  39.         #echo "Saving PID" $PID " to " $PIDFILE
  40.         if [ -z $PID ]; then
  41.             printf "%s\n" "Fail"
  42.         else
  43.             echo $PID > $PIDFILE
  44.             printf "%s\n" "Ok"
  45.         fi
  46. ;;
  47. status)
  48.         printf "%-50s" "Checking $NAME..."
  49.         if [ -f $PIDFILE ]; then
  50.             PID=`cat $PIDFILE`
  51.             if [ -z "`ps axf | grep ${PID} | grep -v grep`" ]; then
  52.                 printf "%s\n" "Process dead but pidfile exists"
  53.             else
  54.                 echo "Running"
  55.             fi
  56.         else
  57.             printf "%s\n" "Service not running"
  58.         fi
  59. ;;
  60. stop)
  61.         printf "%-50s" "Stopping $NAME"
  62.             PID=`cat $PIDFILE`
  63.             cd $DAEMON_PATH
  64.         if [ -f $PIDFILE ]; then
  65.             kill -HUP $PID
  66.             printf "%s\n" "Ok"
  67.             rm -f $PIDFILE
  68.         else
  69.             printf "%s\n" "pidfile not found"
  70.         fi
  71. ;;
  72.  
  73. restart)
  74.         $0 stop
  75.         $0 start
  76. ;;
  77.  
  78. *)
  79.         echo "Usage: $0 {status|start|stop|restart}"
  80.         exit 1
  81. esac

Comments