S92transmission 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. #!/bin/sh
  2. # Original Author: Lennart A. Jtte, based on Rob Howell's script
  3. # Modified by Maarten Van Coile & others (on IRC)
  4. # Changes for buildroot:
  5. # USERNAME points to 'default' in standard installation
  6. # TODO: set logfile with --logfile option
  7. # Do NOT "set -e"
  8. #
  9. # ----- CONFIGURATION -----
  10. #
  11. # For the default location Transmission uses, visit:
  12. # http://trac.transmissionbt.com/wiki/ConfigFiles
  13. # For a guide on how set the preferences, visit:
  14. # http://trac.transmissionbt.com/wiki/EditConfigFiles
  15. # For the available environment variables, visit:
  16. # http://trac.transmissionbt.com/wiki/EnvironmentVariables
  17. #
  18. # The name of the user that should run Transmission.
  19. # It's RECOMMENDED to run Transmission in it's own user,
  20. # by default, this is set to 'transmission'.
  21. # For the sake of security you shouldn't set a password
  22. # on this user
  23. USERNAME=transmission
  24. # ----- *ADVANCED* CONFIGURATION -----
  25. # Only change these options if you know what you are doing!
  26. #
  27. # The folder where Transmission stores the config & web files.
  28. # ONLY change this you have it at a non-default location
  29. #TRANSMISSION_HOME="/var/config/transmission-daemon"
  30. #TRANSMISSION_WEB_HOME="/usr/share/transmission/web"
  31. #
  32. # The arguments passed on to transmission-daemon.
  33. # ONLY change this you need to, otherwise use the
  34. # settings file as per above.
  35. #TRANSMISSION_ARGS=""
  36. # ----- END OF CONFIGURATION -----
  37. #
  38. # PATH should only include /usr/* if it runs after the mountnfs.sh script.
  39. PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
  40. DESC="bittorrent client"
  41. NAME=transmission-daemon
  42. DAEMON=$(which $NAME)
  43. PIDFILE=/var/run/$NAME.pid
  44. SCRIPTNAME=/etc/init.d/$NAME
  45. # Read configuration variable file if it is present
  46. [ -r /etc/default/$NAME ] && . /etc/default/$NAME
  47. # Load the VERBOSE setting and other rcS variables
  48. [ -f /etc/default/rcS ] && . /etc/default/rcS
  49. #
  50. # Function that starts the daemon/service
  51. #
  52. start()
  53. {
  54. # Export the configuration/web directory, if set
  55. if [ -n "$TRANSMISSION_HOME" ]; then
  56. export TRANSMISSION_HOME
  57. fi
  58. if [ -n "$TRANSMISSION_WEB_HOME" ]; then
  59. export TRANSMISSION_WEB_HOME
  60. fi
  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 --chuid $USERNAME --start --pidfile $PIDFILE --make-pidfile \
  66. --exec $DAEMON --background --test -- -f $TRANSMISSION_ARGS > /dev/null \
  67. || return 1
  68. start-stop-daemon --chuid $USERNAME --start --pidfile $PIDFILE --make-pidfile \
  69. --exec $DAEMON --background -- -f $TRANSMISSION_ARGS \
  70. || return 2
  71. }
  72. #
  73. # Function that stops the daemon/service
  74. #
  75. stop()
  76. {
  77. # Return
  78. # 0 if daemon has been stopped
  79. # 1 if daemon was already stopped
  80. # 2 if daemon could not be stopped
  81. # other if a failure occurred
  82. start-stop-daemon --stop --quiet --retry=TERM/10/KILL/5 --pidfile $PIDFILE --exec $DAEMON
  83. RETVAL="$?"
  84. [ "$RETVAL" = 2 ] && return 2
  85. # Wait for children to finish too if this is a daemon that forks
  86. # and if the daemon is only ever run from this initscript.
  87. # If the above conditions are not satisfied then add some other code
  88. # that waits for the process to drop all resources that could be
  89. # needed by services started subsequently. A last resort is to
  90. # sleep for some time.
  91. start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
  92. [ "$?" = 2 ] && return 2
  93. # Many daemons don't delete their pidfiles when they exit.
  94. rm -f $PIDFILE
  95. return "$RETVAL"
  96. }
  97. case "$1" in
  98. start)
  99. echo "Starting $DESC" "$NAME..."
  100. start
  101. case "$?" in
  102. 0|1) echo " Starting $DESC $NAME succeeded" ;;
  103. *) echo " Starting $DESC $NAME failed" ;;
  104. esac
  105. ;;
  106. stop)
  107. echo "Stopping $DESC $NAME..."
  108. stop
  109. case "$?" in
  110. 0|1) echo " Stopping $DESC $NAME succeeded" ;;
  111. *) echo " Stopping $DESC $NAME failed" ;;
  112. esac
  113. ;;
  114. restart|force-reload)
  115. #
  116. # If the "reload" option is implemented then remove the
  117. # 'force-reload' alias
  118. #
  119. echo "Restarting $DESC $NAME..."
  120. stop
  121. case "$?" in
  122. 0|1)
  123. start
  124. case "$?" in
  125. 0|1) echo " Restarting $DESC $NAME succeeded" ;;
  126. *) echo " Restarting $DESC $NAME failed: couldn't start $NAME" ;;
  127. esac
  128. ;;
  129. *)
  130. echo " Restarting $DESC $NAME failed: couldn't stop $NAME" ;;
  131. esac
  132. ;;
  133. *)
  134. echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
  135. exit 3
  136. ;;
  137. esac