Changes between Version 13 and Version 14 of UserGuide/Service


Ignore:
Timestamp:
04/07/2010 04:32:25 PM (14 years ago)
Author:
Cas
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • UserGuide/Service

    v13 v14  
    11= Deluge Init Scripts = 
    22 
    3 [[PageOutline(2-3,,inline)]] 
     3== What are Init scripts? == 
    44 
    5 Scripts found on this page, were originally posted [http://forum.deluge-torrent.org/viewtopic.php?f=7&t=3185 here]. 
     5Linux uses a system of scripts to determine which services to run on system boot. These scripts exist in /etc/init.d/ (or the symbolic link /etc/rc.d/), and are referred to as 'init scripts.'  
     6Init scripts are essentially just shell scripts with options for performing basic actions on a service. They can be invoked manually, or automatically by the system.  
    67 
    7 == What is an init script? == 
     8[http://www.novell.com/coolsolutions/feature/15380.html More Info] 
    89 
    9 == Init Scripts Based On Distribution == 
    1010 
    11 === Debian/Ubuntu Init Script === 
     11== Available Init Scripts == 
     12[[TitleIndex(UserGuide/InitScript/)]] 
    1213 
    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 set DELUGED_USER to the user you which to run deluge as 
    1614 
    1715{{{ 
    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=""             # !!!CHANGE THIS!!!! 
    23  
    24 # Should we run at startup? 
    25 RUN_AT_STARTUP="YES" 
     16#!comment 
     17Scripts found on this page, were originally posted [http://forum.deluge-torrent.org/viewtopic.php?f=7&t=3185 here]. 
    2618}}} 
    2719 
    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 
    4420 
    45 # Author: Adolfo R. Brandes  
    4621 
    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"             # Consult `man deluged` for more options 
    53 DAEMON2=/usr/bin/deluge-web 
    54 DAEMON2_ARGS=""               # Consult `man deluge-web` for more options 
    55 PIDFILE1=/var/run/$NAME1.pid 
    56 PIDFILE2=/var/run/$NAME2.pid 
    57 UMASK=22                      # Change this to 0 if running deluged as its own user 
    58 PKGNAME=deluge-daemon 
    59 SCRIPTNAME=/etc/init.d/$PKGNAME 
    6022 
    61 # Exit if the package is not installed 
    62 [ -x "$DAEMON1" -a -x "$DAEMON2" ] || exit 0 
    6323 
    64 # Read configuration variable file if it is present 
    65 [ -r /etc/default/$PKGNAME ] && . /etc/default/$PKGNAME 
    66  
    67 # Load the VERBOSE setting and other rcS variables 
    68 [ -f /etc/default/rcS ] && . /etc/default/rcS 
    69  
    70 # Define LSB log_* functions. 
    71 # Depend on lsb-base (>= 3.0-6) to ensure that this file is present. 
    72 . /lib/lsb/init-functions 
    73  
    74 if [ -z "$RUN_AT_STARTUP" -o "$RUN_AT_STARTUP" != "YES" ] 
    75 then 
    76    log_warning_msg "Not starting $PKGNAME, edit /etc/default/$PKGNAME to start it." 
    77    exit 0 
    78 fi 
    79  
    80 if [ -z "$DELUGED_USER" ] 
    81 then 
    82     log_warning_msg "Not starting $PKGNAME, DELUGED_USER not set in /etc/default/$PKGNAME." 
    83     exit 0 
    84 fi 
    85  
    86 # 
    87 # Function that starts the daemon/service 
    88 # 
    89 do_start() 
    90 { 
    91    # Return 
    92    #   0 if daemon has been started 
    93    #   1 if daemon was already running 
    94    #   2 if daemon could not be started 
    95    start-stop-daemon --start --background --quiet --pidfile $PIDFILE1 --exec $DAEMON1 \ 
    96       --chuid $DELUGED_USER --user $DELUGED_USER --umask $UMASK --test > /dev/null 
    97    RETVAL1="$?" 
    98    start-stop-daemon --start --background --quiet --pidfile $PIDFILE2 --exec $DAEMON2 \ 
    99       --chuid $DELUGED_USER --user $DELUGED_USER --umask $UMASK --test > /dev/null 
    100    RETVAL2="$?" 
    101    [ "$RETVAL1" = "0" -a "$RETVAL2" = "0" ] || return 1 
    102  
    103    start-stop-daemon --start --background --quiet --pidfile $PIDFILE1 --make-pidfile --exec $DAEMON1 \ 
    104       --chuid $DELUGED_USER --user $DELUGED_USER --umask $UMASK -- $DAEMON1_ARGS 
    105    RETVAL1="$?" 
    106         sleep 2 
    107    start-stop-daemon --start --background --quiet --pidfile $PIDFILE2 --make-pidfile --exec $DAEMON2 \ 
    108       --chuid $DELUGED_USER --user $DELUGED_USER --umask $UMASK -- $DAEMON2_ARGS 
    109    RETVAL2="$?" 
    110    [ "$RETVAL1" = "0" -a "$RETVAL2" = "0" ] || return 2 
    111 } 
    112  
    113 # 
    114 # Function that stops the daemon/service 
    115 # 
    116 do_stop() 
    117 { 
    118    # Return 
    119    #   0 if daemon has been stopped 
    120    #   1 if daemon was already stopped 
    121    #   2 if daemon could not be stopped 
    122    #   other if a failure occurred 
    123  
    124    start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --user $DELUGED_USER --pidfile $PIDFILE2 
    125    RETVAL2="$?" 
    126    start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --user $DELUGED_USER --pidfile $PIDFILE1 
    127    RETVAL1="$?" 
    128    [ "$RETVAL1" = "2" -o "$RETVAL2" = "2" ] && return 2 
    129  
    130    rm -f $PIDFILE1 $PIDFILE2 
    131  
    132    [ "$RETVAL1" = "0" -a "$RETVAL2" = "0" ] && return 0 || return 1 
    133 } 
    134  
    135 case "$1" in 
    136   start) 
    137    [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME1" 
    138    do_start 
    139    case "$?" in 
    140       0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; 
    141       2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; 
    142    esac 
    143    ;; 
    144   stop) 
    145    [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME1" 
    146    do_stop 
    147    case "$?" in 
    148       0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; 
    149       2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; 
    150    esac 
    151    ;; 
    152   restart|force-reload) 
    153    log_daemon_msg "Restarting $DESC" "$NAME1" 
    154    do_stop 
    155    case "$?" in 
    156      0|1) 
    157       do_start 
    158       case "$?" in 
    159          0) log_end_msg 0 ;; 
    160          1) log_end_msg 1 ;; # Old process is still running 
    161          *) log_end_msg 1 ;; # Failed to start 
    162       esac 
    163       ;; 
    164      *) 
    165         # Failed to stop 
    166       log_end_msg 1 
    167       ;; 
    168    esac 
    169    ;; 
    170   *) 
    171    echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2 
    172    exit 3 
    173    ;; 
    174 esac 
    175  
    176 : 
    177  
    178 }}} 
    179  
    180 Make the script executable by root 
    181  
    182 {{{ 
    183 #!sh 
    184 sudo chmod 755 /etc/init.d/deluge-daemon 
    185 }}} 
    186  
    187 Run this script on start up 
    188  
    189 {{{ 
    190 #!sh 
    191 sudo update-rc.d deluge-daemon defaults 
    192 }}} 
    193  
    194 Start the daemon 
    195  
    196 {{{ 
    197 #!sh 
    198 sudo /etc/init.d/deluge-daemon start 
    199 }}} 
    200  
    201 === Fedora Init Script === 
    202  
    203 {{{ 
    204 #!sh 
    205 #!/bin/bash 
    206 # chkconfig: 345 85 15 
    207 # description: deluged is the Deulge bit torrent daemon. It performs downloads and manages torrents. Connect to the service through the configured port. 
    208 # Script to manage start and stopping the fedora service 
    209 # processname: deluged 
    210  
    211     # Source function library. 
    212     . /etc/init.d/functions 
    213  
    214     RETVAL=0; 
    215  
    216     start() { 
    217         echo "Starting deluged service" 
    218         daemon --user=deluge deluged -c /storage/fileshare/Torrents/.deluge/ -p 58846 -l /storage/fileshare/Torrents/.deluge/deluged.log 
    219         RETVAL1=$? 
    220         echo 
    221         [ $RETVAL1 = 0 ] && touch /var/lock/subsys/deluged 
    222          
    223         echo "Starting deluge webui" 
    224         #daemon --user=deluge deluge -u web -c /storage/fileshare/Torrents/.deluge/ -l /storage/fileshare/Torrents/.deluge/deluge-web.log 
    225         #deluge -u web -c /storage/fileshare/Torrents/.deluge/ -q & 
    226         #cant find force background option in daemon function, so I add my own & 
    227         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 &" 
    228         [ "$?" -eq 0 ] && success $"$base startup" || failure $"$base startup" 
    229  
    230         RETVAL2=$? 
    231         echo 
    232         [ $RETVAL2 = 0 ] && touch /var/lock/subsys/deluge-web 
    233     
    234         RETVAL=1 
    235         if [ $RETVAL1 == 0 ]; then 
    236             if [ $RETVAL2 == 0 ]; then 
    237                 RETVAL=0 
    238             fi 
    239         fi 
    240         return $RETVAL 
    241     } 
    242  
    243     stop() { 
    244         echo "Stopping deluge webui" 
    245         killproc deluge 
    246         RETVAL1=$? 
    247         echo 
    248         [ $RETVAL1 = 0 ] && rm -f /var/lock/subsys/deluge-web 
    249  
    250         echo "Stopping deluged service" 
    251         killproc deluged 
    252         RETVAL2=$? 
    253         echo 
    254         [ $RETVAL2 = 0 ] && rm -f /var/lock/subsys/deluged 
    255     } 
    256  
    257     restart() { 
    258         stop 
    259         start 
    260     } 
    261  
    262 case $1 in 
    263     start) 
    264         start 
    265     ;; 
    266     stop) 
    267         stop 
    268     ;; 
    269     restart) 
    270         restart 
    271     ;; 
    272     status) 
    273         status deluged 
    274         status deluge 
    275         RETVAL=$? 
    276     ;; 
    277     *) 
    278     echo $"Usage: $0 {start|stop|restart|status}" 
    279     exit 1 
    280 esac 
    281  
    282     exit $RETVAL 
    283 }}} 
    284  
    285 === Mandriva Init Script === 
    286  
    287 {{{ 
    288 #!sh 
    289 #!/bin/bash 
    290 # 
    291 # Startup script for the deluged daemon 
    292 # 
    293 # chkconfig: 2345 84 09 
    294 # 
    295 # description: deluged is the Deluge bit torrent daemon. It performs downloads and manages torrents. Connect to the service through the configured port. 
    296 # Script to manage start and stopping the fedora service 
    297 # processname: deluged 
    298  
    299 ### BEGIN INIT INFO 
    300 # Provides: deluged 
    301 # Should-Start:   $network 
    302 # Should-Stop:    $network 
    303 # Required-Start: $local_fs 
    304 # Required-Stop:  $local_fs 
    305 # Default-Start:  2 3 4 5 
    306 # Default-Stop:   0 1 6 
    307 # Short-Description: shadok 
    308 # Description: shadok is the Deluge bit torrent daemon. It performs downloads and manages torrents. Connect to the service through the configured port. 
    309 # Script to manage start and stopping the fedora service 
    310 # processname: deluged 
    311 ### END INIT INFO 
    312  
    313 # Source function library. 
    314 . /etc/rc.d/init.d/functions 
    315  
    316 # Check that networking is up. 
    317 . /etc/sysconfig/network 
    318 [ "${NETWORKING}" = "no" ] && exit 0 
    319  
    320 DAEMON='deluged' 
    321 ACCOUNT='deluge' 
    322 HOME='/var/share/deluge' 
    323 # ----------- naming convention ----------- 
    324  
    325 LOG="/var/log/$DAEMON" 
    326 PIDF="/var/run/${DAEMON}.pid" 
    327 LOCK="/var/lock/subsys/$DAEMON" 
    328 # ----------- basic checks ----------- 
    329  
    330 [ ! -d "${HOME}" ] &&  gprintf "Can't find home %s, exit.\n" "${HOME}" && exit 1 
    331 [ -x '/usr/bin/deluged' -a -x '/usr/bin/deluge' ] || exit 0 
    332 # 
    333  
    334 case "$1" in 
    335   daemon_start ) # real start 
    336     [ `id -un` != "$ACCOUNT" ] && [ "$2" != '--test' ] && exit 3 
    337  
    338     /usr/bin/deluged -c $HOME/.deluge/  -l $LOG -P $PIDF 
    339     RETVAL=$? 
    340     if [ $RETVAL -eq 0 ] ; then 
    341        /usr/bin/deluge -u web -c $HOME/.deluge/ > $HOME/weluge.log 2>&1  & 
    342        RETVAL=$? 
    343        echo $!  >>  $PIDF 
    344     fi 
    345     ;; 
    346   start) 
    347     gprintf "Starting $DAEMON daemon: " 
    348     touch  $LOG $PIDF 
    349     chown $ACCOUNT:`id -g $ACCOUNT` $LOG $PIDF 
    350     daemon -9 --user=$ACCOUNT --check $DAEMON /bin/ionice -c 3 $0 daemon_start 
    351     RETVAL=$? 
    352     echo 
    353     [ $RETVAL -eq 0 ] && touch $LOCK 
    354     ;; 
    355   stop | smooth-stop) 
    356     gprintf "Shutting down $DAEMON daemon: " 
    357     [ -r "$PIDF" ] && pid=`cat $PIDF` 2>/dev/null 
    358     # 
    359     # kill first, think later 
    360     # 
    361     kill -TERM $pid >/dev/null 2>&1 
    362     # 
    363     # Saving state takes time: 10 sec 
    364     # 
    365     timeout=10 
    366     for p in $pid ; do 
    367        kill -s 0 $p 2>/dev/null 
    368        for ((  ; 0==$?  && 0<$timeout ; timeout=$timeout - 1 )) do 
    369           echo -n '.' 
    370           sleep 1 
    371           kill -s 0 $p 2>/dev/null 
    372        done 
    373     done 
    374     if [ "$timeout" -eq 0 ] ; then 
    375         failure "%s shutdown" $DAEMON 
    376         kill -KILL $pid >/dev/null 2>&1 
    377         RETVAL=1 
    378     else 
    379         success "%s shutdown" $base 
    380         rm -f $LOCK 
    381         RETVAL=0 
    382     fi 
    383     echo 
    384     ;; 
    385   hard-stop) 
    386     gprintf "Fast stopping $DAEMON daemon: " 
    387     # 
    388     # no time to save state 
    389     # 
    390     killproc -d 1 $DAEMON 
    391     RETVAL=$? 
    392     echo 
    393     [ $RETVAL -eq 0 ] && rm -f $LOCK 
    394     ;; 
    395   status) 
    396     status $DAEMON 
    397     RETVAL=$? 
    398     ;; 
    399   restart|reload) 
    400     $0 stop 
    401     $0 start 
    402     ;; 
    403   condrestart) 
    404     [ -f $LOCK ] && $0 restart || status $DAEMON 
    405     ;; 
    406   *) 
    407     gprintf "Usage: %s {start|stop|smooth-stop|hard-stop|status|restart}\n" "$0" 
    408     RETVAL=1 
    409     ;; 
    410 esac 
    411  
    412 exit $RETVAL 
    413  
    414 }}} 
    415  
    416 === !OpenSuse Init Script === 
    417  
    418 ==== Deluged ==== 
    419  
    420 {{{ 
    421 #!sh 
    422 #! /bin/sh 
    423 # Copyright (c) 1995-2000 SuSE GmbH Nuernberg, Germany. 
    424 # 
    425 # Author: José Ferrandis 
    426 # 
    427 # /etc/init.d/deluged 
    428 # 
    429 #   and symbolic its link 
    430 # 
    431 # /usr/sbin/deluged 
    432 # 
    433 ### BEGIN INIT INFO 
    434 # Provides: deluged 
    435 # Required-Start: $local_fs $remote_fs 
    436 # Required-Stop: $local_fs $remote_fs 
    437 # Should-Start: $network 
    438 # Should-Stop: $network 
    439  
    440 # Default-Start: 3 5 
    441 # Default-Stop: 0 1 2 6 
    442 # Short-Description: Daemonized version of deluge. 
    443 # Description:       Starts the deluge daemon. 
    444 ### END INIT INFO 
    445  
    446 DELUGED_BIN=/usr/bin/deluged 
    447  
    448 test -x $DELUGED_BIN || exit 5 
    449  
    450 DELUGED_USER="deluge"        # CHANGE THIS 
    451 test -n "$DELUGED_USER" || exit 6 
    452  
    453 DELUGED_PIDFILE=~/.config/deluge/deluged.pid 
    454  
    455 DELUGED_ARGS="-P DELUGED_PIDFILE" # consult man deluged for more options 
    456  
    457 . /etc/rc.status 
    458  
    459 # Shell functions sourced from /etc/rc.status: 
    460 #      rc_check         check and set local and overall rc status 
    461 #      rc_status        check and set local and overall rc status 
    462 #      rc_status -v     ditto but be verbose in local rc status 
    463 #      rc_status -v -r  ditto and clear the local rc status 
    464 #      rc_failed        set local and overall rc status to failed 
    465 #      rc_reset         clear local rc status (overall remains) 
    466 #      rc_exit          exit appropriate to overall rc status 
    467  
    468 # First reset status of this service 
    469 rc_reset 
    470  
    471 case "$1" in 
    472     start) 
    473          
    474         echo -n "Starting DELUGE daemon" 
    475         ## Start daemon with startproc(8). If this fails 
    476         ## the echo return value is set appropriate. 
    477  
    478         startproc -p $DELUGED_PIDFILE -u $DELUGED_USER $DELUGED_BIN $DELUGED_ARGS 
    479  
    480         # Remember status and be verbose 
    481         rc_status -v 
    482         ;; 
    483     stop) 
    484         echo -n "Shutting down DELUGE daemon" 
    485         ## Stop daemon with killproc(8) and if this fails 
    486         ## set echo the echo return value. 
    487  
    488         killproc -TERM $DELUGED_BIN 
    489  
    490         # Remember status and be verbose 
    491         rc_status -v 
    492         ;; 
    493     try-restart) 
    494         ## Stop the service and if this succeeds (i.e. the  
    495         ## service was running before), start it again. 
    496         $0 status >/dev/null &&  $0 restart 
    497  
    498         # Remember status and be quiet 
    499         rc_status 
    500         ;; 
    501     restart) 
    502         ## Stop the service and regardless of whether it was 
    503         ## running or not, start it again. 
    504         $0 stop 
    505         $0 start 
    506  
    507         # Remember status and be quiet 
    508         rc_status 
    509         ;; 
    510     force-reload|reload) 
    511         ## Signal the daemon to reload its config. Most daemons 
    512         ## do this on signal 1 (SIGHUP). 
    513  
    514         echo -n "Reload service DELUGED" 
    515  
    516         killproc -HUP $DELUGED_BIN 
    517  
    518         rc_status -v 
    519  
    520         ;; 
    521     status) 
    522         echo -n "Checking for service DELUGED " 
    523         ## Check status with checkproc(8), if process is running 
    524         ## checkproc will return with exit status 0. 
    525  
    526         # Status has a slightly different for the status command: 
    527         # 0 - service running 
    528         # 1 - service dead, but /var/run/  pid  file exists 
    529         # 2 - service dead, but /var/lock/ lock file exists 
    530         # 3 - service not running 
    531  
    532         checkproc $DELUGED_BIN 
    533  
    534         rc_status -v 
    535         ;; 
    536     probe) 
    537         ## Optional: Probe for the necessity of a reload, 
    538         ## give out the argument which is required for a reload. 
    539  
    540         ;; 
    541     *) 
    542         echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload|probe}" 
    543         exit 1 
    544         ;; 
    545 esac 
    546 rc_exit 
    547 }}} 
    548  
    549 ==== Web UI ==== 
    550  
    551 {{{ 
    552 #!sh 
    553 #! /bin/sh 
    554 # Copyright (c) 1995-2000 SuSE GmbH Nuernberg, Germany. 
    555 # 
    556 # Author: José Ferrandis 
    557 # 
    558 # /etc/init.d/deluge-webd 
    559 # 
    560 #   and symbolic its link 
    561 # 
    562 # /usr/sbin/deluge-webd 
    563 # 
    564 ### BEGIN INIT INFO 
    565 # Provides: deluge-webd 
    566 # Required-Start: $local_fs $remote_fs 
    567 # Required-Stop: $local_fs $remote_fs 
    568 # Should-Start: $network 
    569 # Should-Stop: $network 
    570  
    571 # Default-Start: 3 5 
    572 # Default-Stop: 0 1 2 6 
    573 # Short-Description: Daemonized version of deluge-web. 
    574 # Description:       Starts the deluge-web daemon. 
    575  
    576 ### END INIT INFO 
    577  
    578 DELUGED_WEB_BIN=/usr/bin/deluge-web 
    579 test -x $DELUGED_WEB_BIN || exit 5 
    580  
    581 DELUGED_WEB_USER="deluge" 
    582  
    583 . /etc/rc.status 
    584  
    585 # Shell functions sourced from /etc/rc.status: 
    586 #      rc_check         check and set local and overall rc status 
    587 #      rc_status        check and set local and overall rc status 
    588 #      rc_status -v     ditto but be verbose in local rc status 
    589 #      rc_status -v -r  ditto and clear the local rc status 
    590 #      rc_failed        set local and overall rc status to failed 
    591 #      rc_reset         clear local rc status (overall remains) 
    592 #      rc_exit          exit appropriate to overall rc status 
    593  
    594 # First reset status of this service 
    595 rc_reset 
    596  
    597 case "$1" in 
    598     start) 
    599          
    600         echo -n "Starting DELUGE-WEB daemon" 
    601         ## Start daemon with startproc(8). If this fails 
    602         ## the echo return value is set appropriate. 
    603  
    604         startproc -f -u $DELUGED_WEB_USER $DELUGED_WEB_BIN 
    605  
    606         # Remember status and be verbose 
    607         rc_status -v 
    608         ;; 
    609     stop) 
    610         echo -n "Shutting down DELUGE-WEB daemon" 
    611         ## Stop daemon with killproc(8) and if this fails 
    612         ## set echo the echo return value. 
    613  
    614         killproc -TERM $DELUGED_WEB_BIN 
    615  
    616         # Remember status and be verbose 
    617         rc_status -v 
    618         ;; 
    619     try-restart) 
    620         ## Stop the service and if this succeeds (i.e. the  
    621         ## service was running before), start it again. 
    622         $0 status >/dev/null &&  $0 restart 
    623  
    624         # Remember status and be quiet 
    625         rc_status 
    626         ;; 
    627     restart) 
    628         ## Stop the service and regardless of whether it was 
    629         ## running or not, start it again. 
    630         $0 stop 
    631         $0 start 
    632  
    633         # Remember status and be quiet 
    634         rc_status 
    635         ;; 
    636     force-reload|reload) 
    637         ## Signal the daemon to reload its config. Most daemons 
    638         ## do this on signal 1 (SIGHUP). 
    639  
    640         echo -n "Reload service DELUGED_WEB" 
    641  
    642         killproc -HUP $DELUGED_WEB_BIN 
    643  
    644         rc_status -v 
    645  
    646         ;; 
    647     status) 
    648         echo -n "Checking for service DELUGED_WEB " 
    649         ## Check status with checkproc(8), if process is running 
    650         ## checkproc will return with exit status 0. 
    651  
    652         # Status has a slightly different for the status command: 
    653         # 0 - service running 
    654         # 1 - service dead, but /var/run/  pid  file exists 
    655         # 2 - service dead, but /var/lock/ lock file exists 
    656         # 3 - service not running 
    657  
    658         checkproc $DELUGED_WEB_BIN 
    659  
    660         rc_status -v 
    661         ;; 
    662     probe) 
    663         ## Optional: Probe for the necessity of a reload, 
    664         ## give out the argument which is required for a reload. 
    665  
    666         ;; 
    667     *) 
    668         echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload|probe}" 
    669         exit 1 
    670         ;; 
    671 esac 
    672 rc_exit 
    673 }}} 
    674  
    675 === FreeBSD Init Script === 
    676  
    677 ==== Deluged ==== 
    678  
    679 {{{ 
    680 #!sh 
    681 #!/bin/sh 
    682 # 
    683 #  deluged RCng startup script 
    684 #  created by: R.S.A. aka .faust  
    685 #            mail: rsa dot aka dot f at gmail dot com 
    686 #  
    687   
    688 # PROVIDE: deluged 
    689 # REQUIRE: NETWORKING SERVERS DAEMON ldconfig resolv 
    690 # BEFORE: LOGIN 
    691 # KEYWORD: shutdown 
    692   
    693 # Add the following line to /etc/rc.conf.local or /etc/rc.conf to enable deluged at startup 
    694 #       deluged_enable="YES" 
    695 # 
    696 # pidfile  (str):            Specify the full path to the PID file 
    697 # log (str):                    Specify the full path to the LOG file 
    698 # delugew_user (str):  Set to user running deluge-web 
    699 # cfg_dir (str):            Specify the full path to directory with deluge config files 
    700 # 
    701 #  Warning! Rights to folders and files must be "rwx" for the user under which the run deluge  
    702   
    703 . /etc/rc.subr 
    704   
    705 name="deluged" 
    706 rcvar=`set_rcvar` 
    707   
    708 load_rc_config $name 
    709 deluged_enable=${deluged_enable:=NO} 
    710  
    711 log="/home/deluge/${name}.log" 
    712 pidfile="/home/deluge/${name}.pid" 
    713 cfg_dir="/home/deluge/config/" 
    714 deluged_user="nobody" 
    715  
    716 required_dirs=${cfg_dir} 
    717  
    718 command_interpreter="/usr/local/bin/python" 
    719 command="/usr/local/bin/${name}" 
    720 start_cmd="${name}_start" 
    721  
    722 deluged_start() 
    723 { 
    724 if [ ! -f "${pidfile}" ]; then 
    725     su -m ${deluged_user} -c "/usr/local/bin/${name} -c ${cfg_dir} -l ${log} -P ${pidfile}" 
    726     echo "Starting ${name}." 
    727 else 
    728     GETPROCESSPID=`/bin/ps -auxw | /usr/bin/awk '/deluged/ && !/awk/ && !/sh/ {print $2}'` 
    729     PIDFROMFILE=`cat ${pidfile}` 
    730     if [ "$GETPROCESSPID" = "$PIDFROMFILE" ]; then 
    731         echo "${name} already running with PID: ${PIDFROMFILE} ?"   
    732         echo "Remove ${pidfile} manually if needed." 
    733     else 
    734         rm -f ${pidfile} 
    735         su -m ${deluged_user} -c "/usr/local/bin/${name} -c ${cfg_dir} -l ${log} -P ${pidfile}" 
    736         echo "Starting ${name}." 
    737     fi 
    738 fi 
    739 } 
    740   
    741   
    742 run_rc_command "$1" 
    743 }}} 
    744  
    745 ==== Web UI ==== 
    746  
    747 {{{ 
    748 #!sh 
    749 #!/bin/sh 
    750 # 
    751 #  deluge-web RCng startup script 
    752 #  created by: R.S.A. aka .faust  
    753 #            mail: rsa dot aka dot f at gmail dot com 
    754 #  
    755   
    756 # PROVIDE: delugew 
    757 # REQUIRE: NETWORKING SERVERS DAEMON ldconfig resolv 
    758 # BEFORE: LOGIN 
    759 # KEYWORD: shutdown 
    760   
    761 # Add the following line to /etc/rc.conf.local or /etc/rc.conf to enable deluge-web at startup 
    762 #       delugew_enable="YES" 
    763 # 
    764 # pidfile  (str):            Specify the full path to the PID file 
    765 # log (str):                    Specify the full path to the LOG file 
    766 # delugew_user (str):  Set to user running deluge-web 
    767 # cfg_dir (str):            Specify the full path to directory with deluge config files 
    768 # 
    769 #  Warning! Rights to folders and files must be "rwx" for the user under which the run deluge  
    770 . /etc/rc.subr 
    771   
    772 name="delugew" 
    773 rcvar=`set_rcvar` 
    774   
    775 load_rc_config $name 
    776 delugew_enable=${delugew_enable:=NO} 
    777  
    778 log="/home/deluge/${name}.log" 
    779 pidfile="/home/deluge/${name}.pid" 
    780 cfg_dir="/home/deluge/config/" 
    781 delugew_user="nobody" 
    782  
    783 required_dirs=${cfg_dir} 
    784  
    785 command_interpreter="/usr/local/bin/python" 
    786 command="/usr/local/bin/deluge-web" 
    787 start_cmd="${name}_start" 
    788 start_postcmd="${name}_poststart" 
    789  
    790 delugew_start() 
    791 { 
    792 if [ ! -f "${pidfile}" ]; then 
    793     su -m ${delugew_user} -c "/usr/local/bin/deluge-web -f -c ${cfg_dir} -l ${log}" 
    794     echo "Starting ${name}." 
    795 else 
    796     GETPROCESSPID=`/bin/ps -auxw | /usr/bin/awk '/deluge-web/ && !/awk/ && !/sh/ {print $2}'` 
    797     PIDFROMFILE=`cat ${pidfile}` 
    798     if [ "$GETPROCESSPID" = "$PIDFROMFILE" ]; then 
    799         echo "${name} already running with PID: ${PIDFROMFILE} ?"   
    800         echo "Remove ${pidfile} manually if needed." 
    801     else 
    802         rm -f ${pidfile} 
    803         su -m ${delugew_user} -c "/usr/local/bin/deluge-web -f -c ${cfg_dir} -l ${log}" 
    804         echo "Starting ${name}." 
    805     fi 
    806 fi 
    807 } 
    808   
    809 delugew_poststart() 
    810 { 
    811 echo `/bin/ps -auxw | /usr/bin/awk '/deluge-web/ && !/awk/ {print $2}'` > $pidfile 
    812 } 
    813   
    814 run_rc_command "$1" 
    815 }}}