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