Changeset 94c9e9e68a52a85cada2842d74d51b9407ccf5b2

Show
Ignore:
Timestamp:
04/23/09 10:19:24 (3 years ago)
Author:
Neutron Soutmun <neo.neutron@…>
Children:
aace70f808787e6416462b9148cc6777dd2b0ec3
Parents:
32a2b8614528260422ecc05a560bd58085982248
git-committer:
Neutron Soutmun <neo.neutron@…> (04/23/09 10:19:24)
Message:

Handle start-stop process, fix firewall script

2009-04-23 Neutron Soutmun <neo.neutron@…>

  • example/rahunas.init.in:
    • Adjust the code to handle the start and stop process.
    • Waiting for the process really stop.
  • tools/firewall.sh.in: Prevent the script to start the same rules again for each virtual server.
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • ChangeLog

    r32a2b86 r94c9e9e  
     12009-04-23  Neutron Soutmun <neo.neutron@gmail.com> 
     2 
     3        * example/rahunas.init.in:  
     4          - Adjust the code to handle the start and stop process. 
     5          - Waiting for the process really stop. 
     6        * tools/firewall.sh.in: Prevent the script to start the same rules again for  
     7          each virtual server. 
     8 
    192009-04-21  Neutron Soutmun <neo.neutron@gmail.com> 
    210 
  • example/rahunas.init.in

    rf94bd5c r94c9e9e  
    2222WEBLOGIN_CONFIG=@sysconfdir@/rahunas/weblogin-config-update.sh 
    2323NAME=rahunasd 
    24 DESC="RahuNAS: Rahu Network Access Server" 
     24DESC="RahuNAS - Rahu Network Access Server" 
    2525 
    2626 
     
    3636. $INIT  
    3737 
    38 case "$1" in 
    39   start) 
    40         echo -n "Starting $DESC: " 
     38. /lib/lsb/init-functions 
    4139 
     40PID=@localstatedir@/run/$NAME.pid 
     41 
     42start () { 
    4243  $FIREWALL start 
    4344  $WEBLOGIN_CONFIG 
    4445 
    45         if [ "$RUN_DAEMON" = "yes" ]; then 
    46                 start-stop-daemon --start --quiet --pidfile @localstatedir@/run/$NAME.pid \ 
    47                 --exec $DAEMON 
    48                 echo done 
    49         else 
    50                 echo disabled  
    51         fi 
    52         ;; 
     46  start-stop-daemon --start --quiet \ 
     47    --pidfile $PID --exec $DAEMON < /dev/null 
     48  return $? 
     49} 
     50 
     51stop () { 
     52  start-stop-daemon --stop --quiet \ 
     53    --pidfile $PID --name $NAME < /dev/null 
     54 
     55  # Wait until the rahunasd has really stopped. 
     56  sleep 2 
     57  if test -n "$PID" && kill -0 $PID 2>/dev/null 
     58  then 
     59    log_action_begin_msg " ... Waiting" 
     60    cnt=0 
     61    while kill -0 $PID 2>/dev/null 
     62    do 
     63      cnt=`expr $cnt + 1` 
     64      if [ $cnt -gt 24 ] 
     65      then 
     66        log_action_end_msg 1 
     67        return 1 
     68      fi 
     69      sleep 5 
     70      log_action_cont_msg "" 
     71    done 
     72 
     73    log_action_end_msg 0 
     74  fi 
     75 
     76  $FIREWALL stop 
     77  return 0 
     78} 
     79 
     80case "$1" in 
     81  start) 
     82    log_daemon_msg "Starting $DESC" "$NAME" 
     83   
     84    if [ "$RUN_DAEMON" = "yes" ]; then 
     85      if start ; then 
     86        log_end_msg $? 
     87      else 
     88        log_end_msg $? 
     89      fi 
     90    else 
     91      log_end_msg "disabled, to enable see $INIT" 
     92    fi 
     93    ;; 
    5394  stop) 
    54         echo -n "Stopping $DESC: " 
     95    log_daemon_msg "Stopping $DESC" "$NAME" 
     96   
     97    if stop ; then 
     98      log_end_msg $? 
     99    else 
     100      log_end_msg $? 
     101    fi 
     102    ;; 
     103  restart) 
     104    log_daemon_msg "Restarting $DESC" "$NAME" 
     105    stop 
    55106 
    56         start-stop-daemon --stop --oknodo --quiet --pidfile @localstatedir@/run/$NAME.pid \ 
    57                 --exec $DAEMON 
    58         echo done  
    59         $FIREWALL stop 
    60         ;; 
    61   restart|force-reload) 
    62         echo -n "Restarting $DESC: " 
    63  
    64         start-stop-daemon --stop --oknodo --quiet --pidfile \ 
    65                 @localstatedir@/run/$NAME.pid --exec $DAEMON 
    66         sleep 1 
    67  
    68         $FIREWALL restart 
    69  
    70         start-stop-daemon --start --quiet --pidfile \ 
    71                 @localstatedir@/run/$NAME.pid --exec $DAEMON 
    72         echo "$NAME." 
    73         ;; 
     107    if [ "$RUN_DAEMON" = "yes" ]; then 
     108      if start ; then 
     109        log_end_msg $? 
     110      else 
     111        log_end_msg $? 
     112      fi 
     113    else 
     114      log_end_msg "disabled, to enable see $INIT" 
     115    fi 
     116    ;; 
     117  status) 
     118    status_of_proc -p "$PID" "$DAEMON" "$NAME" && exit 0 || exit $? 
     119    ;; 
    74120  *) 
    75         N=@sysconfdir@/init.d/$NAME 
    76         echo "Usage: $N {start|stop|restart|force-reload}" >&2 
    77         exit 1 
    78         ;; 
     121    N=@sysconfdir@/init.d/$NAME 
     122    echo "Usage: $N {start|stop|restart|status}" >&2 
     123    exit 1 
     124    ;; 
    79125esac 
    80126 
  • tools/firewall.sh.in

    rebf1b31 r94c9e9e  
    1414INIT=@sysconfdir@/default/rahunas 
    1515RUN=@localstatedir@/run/rahunas-firewall 
     16RUNDIR=@localstatedir@/run/rahunas-set 
    1617VSERVER_LIST=@localstatedir@/run/rahunas-vserver 
    1718 
     
    2122. $INIT 
    2223 
    23 test "$RUN_DAEMON" = "yes" || exit 0 
    2424test -f $RAHUNAS_CONFIG || exit 1 
    2525test -f $VSERVER_LIST || touch $VSERVER_LIST 
     26test -d $RUNDIR || mkdir -p $RUNDIR 
    2627 
    2728get_section_name () { 
     
    624625 
    625626start () { 
     627  test "$RUN_DAEMON" = "yes" || return 0 
    626628  test ! -f $RUN || return 0 
    627629 
     
    651653 
    652654start_config() { 
     655  test ! -f $RUNDIR/$SETNAME || return 0 
    653656  add_set 
    654657  new_chains 
    655658  rules 
     659  touch $RUNDIR/$SETNAME 
     660  return 0 
    656661} 
    657662 
     
    659664  do_get_config "" start 
    660665  start_config 
     666  return $? 
    661667} 
    662668 
     
    665671  do_get_config $file start 
    666672  if [ $? -gt 0 ]; then 
    667     return 
     673    return 1 
    668674  fi  
    669675   
    670676  start_config 
     677  return $? 
    671678} 
    672679 
    673680stop_config() { 
     681  test -f $RUNDIR/$SETNAME || return 0 
    674682  cleanup 
    675683  cleanup_set 
     684  rm -f $RUNDIR/$SETNAME 
     685  return 0 
    676686} 
    677687 
     
    679689  do_get_config "" stop 
    680690  stop_config 
     691  return $? 
    681692} 
    682693 
     
    685696  do_get_config $file stop 
    686697  if [ $? -gt 0 ]; then 
    687     return 
     698    return 1 
    688699  fi  
    689700 
    690701  stop_config 
     702  return $? 
    691703} 
    692704