Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Mar 31st, 2012  |  syntax: None  |  size: 3.25 KB  |  hits: 114  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #! /bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides:          tvheadend
  4. # Required-Start:    $local_fs $remote_fs udev
  5. # Required-Stop:     $local_fs $remote_fs
  6. # Default-Start:     2 3 4 5
  7. # Default-Stop:      0 1 6
  8. ### END INIT INFO
  9.  
  10. # Author: Andreas Ă–man
  11.  
  12. # Do NOT "set -e"
  13.  
  14. # PATH should only include /usr/* if it runs after the mountnfs.sh script
  15. PATH=/usr/sbin:/usr/bin:/sbin:/bin
  16. DESC="HTS Tvheadend"
  17. NAME=tvheadend
  18. DAEMON=/usr/bin/$NAME
  19. DAEMON_ARGS="-f -u hts -g video -s -d"
  20. PIDFILE=/var/run/$NAME.pid
  21. SCRIPTNAME=/etc/init.d/$NAME
  22.  
  23. # Exit if the package is not installed
  24. [ -x "$DAEMON" ] || exit 0
  25.  
  26. # Read configuration variable file if it is present
  27. [ -r /etc/default/$NAME ] && . /etc/default/$NAME
  28.  
  29. # Load the VERBOSE setting and other rcS variables
  30. [ -f /etc/default/rcS ] && . /etc/default/rcS
  31.  
  32. # Define LSB log_* functions.
  33. # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
  34. . /lib/lsb/init-functions
  35.  
  36. #
  37. # Function that starts the daemon/service
  38. #
  39. do_start()
  40. {
  41.         # Return
  42.         #   0 if daemon has been started
  43.         #   1 if daemon was already running
  44.         #   2 if daemon could not be started
  45.         udevadm settle
  46.         start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
  47.                 || return 1
  48.         start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- $DAEMON_ARGS  \
  49.                 || return 2
  50. }
  51.  
  52. #
  53. # Function that stops the daemon/service
  54. #
  55. do_stop()
  56. {
  57.         # Return
  58.         #   0 if daemon has been stopped
  59.         #   1 if daemon was already stopped
  60.         #   2 if daemon could not be stopped
  61.         #   other if a failure occurred
  62.         start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
  63.         RETVAL="$?"
  64.         [ "$RETVAL" = 2 ] && return 2
  65.         # Many daemons don't delete their pidfiles when they exit.
  66.         rm -f $PIDFILE
  67.         return "$RETVAL"
  68. }
  69.  
  70.  
  71. case "$1" in
  72.   start)
  73.         [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
  74.         do_start
  75.         case "$?" in
  76.                 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  77.                 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  78.         esac
  79.         ;;
  80.   stop)
  81.         [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
  82.         do_stop
  83.         case "$?" in
  84.                 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  85.                 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  86.         esac
  87.         ;;
  88.   restart|force-reload)
  89.         #
  90.         # If the "reload" option is implemented then remove the
  91.         # 'force-reload' alias
  92.         #
  93.         log_daemon_msg "Restarting $DESC" "$NAME"
  94.         do_stop
  95.         case "$?" in
  96.           0|1)
  97.                 do_start
  98.                 case "$?" in
  99.                         0) log_end_msg 0 ;;
  100.                         1) log_end_msg 1 ;; # Old process is still running
  101.                         *) log_end_msg 1 ;; # Failed to start
  102.                 esac
  103.                 ;;
  104.           *)
  105.                 # Failed to stop
  106.                 log_end_msg 1
  107.                 ;;
  108.         esac
  109.         ;;
  110.   *)
  111.         echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
  112.         exit 3
  113.         ;;
  114. esac