blob: d1ffff58b029a33c400ecad4ce166e68ebc07d88 [file] [log] [blame]
Andrew Geissler2ee498a2020-05-29 15:52:06 -05001#! /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
31USERNAME=transmission
32
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/config/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=""
46
47
48# ----- END OF CONFIGURATION -----
49#
50# PATH should only include /usr/* if it runs after the mountnfs.sh script.
51PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
52DESC="bittorrent client"
53NAME=transmission-daemon
54DAEMON=$(which $NAME)
55PIDFILE=/var/run/$NAME.pid
56SCRIPTNAME=/etc/init.d/$NAME
57
58# Exit if the package is not installed
59[ -x "$DAEMON" ] || exit 0
60
61# Read configuration variable file if it is present
62[ -r /etc/default/$NAME ] && . /etc/default/$NAME
63
64# Load the VERBOSE setting and other rcS variables
65[ -f /etc/default/rcS ] && . /etc/default/rcS
66
67#
68# Function that starts the daemon/service
69#
70
71do_start()
72{
73 # Export the configuration/web directory, if set
74 if [ -n "$TRANSMISSION_HOME" ]; then
75 export TRANSMISSION_HOME
76 fi
77 if [ -n "$TRANSMISSION_WEB_HOME" ]; then
78 export TRANSMISSION_WEB_HOME
79 fi
80
81 # Return
82 # 0 if daemon has been started
83 # 1 if daemon was already running
84 # 2 if daemon could not be started
85 start-stop-daemon --chuid $USERNAME --start --pidfile $PIDFILE --make-pidfile \
86 --exec $DAEMON --background --test -- -f $TRANSMISSION_ARGS > /dev/null \
87 || return 1
88 start-stop-daemon --chuid $USERNAME --start --pidfile $PIDFILE --make-pidfile \
89 --exec $DAEMON --background -- -f $TRANSMISSION_ARGS \
90 || return 2
91}
92
93#
94# Function that stops the daemon/service
95#
96do_stop()
97{
98 # Return
99 # 0 if daemon has been stopped
100 # 1 if daemon was already stopped
101 # 2 if daemon could not be stopped
102 # other if a failure occurred
103 start-stop-daemon --stop --quiet --retry=TERM/10/KILL/5 --pidfile $PIDFILE --exec $DAEMON
104 RETVAL="$?"
105 [ "$RETVAL" = 2 ] && return 2
106
107 # Wait for children to finish too if this is a daemon that forks
108 # and if the daemon is only ever run from this initscript.
109 # If the above conditions are not satisfied then add some other code
110 # that waits for the process to drop all resources that could be
111 # needed by services started subsequently. A last resort is to
112 # sleep for some time.
113
114 start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
115 [ "$?" = 2 ] && return 2
116
117 # Many daemons don't delete their pidfiles when they exit.
118 rm -f $PIDFILE
119
120 return "$RETVAL"
121}
122
123case "$1" in
124 start)
125 echo "Starting $DESC" "$NAME..."
126 do_start
127 case "$?" in
128 0|1) echo " Starting $DESC $NAME succeeded" ;;
129 *) echo " Starting $DESC $NAME failed" ;;
130 esac
131 ;;
132 stop)
133 echo "Stopping $DESC $NAME..."
134 do_stop
135 case "$?" in
136 0|1) echo " Stopping $DESC $NAME succeeded" ;;
137 *) echo " Stopping $DESC $NAME failed" ;;
138 esac
139 ;;
140 restart|force-reload)
141 #
142 # If the "reload" option is implemented then remove the
143 # 'force-reload' alias
144 #
145 echo "Restarting $DESC $NAME..."
146 do_stop
147 case "$?" in
148 0|1)
149 do_start
150 case "$?" in
151 0|1) echo " Restarting $DESC $NAME succeeded" ;;
152 *) echo " Restarting $DESC $NAME failed: couldn't start $NAME" ;;
153 esac
154 ;;
155 *)
156 echo " Restarting $DESC $NAME failed: couldn't stop $NAME" ;;
157 esac
158 ;;
159 *)
160 echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
161 exit 3
162 ;;
163esac