Loading

/etc/init.d/fail2rest

  1. #! /bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides:          fail2rest
  4. # Required-Start:    $syslog $network
  5. # Required-Stop:     $syslog
  6. # Should-Start:      mysql postgresql
  7. # Should-Stop:       mysql postgresql
  8. # Default-Start:     2 3 4 5
  9. # Default-Stop:      0 1 6
  10. # Short-Description: Fail2rest.
  11. # Description:       Fail2rest.
  12. ### END INIT INFO
  13. # Do NOT "set -e"
  14.  
  15. # PATH should only include /usr/* if it runs after the mountnfs.sh script
  16. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  17. DESC="fail2rest"
  18. NAME=fail2rest
  19. SERVICEVERBOSE=yes
  20. PIDFILE=/var/run/$NAME.pid
  21. SCRIPTNAME=/etc/init.d/$NAME
  22. WORKINGDIR=/home/tools/go
  23. DAEMON=$WORKINGDIR/bin/$NAME
  24. DAEMON_ARGS="--config /etc/fail2rest.json"
  25. USER=root
  26.  
  27. # Read configuration variable file if it is present
  28. [ -r /etc/default/$NAME ] && . /etc/default/$NAME
  29.  
  30. # Exit if the package is not installed
  31. [ -x "$DAEMON" ] || exit 0
  32.  
  33. # Load the VERBOSE setting and other rcS variables
  34. . /lib/init/vars.sh
  35.  
  36. # Define LSB log_* functions.
  37. # Depend on lsb-base (>= 3.2-14) to ensure that this file is present
  38. # and status_of_proc is working.
  39. . /lib/lsb/init-functions
  40.  
  41. #
  42. # Function that starts the daemon/service
  43. #
  44. do_start()
  45. {
  46.         # Return
  47.         #   0 if daemon has been started
  48.         #   1 if daemon was already running
  49.         #   2 if daemon could not be started
  50.  /bin/sh  -c "USER=$USER start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile --exec $DAEMON -- $DAEMON_ARGS > /dev/null \\
  51.                        --test --chdir $WORKINGDIR --chuid $USER \\
  52.                        || return 1"
  53.  /bin/sh  -c "USER=$USER start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile \\
  54.                        --background --chdir $WORKINGDIR --chuid $USER \\
  55.                        --exec $DAEMON -- $DAEMON_ARGS \\
  56.                        || return 2"
  57. }
  58.  
  59. #
  60. # Function that stops the daemon/service
  61. #
  62. do_stop()
  63. {
  64.         # Return
  65.         #   0 if daemon has been stopped
  66.         #   1 if daemon was already stopped
  67.         #   2 if daemon could not be stopped
  68.         #   other if a failure occurred
  69.         start-stop-daemon --stop --quiet --retry=TERM/1/KILL/5 --pidfile $PIDFILE --name $NAME
  70.         RETVAL="$?"
  71.         [ "$RETVAL" = 2 ] && return 2
  72.         start-stop-daemon --stop --quiet --oknodo --retry=0/1/KILL/5 --exec $DAEMON
  73.         [ "$?" = 2 ] && return 2
  74.         # Many daemons don't delete their pidfiles when they exit.
  75.         rm -f $PIDFILE
  76.         return "$RETVAL"
  77. }
  78.  
  79.  
  80. case "$1" in
  81.   start)
  82.         [ "$SERVICEVERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
  83.         do_start
  84.         case "$?" in
  85.                 0|1) [ "$SERVICEVERBOSE" != no ] && log_end_msg 0 ;;
  86.                 2) [ "$SERVICEVERBOSE" != no ] && log_end_msg 1 ;;
  87.         esac
  88.         ;;
  89.   stop)
  90.         [ "$SERVICEVERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
  91.         do_stop
  92.         case "$?" in
  93.                 0|1) [ "$SERVICEVERBOSE" != no ] && log_end_msg 0 ;;
  94.                 2) [ "$SERVICEVERBOSE" != no ] && log_end_msg 1 ;;
  95.         esac
  96.         ;;
  97.   status)
  98.         status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
  99.         ;;
  100.   restart|force-reload)
  101.         log_daemon_msg "Restarting $DESC" "$NAME"
  102.         do_stop
  103.         case "$?" in
  104.           0|1)
  105.                 do_start
  106.                 case "$?" in
  107.                         0) log_end_msg 0 ;;
  108.                         1) log_end_msg 1 ;; # Old process is still running
  109.                         *) log_end_msg 1 ;; # Failed to start
  110.                 esac
  111.                 ;;
  112.           *)
  113.                 # Failed to stop
  114.                 log_end_msg 1
  115.                 ;;
  116.                 esac
  117.         ;;
  118.   *)
  119.                 echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
  120.                 exit 3
  121.                 ;;
  122. esac

Comments