| 285 | === Mandriva Init Script === |
| 286 | |
| 287 | {{{ |
| 288 | #!/bin/bash |
| 289 | # |
| 290 | # Startup script for the deluged daemon (HappyWorker) |
| 291 | # |
| 292 | # chkconfig: 2345 84 09 |
| 293 | # |
| 294 | # description: deluged is the Deluge bit torrent daemon. It performs downloads and manages torrents. Connect to the service through the configured port. |
| 295 | # Script to manage start and stopping the fedora service |
| 296 | # processname: deluged |
| 297 | |
| 298 | ### BEGIN INIT INFO |
| 299 | # Provides: deluged |
| 300 | # Should-Start: $network |
| 301 | # Should-Stop: $network |
| 302 | # Required-Start: $local_fs |
| 303 | # Required-Stop: $local_fs |
| 304 | # Default-Start: 2 3 4 5 |
| 305 | # Default-Stop: 0 1 6 |
| 306 | # Short-Description: shadok |
| 307 | # Description: shadok is the Deluge bit torrent daemon. It performs downloads and manages torrents. Connect to the service through the configured port. |
| 308 | # Script to manage start and stopping the fedora service |
| 309 | # processname: deluged |
| 310 | ### END INIT INFO |
| 311 | |
| 312 | # Source function library. |
| 313 | . /etc/rc.d/init.d/functions |
| 314 | |
| 315 | # Check that networking is up. |
| 316 | . /etc/sysconfig/network |
| 317 | [ "${NETWORKING}" = "no" ] && exit 0 |
| 318 | |
| 319 | DAEMON='deluged' |
| 320 | ACCOUNT='deluge' |
| 321 | HOME='/var/share/deluge' |
| 322 | # ----------- naming convention ----------- |
| 323 | |
| 324 | LOG="/var/log/$DAEMON" |
| 325 | PIDF="/var/run/${DAEMON}.pid" |
| 326 | LOCK="/var/lock/subsys/$DAEMON" |
| 327 | # ----------- basic checks ----------- |
| 328 | |
| 329 | [ ! -d "${HOME}" ] && gprintf "Can't find home %s, exit.\n" "${HOME}" && exit 1 |
| 330 | [ -x '/usr/bin/deluged' -a -x '/usr/bin/deluge' ] || exit 0 |
| 331 | # |
| 332 | |
| 333 | case "$1" in |
| 334 | daemon_start ) # real start |
| 335 | [ `id -un` != "$ACCOUNT" ] && [ "$2" != '--test' ] && exit 3 |
| 336 | |
| 337 | /usr/bin/deluged -c $HOME/.deluge/ -l $LOG -P $PIDF |
| 338 | RETVAL=$? |
| 339 | if [ $RETVAL -eq 0 ] ; then |
| 340 | /usr/bin/deluge -u web -c $HOME/.deluge/ > $HOME/weluge.log 2>&1 & |
| 341 | RETVAL=$? |
| 342 | echo $! >> $PIDF |
| 343 | fi |
| 344 | ;; |
| 345 | start) |
| 346 | gprintf "Starting $DAEMON daemon: " |
| 347 | touch $LOG $PIDF |
| 348 | chown $ACCOUNT:`id -g $ACCOUNT` $LOG $PIDF |
| 349 | daemon -9 --user=$ACCOUNT --check $DAEMON /bin/ionice -c 3 $0 daemon_start |
| 350 | RETVAL=$? |
| 351 | echo |
| 352 | [ $RETVAL -eq 0 ] && touch $LOCK |
| 353 | ;; |
| 354 | stop | smooth-stop) |
| 355 | gprintf "Shutting down $DAEMON daemon: " |
| 356 | [ -r "$PIDF" ] && pid=`cat $PIDF` 2>/dev/null |
| 357 | # |
| 358 | # kill first, think later |
| 359 | # |
| 360 | kill -TERM $pid >/dev/null 2>&1 |
| 361 | # |
| 362 | # Saving state takes time: 10 sec |
| 363 | # |
| 364 | timeout=10 |
| 365 | for p in $pid ; do |
| 366 | kill -s 0 $p 2>/dev/null |
| 367 | for (( ; 0==$? && 0<$timeout ; timeout=$timeout - 1 )) do |
| 368 | echo -n '.' |
| 369 | sleep 1 |
| 370 | kill -s 0 $p 2>/dev/null |
| 371 | done |
| 372 | done |
| 373 | if [ "$timeout" -eq 0 ] ; then |
| 374 | failure "%s shutdown" $DAEMON |
| 375 | kill -KILL $pid >/dev/null 2>&1 |
| 376 | RETVAL=1 |
| 377 | else |
| 378 | success "%s shutdown" $base |
| 379 | rm -f $LOCK |
| 380 | RETVAL=0 |
| 381 | fi |
| 382 | echo |
| 383 | ;; |
| 384 | hard-stop) |
| 385 | gprintf "Fast stopping $DAEMON daemon: " |
| 386 | # |
| 387 | # no time to save state |
| 388 | # |
| 389 | killproc -d 1 $DAEMON |
| 390 | RETVAL=$? |
| 391 | echo |
| 392 | [ $RETVAL -eq 0 ] && rm -f $LOCK |
| 393 | ;; |
| 394 | status) |
| 395 | status $DAEMON |
| 396 | RETVAL=$? |
| 397 | ;; |
| 398 | restart|reload) |
| 399 | $0 stop |
| 400 | $0 start |
| 401 | ;; |
| 402 | condrestart) |
| 403 | [ -f $LOCK ] && $0 restart || status $DAEMON |
| 404 | ;; |
| 405 | *) |
| 406 | gprintf "Usage: %s {start|stop|smooth-stop|hard-stop|status|restart}\n" "$0" |
| 407 | RETVAL=1 |
| 408 | ;; |
| 409 | esac |
| 410 | |
| 411 | exit $RETVAL |
| 412 | |
| 413 | }}} |