longlostbro

/etc/init.d/deluged

Aug 5th, 2015
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.76 KB | None | 0 0
  1. #!/bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides:          deluged
  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.  
  17. ## Change log:
  18. #      - Removed deluge-web from list
  19.  
  20. PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
  21. DESC="Deluge Daemon"
  22. NAME1="deluged"
  23. DAEMON1=/usr/bin/deluged
  24. INTERFACE="-i $(/sbin/ifconfig tun0 |grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}')"
  25. DAEMON1_ARGS="-d -c /var/lib/deluged/config -l /var/log/deluged/daemon.log -L error ${INTERFACE} -p 8112 -u 192.168.1.15"
  26. PIDFILE1=/var/run/$NAME1.pid
  27. UMASK=007
  28. PKGNAME=deluged
  29. SCRIPTNAME=/etc/init.d/$PKGNAME
  30.  
  31. # Exit if the package is not installed
  32. [ -x "$DAEMON1" ] || 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 --umask $UMASK --test > /dev/null
  67.    RETVAL1="$?"
  68.  
  69.    [ "$RETVAL1" = "0" ] || return 1
  70.  
  71.    start-stop-daemon --start --background --quiet --pidfile $PIDFILE1 --make-pidfile --exec $DAEMON1 \
  72.       --chuid $DELUGED_USER --user $DELUGED_USER --umask $UMASK -- $DAEMON1_ARGS
  73.    RETVAL1="$?"
  74.  
  75.    [ "$RETVAL1" = "0" ] || return 2
  76. }
  77.  
  78. #
  79. # Function that stops the daemon/service
  80. #
  81. do_stop()
  82. {
  83.    # Return
  84.    #   0 if daemon has been stopped
  85.    #   1 if daemon was already stopped
  86.    #   2 if daemon could not be stopped
  87.    #   other if a failure occurred
  88.  
  89.    start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --user $DELUGED_USER --pidfile $PIDFILE1
  90.    RETVAL1="$?"
  91.    [ "$RETVAL1" = "2" ] && return 2
  92.  
  93.    rm -f $PIDFILE1
  94.  
  95.    [ "$RETVAL1" = "0" ] && return 0 || return 1
  96. }
  97.  
  98. case "$1" in
  99.   start)
  100.    [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME1"
  101.    do_start
  102.    case "$?" in
  103.       0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  104.       2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  105.    esac
  106.    ;;
  107.   stop)
  108.    [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME1"
  109.    do_stop
  110.    case "$?" in
  111.       0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  112.       2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  113.    esac
  114.    ;;
  115.   restart|force-reload)
  116.    log_daemon_msg "Restarting $DESC" "$NAME1"
  117.    do_stop
  118.    case "$?" in
  119.      0|1)
  120.       do_start
  121.       case "$?" in
  122.          0) log_end_msg 0 ;;
  123.          1) log_end_msg 1 ;; # Old process is still running
  124.          *) log_end_msg 1 ;; # Failed to start
  125.       esac
  126.       ;;
  127.      *)
  128.         # Failed to stop
  129.       log_end_msg 1
  130.       ;;
  131.    esac
  132.    ;;
  133.   *)
  134.    echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
  135.    exit 3
  136.    ;;
  137. esac
  138.  
  139. :
Advertisement
Add Comment
Please, Sign In to add comment