Transmission start-up script for slackware.

I installed transmission on a headless server so I need it to start on boot. The included start-up script was dependent on start-stop-daemon that is mission on Slackware. The examples on the transmission forums were ok but would resulted in transmission running as root and I want it to run as a non-privileged user. So I modified an example script to read like this:

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
#Slackware startup deamon script

# Name of Service
NAME="Transmission Daemon"

# Command to run
CMD="/usr/bin/transmission-daemon"

# Option to run with deamon
# -a means from where to accept incoming connections, comma separated
# you may want to add your local network if you have multiple clients
OPTIONS="-a 127.0.0.1"

# Process name of daemon, for killing it.
PROCESSNAME="/usr/bin/transmission-daemon"

# The name of the user that should run Transmission.
# It's RECOMENDED to run Transmission in it's own user,
# by default, this is set to 'transmission'.
# For the sake of security you shouldn't set a password
# on this user
USERNAME="transmission"

func_stop() {
        if [ "$(ps aux | grep $PROCESSNAME | grep -v grep)" ]; then
                echo -n "Stopping $NAME ... "
                killall $PROCESSNAME
                sleep 2
        fi

        if [ ! "$(ps aux | grep $PROCESSNAME | grep -v grep)" ]; then
                echo "Done!"
        else
                echo "Error!"
        fi
}

func_start() {
        echo -n "Starting $NAME ... "
        su - $USERNAME -c "$CMD $OPTIONS"
        sleep 2

        if [ "$(ps aux | grep $PROCESSNAME | grep -v grep)" ]; then
                echo "Done!"
        else
                echo "Error!"
        fi
}


case $1 in
        "start")
                func_start
                ;;

        "stop")
                func_stop
                ;;

        "restart")
                func_stop
                sleep 2
                func_start
                ;;
        *)
                echo "Usage; start|stop|restart"
                ;;
esac

After you test this script (make sure it starts as the user you want it to) be sure to add stop calls in /etc/rc.d/rc.6 , rc.K and start calls in rc.M (if you have a look at how rc.ntpd is called for example you’ll know how to add this one). Take care, breaking those scripts could leave you with a non functional system.