daily pastebin goal
51%
SHARE
TWEET

Untitled

SoulSmasher Jul 28th, 2012 131 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides:          deluge-daemon
  4. # Required-Start:    $local_fs $remote_fs
  5. # Required-Stop:     $local_fs $remote_fs
  6. # Should-Start:      $network
  7. # Should-Stop:       $network
  8. # Default-Start:     2 3 4 5
  9. # Default-Stop:      0 1 6
  10. # Short-Description: Daemonized version of deluge and webui.
  11. # Description:       Starts the deluge daemon with the user specified in
  12. #                    /etc/default/deluge-daemon.
  13. ### END INIT INFO
  14.  
  15. # Author: Adolfo R. Brandes
  16. # Modified: Sami Olmari
  17.  
  18. PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
  19. DESC="Deluge Daemon"
  20. NAME1="deluged"
  21. NAME2="deluge-web"
  22. DAEMON1=/usr/bin/deluged
  23. DAEMON1_ARGS="-d -c /var/lib/deluge -l /var/log/deluged.log -L warning"
  24. DAEMON2=/usr/bin/deluge-web
  25. DAEMON2_ARGS="-p 9092 -c /var/lib/deluge -l /var/log/deluge-web.log -L warning"
  26. PIDFILE1=/var/run/$NAME1.pid
  27. PIDFILE2=/var/run/$NAME2.pid
  28. PKGNAME=deluge-daemon
  29. SCRIPTNAME=/etc/init.d/$PKGNAME
  30.  
  31. # Exit if the package is not installed
  32. [ -x "$DAEMON1" -a -x "$DAEMON2" ] || exit 0
  33.  
  34. # Read configuration variable file if it is present
  35. [ -r /etc/default/$PKGNAME ] && . /etc/default/$PKGNAME
  36.  
  37. # Load the VERBOSE setting and other rcS variables
  38. [ -f /etc/default/rcS ] && . /etc/default/rcS
  39.  
  40. # Define LSB log_* functions.
  41. # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
  42. . /lib/lsb/init-functions
  43.  
  44. if [ -z "$RUN_AT_STARTUP" -o "$RUN_AT_STARTUP" != "YES" ]
  45. then
  46.    log_warning_msg "Not starting $PKGNAME, edit /etc/default/$PKGNAME to start it."
  47.    exit 0
  48. fi
  49.  
  50. if [ -z "$DELUGED_USER" ]
  51. then
  52.     log_warning_msg "Not starting $PKGNAME, DELUGED_USER not set in /etc/default/$PKGNAME."
  53.     exit 0
  54. fi
  55.  
  56. #
  57. # Function that starts the daemon/service
  58. #
  59. do_start()
  60. {
  61.    # Return
  62.    #   0 if daemon has been started
  63.    #   1 if daemon was already running
  64.    #   2 if daemon could not be started
  65.    start-stop-daemon --start --background --quiet --pidfile $PIDFILE1 --exec $DAEMON1 \
  66.       --chuid $DELUGED_USER --user $DELUGED_USER --test > /dev/null
  67.    RETVAL1="$?"
  68.    start-stop-daemon --start --background --quiet --pidfile $PIDFILE2 --exec $DAEMON2 \
  69.       --chuid $DELUGED_USER --user $DELUGED_USER --test > /dev/null
  70.    RETVAL2="$?"
  71.    [ "$RETVAL1" = "0" -a "$RETVAL2" = "0" ] || return 1
  72.  
  73.    start-stop-daemon --start --background --quiet --pidfile $PIDFILE1 --make-pidfile --exec $DAEMON1 \
  74.       --chuid $DELUGED_USER --user $DELUGED_USER -- $DAEMON1_ARGS
  75.    RETVAL1="$?"
  76.         sleep 2
  77.    start-stop-daemon --start --background --quiet --pidfile $PIDFILE2 --make-pidfile --exec $DAEMON2 \
  78.       --chuid $DELUGED_USER --user $DELUGED_USER -- $DAEMON2_ARGS
  79.    RETVAL2="$?"
  80.    [ "$RETVAL1" = "0" -a "$RETVAL2" = "0" ] || return 2
  81. }
  82.  
  83. #
  84. # Function that stops the daemon/service
  85. #
  86. do_stop()
  87. {
  88.    # Return
  89.    #   0 if daemon has been stopped
  90.    #   1 if daemon was already stopped
  91.    #   2 if daemon could not be stopped
  92.    #   other if a failure occurred
  93.  
  94.    start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --user $DELUGED_USER --pidfile $PIDFILE2
  95.    RETVAL2="$?"
  96.    start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --user $DELUGED_USER --pidfile $PIDFILE1
  97.    RETVAL1="$?"
  98.    [ "$RETVAL1" = "2" -o "$RETVAL2" = "2" ] && return 2
  99.  
  100.    rm -f $PIDFILE1 $PIDFILE2
  101.  
  102.    [ "$RETVAL1" = "0" -a "$RETVAL2" = "0" ] && return 0 || return 1
  103. }
  104.  
  105. case "$1" in
  106.   start)
  107.    [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME1"
  108.    do_start
  109.    case "$?" in
  110.       0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  111.       2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  112.    esac
  113.    ;;
  114.   stop)
  115.    [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME1"
  116.    do_stop
  117.    case "$?" in
  118.       0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  119.       2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  120.    esac
  121.    ;;
  122.   restart|force-reload)
  123.    log_daemon_msg "Restarting $DESC" "$NAME1"
  124.    do_stop
  125.    case "$?" in
  126.      0|1)
  127.       do_start
  128.       case "$?" in
  129.          0) log_end_msg 0 ;;
  130.          1) log_end_msg 1 ;; # Old process is still running
  131.          *) log_end_msg 1 ;; # Failed to start
  132.       esac
  133.       ;;
  134.      *)
  135.         # Failed to stop
  136.       log_end_msg 1
  137.       ;;
  138.    esac
  139.    ;;
  140.   *)
  141.    echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
  142.    exit 3
  143.    ;;
  144. esac
  145.  
  146. :
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top