#!/bin/sh #---------------------------------------------------------------------------- # /etc/init.d/xinetd - start/stop/status script for xinetd # # Copyright (c) 2001-2005 Ansgar Püster # # Creation: 18.07.2002 jh # Last Update: 07.02.2005 $Id$ # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. #---------------------------------------------------------------------------- # include eislib . /var/install/include/eislib # define constants # all times in seconds start_max_waittime=60 # start: maximum waittime start_sleep_time=2 # start: sleep time between checks stop_max_waittime=20 # stop: maximum waittime for each signal stop_sleep_time=2 # stop: sleep time between checks debug="" # debug Option # "" no debuging # "-d" debug # include shell library . /etc/init.d/inet_shlib #------------------------------------------------------------------------------- # process service #------------------------------------------------------------------------------- process_service () { service=$1 tmp=${service}_tmp.$$ expert=$service.expert b_line='#B Expert' e_line='#E Expert' [ "$MMODE" = 'detailed' ] && mecho "processing service $service" # 1.) remove lines '#B Expert' to '#E Expert' if grep -q -s "$b_line" $service then cp $service $tmp sed "/$b_line/,/$e_line/d" $tmp > $service rm -f $tmp fi # 2.) if .expert file exists create new service file if [ -f $expert ]; then mecho -info "processing $expert" cp $service $tmp # copy up to { sed -n '1,/^ *{ */p' < $service > $tmp # add b_line echo $b_line >> $tmp # add expert file cat $expert >> $tmp # add e_line echo $e_line >> $tmp # copy remaining file sed '1,/^ *{ */d' < $service >> $tmp # copy tmp to service cp $tmp $service # remove tmp rm -f $tmp fi } #------------------------------------------------------------------------------- # process expert files #------------------------------------------------------------------------------- process_expert_files () { oldpwd=$PWD cd /etc/xinetd.d for file in * do case $file in *.expert) ;; *) if [ -f $file ]; then process_service $file fi ;; esac done cd $oldpwd } # ------------------------------------------------------------------------------ PATH=/bin:/usr/bin:/sbin:/usr/sbin trap "" SIGHUP trap "" SIGTERM # read config file . /etc/config.d/inet case "$1" in start|forcestart) daemon=xinetd [ "$1" = 'forcestart' ] && START_XINETD='yes' if [ "$START_XINETD" = 'yes' ]; then verify_pidfile $daemon.pid $daemon rc=$? case $rc in 0) mecho -std "$daemon daemon is already running" ;; 1) mecho -info "Starting $daemon daemon" process_expert_files /usr/sbin/xinetd $debug -reuse -stayalive -pidfile /var/run/$daemon.pid check_start $daemon.pid $daemon $start_max_waittime $start_sleep_time ;; 2) mecho -info "Starting $daemon daemon" process_expert_files /usr/sbin/xinetd $debug -reuse -stayalive -pidfile /var/run/$daemon.pid check_start $daemon.pid $daemon $start_max_waittime $start_sleep_time ;; *) mecho -error "internal error in verify_pidfile (RC=$rc)" ;; esac else mecho -std "START_XINETD was set to 'no', $daemon not started" fi ;; stop) daemon=xinetd verify_pidfile $daemon.pid $daemon rc=$? case $rc in 0) mecho -info "Stopping $daemon daemon" kill_and_wait $daemon.pid $daemon $stop_max_waittime $stop_sleep_time kill TERM INT KILL ;; 1) [ "$MMODE" = 'detailed' ] && mecho -std "$daemon daemon is not running" ;; 2) ;; *) mecho -error "internal error in verify_pidfile (RC=$rc)" ;; esac ;; reload) daemon=xinetd verify_pidfile $daemon.pid $daemon rc=$? case $rc in 0) mecho -info "Reloading configuration of $daemon daemon" process_expert_files kill -HUP `cat /var/run/$daemon.pid 2>/dev/null` 2>/dev/null ;; 1) mecho -std "$daemon daemon is not running" ;; 2) ;; *) mecho -error "internal error in verify_pidfile (RC=$rc)" ;; esac ;; force-reload) $0 reload ;; status) daemon=xinetd verify_pidfile $daemon.pid $daemon rc=$? case $rc in 0) PID=`cat /var/run/$daemon.pid` mecho -std "$daemon daemon is running (pid = $PID)" ;; 1) mecho -std "$daemon daemon is not running" ;; 2) ;; *) mecho -error "internal error in verify_pidfile (RC=$rc)" ;; esac ;; restart) mecho -info "Restarting $daemon" $0 stop > /dev/null 2>&1 sleep 2 $0 start > /dev/null ;; *) mecho -error "Usage: $0 {start|forcestart|stop|reload|force-reload|status|restart}" exit 1 ;; esac exit 0