UserGuide/InitScript: deluged

File deluged, 3.1 KB (added by egoguerillas, 8 months ago)

Mandriva deluge InitScript

Line 
1#!/bin/sh
2#
3# Startup script for the deluged daemon (HappyWorker)
4#
5# chkconfig: 2345 84 09
6#
7# description: deluged is the Deluge bit torrent daemon. It performs downloads and manages torrents. Connect to the service through the configured port.
8# Script to manage start and stopping the fedora service
9# processname: deluged
10
11### BEGIN INIT INFO
12# Provides: deluged
13# Should-Start:   $network
14# Should-Stop:    $network
15# Required-Start: $local_fs
16# Required-Stop:  $local_fs
17# Default-Start:  2 3 4 5
18# Default-Stop:   0 1 6
19# Short-Description: shadok
20# Description: shadok is the Deluge bit torrent daemon. It performs downloads and manages torrents. Connect to the service through the configured port.
21# Script to manage start and stopping the fedora service
22# processname: deluged
23### END INIT INFO
24
25# Source function library.
26. /etc/rc.d/init.d/functions
27
28# Check that networking is up.
29. /etc/sysconfig/network
30[ "${NETWORKING}" = "no" ] && exit 0
31
32DAEMON='deluged'
33ACCOUNT='deluge'
34HOME='/var/share/deluge'
35# ----------- naming convention -----------
36
37LOG="/var/log/$DAEMON"
38PIDF="/var/run/${DAEMON}.pid"
39LOCK="/var/lock/subsys/$DAEMON"
40# ----------- basic checks -----------
41
42[ ! -d "${HOME}" ] &&  gprintf "Can't find home %s, exit.\n" "${HOME}" && exit 1
43[ -x '/usr/bin/deluged' -a -x '/usr/bin/deluge' ] || exit 0
44#
45
46case "$1" in
47  daemon_start ) # real start
48    [ `id -un` != "$ACCOUNT" ] && [ "$2" != '--test' ] && exit 3
49
50    /usr/bin/deluged -c $HOME/.deluge/  -l $LOG -P $PIDF
51    RETVAL=$?
52    if [ $RETVAL -eq 0 ] ; then
53       /usr/bin/deluge -u web -c $HOME/.deluge/ > $HOME/weluge.log 2>&1  &
54       RETVAL=$?
55       echo $!  >>  $PIDF
56    fi
57    ;;
58  start)
59    gprintf "Starting $DAEMON daemon: "
60    touch  $LOG $PIDF
61    chown $ACCOUNT:`id -g $ACCOUNT` $LOG $PIDF
62    daemon -9 --user=$ACCOUNT --check $DAEMON /bin/ionice -c 3 $0 daemon_start
63    RETVAL=$?
64    echo
65    [ $RETVAL -eq 0 ] && touch $LOCK
66    ;;
67  stop | smooth-stop)
68    gprintf "Shutting down $DAEMON daemon: "
69    [ -r "$PIDF" ] && pid=`cat $PIDF` 2>/dev/null
70    ### __pids_var_run "$DAEMON" "$PIDF"
71    #
72    # kill first, think after
73    #
74    kill -TERM $pid >/dev/null 2>&1
75    #
76    # Saving state takes time: 10 sec
77    #
78    timeout=10
79    for p in $pid ; do
80       kill -s 0 $p 2>/dev/null
81       for ((  ; 0==$?  && 0<$timeout ; timeout=$timeout - 1 )) do
82          echo -n '.'
83          sleep 1
84          kill -s 0 $p 2>/dev/null
85       done
86    done
87    RETVAL=$?
88    ### RC=$((! $RC))
89    if [ "$RETVAL" -eq 0 ] ; then
90        failure "%s shutdown" $DAEMON
91        kill -KILL $pid >/dev/null 2>&1
92        RETVAL=1
93    else
94        success "%s shutdown" $base
95        rm -f $LOCK
96        RETVAL=0
97    fi
98    echo
99    ;;
100  hard-stop)
101    gprintf "Fast stopping $DAEMON daemon: "
102    #
103    # no time to save state
104    #
105    killproc -d 1 $DAEMON
106    RETVAL=$?
107    echo
108    [ $RETVAL -eq 0 ] && rm -f $LOCK
109    ;;
110  status)
111    status $DAEMON
112    RETVAL=$?
113    ;;
114  restart|reload)
115    $0 stop
116    $0 start
117    ;;
118  condrestart)
119    [ -f $LOCK ] && $0 restart || status $DAEMON
120    ;;
121  *)
122    gprintf "Usage: %s {start|stop|smooth-stop|hard-stop|status|restart}\n" "$0"
123    RETVAL=1
124    ;;
125esac
126
127exit $RETVAL