Changes between Initial Version and Version 1 of UserGuide/InitScript/Mandriva


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

--

Legend:

Unmodified
Added
Removed
Modified
  • UserGuide/InitScript/Mandriva

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