YamashitaRen

Untitled

Oct 15th, 2014
486
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.37 KB | None | 0 0
  1. BB@WY:~$ cat /etc/init.d/deluged
  2. #!/bin/sh
  3. ### BEGIN INIT INFO
  4. # Provides: deluged
  5. # Required-Start: $local_fs $remote_fs
  6. # Required-Stop: $local_fs $remote_fs
  7. # Should-Start: $network
  8. # Should-Stop: $network
  9. # Default-Start: 2 3 4 5
  10. # Default-Stop: 0 1 6
  11. # Short-Description: Start or stop the Deluge BitTorrent daemon.
  12. # Description: Start or stop the Deluge BitTorrent daemon.
  13. ### END INIT INFO
  14.  
  15. # Authors: Tanguy Ortolo <[email protected]>,
  16. # Cristian Greco <[email protected]>
  17.  
  18. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  19. DESC="Deluge BitTorrent Daemon"
  20. NAME="deluged"
  21. DAEMON=/usr/bin/$NAME
  22. DAEMON_ARGS="-d -c /var/lib/deluged/config -l /var/log/deluged/daemon.log -L info"
  23. USER=debian-deluged
  24. MASK=0027
  25. PIDFILE=/var/run/$NAME.pid
  26. SCRIPTNAME=/etc/init.d/$NAME
  27.  
  28. # Exit if the package is not installed
  29. [ -x "$DAEMON" ] || exit 0
  30.  
  31. ENABLE_DELUGED=1
  32.  
  33. # Read configuration variable file if it is present
  34. [ -r /etc/default/$NAME ] && . /etc/default/$NAME
  35.  
  36. # Load the VERBOSE setting and other rcS variables
  37. [ -f /etc/default/rcS ] && . /etc/default/rcS
  38.  
  39. # Define LSB log_* functions.
  40. # Depend on lsb-base (>= 3.0-6) to ensure that this file is present
  41. # and status_of_proc is working.
  42. . /lib/lsb/init-functions
  43.  
  44. #
  45. # Function that starts the daemon/service
  46. #
  47. do_start()
  48. {
  49. if [ $ENABLE_DELUGED != 1 ]; then
  50. log_progress_msg "Not starting ${DESC} ${NAME}, disabled in /etc/default/${NAME}"
  51. else
  52. # Return
  53. # 0 if daemon has been started
  54. # 1 if daemon was already running
  55. # 2 if daemon could not be started
  56. start-stop-daemon --start --background --quiet --pidfile $PIDFILE --exec $DAEMON \
  57. --chuid $USER --umask $MASK --test > /dev/null \
  58. || return 1
  59.  
  60. start-stop-daemon --start --background --quiet --pidfile $PIDFILE --make-pidfile --exec $DAEMON \
  61. --chuid $USER --umask $MASK -- $DAEMON_ARGS \
  62. || return 2
  63. fi
  64. }
  65.  
  66. #
  67. # Function that stops the daemon/service
  68. #
  69. do_stop()
  70. {
  71. # Return
  72. # 0 if daemon has been stopped
  73. # 1 if daemon was already stopped
  74. # 2 if daemon could not be stopped
  75. # other if a failure occurred
  76.  
  77. start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE
  78. RETVAL="$?"
  79. [ "$RETVAL" = "2" ] && return 2
  80.  
  81. rm -f $PIDFILE
  82. return "$RETVAL"
  83. }
  84.  
  85. case "$1" in
  86. start)
  87. [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
  88. do_start
  89. case "$?" in
  90. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  91. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  92. esac
  93. ;;
  94. stop)
  95. [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
  96. do_stop
  97. case "$?" in
  98. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  99. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  100. esac
  101. ;;
  102. status)
  103. status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
  104. ;;
  105. restart|force-reload)
  106. log_daemon_msg "Restarting $DESC" "$NAME"
  107. do_stop
  108. case "$?" in
  109. 0|1)
  110. do_start
  111. case "$?" in
  112. 0) log_end_msg 0 ;;
  113. 1) log_end_msg 1 ;; # Old process is still running
  114. *) log_end_msg 1 ;; # Failed to start
  115. esac
  116. ;;
  117. *)
  118. # Failed to stop
  119. log_end_msg 1
  120. ;;
  121. esac
  122. ;;
  123. *)
  124. echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
  125. exit 3
  126. ;;
  127. esac
  128.  
  129. :
Add Comment
Please, Sign In to add comment