Changes between Version 4 and Version 5 of Scripts/runscript


Ignore:
Timestamp:
Feb 16, 2009, 5:10:26 PM (13 years ago)
Author:
Waldorf
Comment:

another try at getting this right

Legend:

Unmodified
Added
Removed
Modified
  • Scripts/runscript

    v4 v5  
    11= runscript =
    22''(for other scripts, see the [wiki:Scripts] page)''
     3[[PageOutline]]
    34== Description ==
    45This is the bootscript for [http://www.gentoo.org/ Gentoo], for use with their {{{init}}} daemon.
     
    1516Try:
    1617{{{
    17 $ adduser --disabled-password transmission
     18$ useradd -m transmission
    1819}}}
     20However, you can set the {{{USERNAME}}} to any user you prefer.
    1921
    20 However, you can set the {{{USERNAME}}} to any user you prefer.
     22Although you can set any setting from the {{{init.d}}} file, Gentoo recommends setting variables in the {{{conf.d}}} file. For this reason, a template configuration file can be found at the bottom.
    2123
    2224For more information, visit the [HeadlessUsage Running Transmission on a headless machine] page
     
    3537}}}
    3638
    37 == Script "transmission-daemon" ==
     39== Scripts ==
     40=== "/etc/init.d/transmission-daemon" ===
    3841{{{
     42#!sh
    3943#!/sbin/runscript
    4044#
     
    8286SCRIPTNAME=/etc/init.d/$NAME
    8387
    84 # Set default values
    85 USERNAME=${USERNAME:-transmission}
    86 
    8788# Exit if the package is not installed
    8889[ -x "$DAEMON" ] || exit 0
    8990
    9091depend() {
    91    need net
     92    need net
    9293}
    9394
     
    9596# Function that starts the daemon/service
    9697#
    97 do_start()
    98 {
     98start() {
     99    ebegin "Starting $DESC" "$NAME..."
     100   
    99101    # Export the configuration/web directory, if set
    100102    if [ -n "$TRANSMISSION_HOME" ]; then
    101           export TRANSMISSION_HOME
     103        export TRANSMISSION_HOME
    102104    fi
    103105    if [ -n "$TRANSMISSION_WEB_HOME" ]; then
    104           export TRANSMISSION_WEB_HOME
     106        export TRANSMISSION_WEB_HOME
    105107    fi
    106108
    107     # Return
    108     #   0 if daemon has been started
    109     #   1 if daemon was already running
    110     #   2 if daemon could not be started
    111     start-stop-daemon --chuid $USERNAME --start --pidfile $PIDFILE --make-pidfile \
    112             --exec $DAEMON --background --test -- -f $TRANSMISSION_ARGS > /dev/null \
    113             || return 1
    114     start-stop-daemon --chuid $USERNAME --start --pidfile $PIDFILE --make-pidfile \
    115             --exec $DAEMON --background -- -f $TRANSMISSION_ARGS \
    116             || return 2
     109    start-stop-daemon --start --chuid ${USERNAME:-transmission} --pidfile $PIDFILE --make-pidfile \
     110        --exec $DAEMON --background -- -f $TRANSMISSION_ARGS
     111   
     112    eend $?
    117113}
    118114
     
    120116# Function that stops the daemon/service
    121117#
    122 do_stop()
    123 {
    124         # Return
    125         #   0 if daemon has been stopped
    126         #   1 if daemon was already stopped
    127         #   2 if daemon could not be stopped
    128         #   other if a failure occurred
    129         start-stop-daemon --stop --quiet --retry=TERM/10/KILL/5 --pidfile $PIDFILE --name $NAME
    130         RETVAL="$?"
    131         [ "$RETVAL" = 2 ] && return 2
     118stop() {
     119    ebegin "Stopping $DESC" "$NAME..."
    132120
    133         # Wait for children to finish too if this is a daemon that forks
    134         # and if the daemon is only ever run from this initscript.
    135         # If the above conditions are not satisfied then add some other code
    136         # that waits for the process to drop all resources that could be
    137         # needed by services started subsequently.  A last resort is to
    138         # sleep for some time.
     121    start-stop-daemon --stop --quiet --user ${USERNAME:-transmission} \
     122        --pidfile $PIDFILE --name $NAME
    139123
    140         start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
    141         [ "$?" = 2 ] && return 2
     124    # Many daemons don't delete their pidfiles when they exit.
     125    rm -f $PIDFILE
    142126
    143         # Many daemons don't delete their pidfiles when they exit.
    144         rm -f $PIDFILE
     127    eend $?
     128}
     129}}}
    145130
    146         return "$RETVAL"
    147 }
     131=== Script "/etc/conf.d/transmission-daemon" ===
     132{{{
     133#!sh
     134# /etc/conf.d/transmission-daemon
     135#
     136
     137#
     138# ----- CONFIGURATION -----
     139#
     140# For the default location Transmission uses, visit:
     141# http://trac.transmissionbt.com/wiki/ConfigFiles
     142# For a guide on how set the preferences, visit:
     143# http://trac.transmissionbt.com/wiki/EditConfigFiles
     144# For the available environement variables, visit:
     145# http://trac.transmissionbt.com/wiki/EnvironmentVariables
     146#
     147# The name of the user that should run Transmission.
     148# It's RECOMENDED to run Transmission in it's own user,
     149# by default, this is set to 'transmission'.
     150# For the sake of security you shouldn't set a password
     151# on this user.
     152#USERNAME=transmission
    148153
    149154
    150 start() {
    151     ebegin "Starting $DESC" "$NAME..."
    152     do_start
    153     case "$?" in
    154             0|1) eend $? "   Starting $DESC $NAME succeeded" ;;
    155             *)   eend $? "   Starting $DESC $NAME failed" ;;
    156     esac
    157     ;;
    158 }
    159 
    160 stop() {
    161     ebegin "Stopping $DESC $NAME..."
    162     do_stop
    163     case "$?" in
    164             0|1) eend $? "   Stopping $DESC $NAME succeeded" ;;
    165             *)   eend $? "   Stopping $DESC $NAME failed" ;;
    166     esac
    167     ;;
    168 }
    169 
    170 restart() {
    171   ebegin "Restarting $DESC $NAME..."
    172   do_stop
    173   case "$?" in
    174     0|1)
    175           do_start
    176           case "$?" in
    177               0|1) eend $? "   Restarting $DESC $NAME succeeded" ;;
    178               *)   eend $? "   Restarting $DESC $NAME failed: couldn't start $NAME" ;;
    179           esac
    180           ;;
    181     *)
    182           eend $? "   Restarting $DESC $NAME failed: couldn't stop $NAME" ;;
    183   esac
    184   ;;
    185 }
     155# ----- *ADVANCED* CONFIGURATION -----
     156# Only change these options if you know what you are doing!
     157#
     158# The folder where Transmission stores the config & web files.
     159# ONLY change this you have it at a non-default location!
     160#TRANSMISSION_HOME="/var/config/transmission-daemon"
     161#TRANSMISSION_WEB_HOME="/usr/share/transmission/web"
     162#
     163# The arguments passed on to transmission-daemon.
     164# ONLY change this you need to, otherwise use the
     165# settings file as per above.
     166#TRANSMISSION_ARGS=""
    186167}}}