#! /bin/sh ### BEGIN INIT INFO # Provides: killprocs # Required-Start: $local_fs # Required-Stop: # Default-Start: 1 # Default-Stop: # Short-Description: executed by init(8) upon entering runlevel 1 (single). ### END INIT INFO setvar PATH = "/sbin:/usr/sbin:/bin:/usr/bin" source /lib/lsb/init-functions proc do_start { # Kill all processes. log_action_begin_msg "Asking all remaining processes to terminate" killall5 -15 # SIGTERM log_action_end_msg 0 setvar alldead = """" for seq in [1 2 3 4 5 6 7 8 9 10] { # use SIGCONT/signal 18 to check if there are # processes left. No need to check the exit code # value, because either killall5 work and it make # sense to wait for processes to die, or it fail and # there is nothing to wait for. if killall5 -18 { : } else { setvar alldead = '1' break } sleep 1 } if test -z $alldead { log_action_begin_msg "Killing all remaining processes" killall5 -9 # SIGKILL log_action_end_msg 1 } else { log_action_begin_msg "All processes ended within $seq seconds." log_action_end_msg 0 } } match $1 { with start do_start with restart|reload|force-reload echo "Error: argument '$1' not supported" >&2 exit 3 with stop|status # No-op with * echo "Usage: $0 start|stop" >&2 exit 3 }