Advertisement
Trinket

transmission-daemon

Mar 3rd, 2013
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 5.26 KB | None | 0 0
  1. #! /bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides:          transmission-daemon
  4. # Required-Start:    networking
  5. # Required-Stop:     networking
  6. # Default-Start:     2 3 5
  7. # Default-Stop:      0 1 6
  8. # Short-Description: Start the transmission BitTorrent daemon client.
  9. ### END INIT INFO
  10.  
  11. # Original Author: Lennart A. JÃŒtte, based on Rob Howell's script
  12. # Modified by Maarten Van Coile & others (on IRC)
  13.  
  14. # Do NOT "set -e"
  15.  
  16. #
  17. # ----- CONFIGURATION -----
  18. #
  19. # For the default location Transmission uses, visit:
  20. # http://trac.transmissionbt.com/wiki/ConfigFiles
  21. # For a guide on how set the preferences, visit:
  22. # http://trac.transmissionbt.com/wiki/EditConfigFiles
  23. # For the available environement variables, visit:
  24. # http://trac.transmissionbt.com/wiki/EnvironmentVariables
  25. #
  26. # The name of the user that should run Transmission.
  27. # It's RECOMENDED to run Transmission in it's own user,
  28. # by default, this is set to 'transmission'.
  29. # For the sake of security you shouldn't set a password
  30. # on this user
  31. USERNAME=transmission
  32. GROUP=download
  33.  
  34. # ----- *ADVANCED* CONFIGURATION -----
  35. # Only change these options if you know what you are doing!
  36. #
  37. # The folder where Transmission stores the config & web files.
  38. # ONLY change this you have it at a non-default location
  39. #TRANSMISSION_HOME="/var/lib/transmission-daemon"
  40. #TRANSMISSION_WEB_HOME="/usr/share/transmission/web"
  41. #
  42. # The arguments passed on to transmission-daemon.
  43. # ONLY change this you need to, otherwise use the
  44. # settings file as per above.
  45. TRANSMISSION_ARGS="--config-dir /var/lib/transmission-daemon/info"
  46.  
  47.  
  48. # ----- END OF CONFIGURATION -----
  49. #
  50. # PATH should only include /usr/* if it runs after the mountnfs.sh script.
  51. PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
  52. DESC="bittorrent client"
  53. NAME=transmission-daemon
  54. DAEMON=$(which $NAME)
  55. PIDFILE=/var/run/$NAME.pid
  56. SCRIPTNAME=/etc/init.d/$NAME
  57. DAEMON_OPTS="-N 10 -I best-effort:6
  58.  
  59. # Exit if the package is not installed
  60. [ -x "$DAEMON" ] || exit 0
  61.  
  62. # Read configuration variable file if it is present
  63. [ -r /etc/default/$NAME ] && . /etc/default/$NAME
  64.  
  65. # Load the VERBOSE setting and other rcS variables
  66. [ -f /etc/default/rcS ] && . /etc/default/rcS
  67.  
  68. #
  69. # Function that starts the daemon/service
  70. #
  71.  
  72. do_start()
  73. {
  74.    # Export the configuration/web directory, if set
  75.    if [ -n "$TRANSMISSION_HOME" ]; then
  76.          export TRANSMISSION_HOME
  77.    fi
  78.    if [ -n "$TRANSMISSION_WEB_HOME" ]; then
  79.          export TRANSMISSION_WEB_HOME
  80.    fi
  81.  
  82.    # Return
  83.    #   0 if daemon has been started
  84.    #   1 if daemon was already running
  85.    #   2 if daemon could not be started
  86.    start-stop-daemon $DAEMON_OPTS --chuid $USERNAME:$GROUP --start --pidfile $PIDFILE --make-pidfile \
  87.            --exec $DAEMON --background --test -- -f $TRANSMISSION_ARGS > /dev/null \
  88.            || return 1
  89.    start-stop-daemon $DAEMON_OPTS --chuid $USERNAME:$GROUP --start --pidfile $PIDFILE --make-pidfile \
  90.            --exec $DAEMON --background -- -f $TRANSMISSION_ARGS \
  91.            || return 2
  92. }
  93.  
  94. #
  95. # Function that stops the daemon/service
  96. #
  97. do_stop()
  98. {
  99.        # Return
  100.        #   0 if daemon has been stopped
  101.        #   1 if daemon was already stopped
  102.        #   2 if daemon could not be stopped
  103.        #   other if a failure occurred
  104.        start-stop-daemon --stop --quiet --retry=TERM/10/KILL/5 --pidfile $PIDFILE --exec $DAEMON
  105.        RETVAL="$?"
  106.        [ "$RETVAL" = 2 ] && return 2
  107.  
  108.        # Wait for children to finish too if this is a daemon that forks
  109.        # and if the daemon is only ever run from this initscript.
  110.       # If the above conditions are not satisfied then add some other code
  111.        # that waits for the process to drop all resources that could be
  112.        # needed by services started subsequently.  A last resort is to
  113.        # sleep for some time.
  114.  
  115.        start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
  116.        [ "$?" = 2 ] && return 2
  117.  
  118.        # Many daemons don't delete their pidfiles when they exit.
  119.        rm -f $PIDFILE
  120.  
  121.        return "$RETVAL"
  122. }
  123.  
  124. case "$1" in
  125.  start)
  126.        echo "Starting $DESC" "$NAME..."
  127.        do_start
  128.        case "$?" in
  129.                0|1) echo "   Starting $DESC $NAME succeeded" ;;
  130.                *)   echo "   Starting $DESC $NAME failed" ;;
  131.        esac
  132.        ;;
  133.  stop)
  134.        echo "Stopping $DESC $NAME..."
  135.        do_stop
  136.        case "$?" in
  137.                0|1) echo "   Stopping $DESC $NAME succeeded" ;;
  138.                *)   echo "   Stopping $DESC $NAME failed" ;;
  139.        esac
  140.        ;;
  141.  restart|force-reload)
  142.        #
  143.        # If the "reload" option is implemented then remove the
  144.        # 'force-reload' alias
  145.        #
  146.        echo "Restarting $DESC $NAME..."
  147.        do_stop
  148.        case "$?" in
  149.          0|1)
  150.                do_start
  151.                case "$?" in
  152.                    0|1) echo "   Restarting $DESC $NAME succeeded" ;;
  153.                    *)   echo "   Restarting $DESC $NAME failed: couldn't start $NAME" ;;
  154.                esac
  155.                ;;
  156.          *)
  157.                echo "   Restarting $DESC $NAME failed: couldn't stop $NAME" ;;
  158.        esac
  159.        ;;
  160.  *)
  161.        echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
  162.        exit 3
  163.        ;;
  164. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement