| 1 | = Deluge Init Scripts = |
| 2 | |
| 3 | [[PageOutline(2-3,,inline)]] |
| 4 | |
| 5 | Scripts found on this page, were originally posted [http://forum.deluge-torrent.org/viewtopic.php?f=7&t=3185 here]. |
| 6 | |
| 7 | == What is an init script? == |
| 8 | |
| 9 | == Init Scripts Based On Distribution == |
| 10 | |
| 11 | === Debian/Ubuntu Init Script === |
| 12 | |
| 13 | All of this is copied from http://apocryph.org/2008/11/30/setting_deluge_headless_ubuntu_seedbox_windows_client/ Go there for more detailed information. |
| 14 | |
| 15 | Put this in /etc/default/deluge-daemon and replace <username> with your username |
| 16 | |
| 17 | {{{ |
| 18 | #!sh |
| 19 | # Configuration for /etc/init.d/deluge-daemon |
| 20 | |
| 21 | # The init.d script will only run if this variable non-empty. |
| 22 | DELUGED_USER="<username>" # !!!CHANGE THIS!!!! |
| 23 | |
| 24 | # Should we run at startup? |
| 25 | RUN_AT_STARTUP="YES" |
| 26 | }}} |
| 27 | |
| 28 | This should be placed in /etc/init.d/deluge-daemon |
| 29 | {{{ |
| 30 | #!sh |
| 31 | #!/bin/sh |
| 32 | ### BEGIN INIT INFO |
| 33 | # Provides: deluge-daemon |
| 34 | # Required-Start: $local_fs $remote_fs |
| 35 | # Required-Stop: $local_fs $remote_fs |
| 36 | # Should-Start: $network |
| 37 | # Should-Stop: $network |
| 38 | # Default-Start: 2 3 4 5 |
| 39 | # Default-Stop: 0 1 6 |
| 40 | # Short-Description: Daemonized version of deluge and webui. |
| 41 | # Description: Starts the deluge daemon with the user specified in |
| 42 | # /etc/default/deluge-daemon. |
| 43 | ### END INIT INFO |
| 44 | |
| 45 | # Author: Adolfo R. Brandes |
| 46 | |
| 47 | PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin |
| 48 | DESC="Deluge Daemon" |
| 49 | NAME1="deluged" |
| 50 | NAME2="deluge" |
| 51 | DAEMON1=/usr/bin/deluged |
| 52 | DAEMON1_ARGS="-d" |
| 53 | DAEMON2=/usr/bin/deluge |
| 54 | DAEMON2_ARGS="-u web" |
| 55 | PIDFILE1=/var/run/$NAME1.pid |
| 56 | PIDFILE2=/var/run/$NAME2.pid |
| 57 | PKGNAME=deluge-daemon |
| 58 | SCRIPTNAME=/etc/init.d/$PKGNAME |
| 59 | |
| 60 | # Exit if the package is not installed |
| 61 | [ -x "$DAEMON1" -a -x "$DAEMON2" ] || exit 0 |
| 62 | |
| 63 | # Read configuration variable file if it is present |
| 64 | [ -r /etc/default/$PKGNAME ] && . /etc/default/$PKGNAME |
| 65 | |
| 66 | # Load the VERBOSE setting and other rcS variables |
| 67 | [ -f /etc/default/rcS ] && . /etc/default/rcS |
| 68 | |
| 69 | # Define LSB log_* functions. |
| 70 | # Depend on lsb-base (>= 3.0-6) to ensure that this file is present. |
| 71 | . /lib/lsb/init-functions |
| 72 | |
| 73 | if [ -z "$RUN_AT_STARTUP" -o "$RUN_AT_STARTUP" != "YES" ] |
| 74 | then |
| 75 | log_warning_msg "Not starting $PKGNAME, edit /etc/default/$PKGNAME to start it." |
| 76 | exit 0 |
| 77 | fi |
| 78 | |
| 79 | if [ -z "$DELUGED_USER" ] |
| 80 | then |
| 81 | log_warning_msg "Not starting $PKGNAME, DELUGED_USER not set in /etc/default/$PKGNAME." |
| 82 | exit 0 |
| 83 | fi |
| 84 | |
| 85 | # |
| 86 | # Function that starts the daemon/service |
| 87 | # |
| 88 | do_start() |
| 89 | { |
| 90 | # Return |
| 91 | # 0 if daemon has been started |
| 92 | # 1 if daemon was already running |
| 93 | # 2 if daemon could not be started |
| 94 | start-stop-daemon --start --background --quiet --pidfile $PIDFILE1 --exec $DAEMON1 \ |
| 95 | --chuid $DELUGED_USER --user $DELUGED_USER --test > /dev/null |
| 96 | RETVAL1="$?" |
| 97 | start-stop-daemon --start --background --quiet --pidfile $PIDFILE2 --exec $DAEMON2 \ |
| 98 | --chuid $DELUGED_USER --user $DELUGED_USER --test > /dev/null |
| 99 | RETVAL2="$?" |
| 100 | [ "$RETVAL1" = "0" -a "$RETVAL2" = "0" ] || return 1 |
| 101 | |
| 102 | start-stop-daemon --start --background --quiet --pidfile $PIDFILE1 --make-pidfile --exec $DAEMON1 \ |
| 103 | --chuid $DELUGED_USER --user $DELUGED_USER -- $DAEMON1_ARGS |
| 104 | RETVAL1="$?" |
| 105 | sleep 2 |
| 106 | start-stop-daemon --start --background --quiet --pidfile $PIDFILE2 --make-pidfile --exec $DAEMON2 \ |
| 107 | --chuid $DELUGED_USER --user $DELUGED_USER -- $DAEMON2_ARGS |
| 108 | RETVAL2="$?" |
| 109 | [ "$RETVAL1" = "0" -a "$RETVAL2" = "0" ] || return 2 |
| 110 | } |
| 111 | |
| 112 | # |
| 113 | # Function that stops the daemon/service |
| 114 | # |
| 115 | do_stop() |
| 116 | { |
| 117 | # Return |
| 118 | # 0 if daemon has been stopped |
| 119 | # 1 if daemon was already stopped |
| 120 | # 2 if daemon could not be stopped |
| 121 | # other if a failure occurred |
| 122 | |
| 123 | start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --user $DELUGED_USER --pidfile $PIDFILE2 |
| 124 | RETVAL2="$?" |
| 125 | start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --user $DELUGED_USER --pidfile $PIDFILE1 |
| 126 | RETVAL1="$?" |
| 127 | [ "$RETVAL1" = "2" -o "$RETVAL2" = "2" ] && return 2 |
| 128 | |
| 129 | rm -f $PIDFILE1 $PIDFILE2 |
| 130 | |
| 131 | [ "$RETVAL1" = "0" -a "$RETVAL2" = "0" ] && return 0 || return 1 |
| 132 | } |
| 133 | |
| 134 | case "$1" in |
| 135 | start) |
| 136 | [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME1" |
| 137 | do_start |
| 138 | case "$?" in |
| 139 | 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; |
| 140 | 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; |
| 141 | esac |
| 142 | ;; |
| 143 | stop) |
| 144 | [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME1" |
| 145 | do_stop |
| 146 | case "$?" in |
| 147 | 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; |
| 148 | 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; |
| 149 | esac |
| 150 | ;; |
| 151 | restart|force-reload) |
| 152 | log_daemon_msg "Restarting $DESC" "$NAME1" |
| 153 | do_stop |
| 154 | case "$?" in |
| 155 | 0|1) |
| 156 | do_start |
| 157 | case "$?" in |
| 158 | 0) log_end_msg 0 ;; |
| 159 | 1) log_end_msg 1 ;; # Old process is still running |
| 160 | *) log_end_msg 1 ;; # Failed to start |
| 161 | esac |
| 162 | ;; |
| 163 | *) |
| 164 | # Failed to stop |
| 165 | log_end_msg 1 |
| 166 | ;; |
| 167 | esac |
| 168 | ;; |
| 169 | *) |
| 170 | echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2 |
| 171 | exit 3 |
| 172 | ;; |
| 173 | esac |
| 174 | |
| 175 | : |
| 176 | |
| 177 | }}} |
| 178 | |
| 179 | Make the script executable by root |
| 180 | |
| 181 | {{{ |
| 182 | #!sh |
| 183 | sudo chmod 755 /etc/init.d/deluge-daemon |
| 184 | }}} |
| 185 | |
| 186 | Run this script on start up |
| 187 | |
| 188 | {{{ |
| 189 | #!sh |
| 190 | sudo update-rc.d deluge-daemon defaults |
| 191 | }}} |
| 192 | |
| 193 | Start the daemon |
| 194 | |
| 195 | {{{ |
| 196 | #!sh |
| 197 | sudo /etc/init.d/deluge-daemon start |
| 198 | }}} |
| 199 | |
| 200 | === Fedora Init Script === |
| 201 | |
| 202 | {{{ |
| 203 | #!sh |
| 204 | #!/bin/bash |
| 205 | # chkconfig: 345 85 15 |
| 206 | # description: deluged is the Deulge bit torrent daemon. It performs downloads and manages torrents. Connect to the service through the configured port. |
| 207 | # Script to manage start and stopping the fedora service |
| 208 | # processname: deluged |
| 209 | |
| 210 | # Source function library. |
| 211 | . /etc/init.d/functions |
| 212 | |
| 213 | RETVAL=0; |
| 214 | |
| 215 | start() { |
| 216 | echo "Starting deluged service" |
| 217 | daemon --user=deluge deluged -c /storage/fileshare/Torrents/.deluge/ -p 58846 -l /storage/fileshare/Torrents/.deluge/deluged.log |
| 218 | RETVAL1=$? |
| 219 | echo |
| 220 | [ $RETVAL1 = 0 ] && touch /var/lock/subsys/deluged |
| 221 | |
| 222 | echo "Starting deluge webui" |
| 223 | #daemon --user=deluge deluge -u web -c /storage/fileshare/Torrents/.deluge/ -l /storage/fileshare/Torrents/.deluge/deluge-web.log |
| 224 | #deluge -u web -c /storage/fileshare/Torrents/.deluge/ -q & |
| 225 | #cant find force background option in daemon function, so I add my own & |
| 226 | runuser -s /bin/bash - deluge -c "ulimit -S -c ${DAEMON_COREFILE_LIMIT:-0} >/dev/null 2>&1 ; deluge -u web -c /storage/fileshare/Torrents/.deluge/ -l /storage/fileshare/Torrents/.deluge/deluge-web.log &" |
| 227 | [ "$?" -eq 0 ] && success $"$base startup" || failure $"$base startup" |
| 228 | |
| 229 | RETVAL2=$? |
| 230 | echo |
| 231 | [ $RETVAL2 = 0 ] && touch /var/lock/subsys/deluge-web |
| 232 | |
| 233 | RETVAL=1 |
| 234 | if [ $RETVAL1 == 0 ]; then |
| 235 | if [ $RETVAL2 == 0 ]; then |
| 236 | RETVAL=0 |
| 237 | fi |
| 238 | fi |
| 239 | return $RETVAL |
| 240 | } |
| 241 | |
| 242 | stop() { |
| 243 | echo "Stopping deluge webui" |
| 244 | killproc deluge |
| 245 | RETVAL1=$? |
| 246 | echo |
| 247 | [ $RETVAL1 = 0 ] && rm -f /var/lock/subsys/deluge-web |
| 248 | |
| 249 | echo "Stopping deluged service" |
| 250 | killproc deluged |
| 251 | RETVAL2=$? |
| 252 | echo |
| 253 | [ $RETVAL2 = 0 ] && rm -f /var/lock/subsys/deluged |
| 254 | } |
| 255 | |
| 256 | restart() { |
| 257 | stop |
| 258 | start |
| 259 | } |
| 260 | |
| 261 | case $1 in |
| 262 | start) |
| 263 | start |
| 264 | ;; |
| 265 | stop) |
| 266 | stop |
| 267 | ;; |
| 268 | restart) |
| 269 | restart |
| 270 | ;; |
| 271 | status) |
| 272 | status deluged |
| 273 | status deluge |
| 274 | RETVAL=$? |
| 275 | ;; |
| 276 | *) |
| 277 | echo $"Usage: $0 {start|stop|restart|status}" |
| 278 | exit 1 |
| 279 | esac |
| 280 | |
| 281 | exit $RETVAL |
| 282 | }}} |
| 283 | |
| 284 | === Gentoo Init Script === |