#! /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 global 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 global 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 { global 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 } } matchstr $1 { start { do_start } restart|reload|force-reload { echo "Error: argument '$1' not supported" > !2 exit 3 } stop|status { # No-op } * { echo "Usage: $0 start|stop" > !2 exit 3 } } (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:PATH) op: Equal rhs: {(/sbin) (Lit_Other ":") (/usr/sbin) (Lit_Other ":") (/bin) (Lit_Other ":") (/usr/bin)} spids: [28] ) ] spids: [28] ) (C {(.)} {(/lib/lsb/init-functions)}) (FuncDef name: do_start body: (BraceGroup children: [ (C {(log_action_begin_msg)} {(DQ ("Asking all remaining processes to terminate"))}) (C {(killall5)} {(-15)}) (C {(log_action_end_msg)} {(0)}) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:alldead) op:Equal rhs:{(DQ )} spids:[75])] spids: [75] ) (ForEach iter_name: seq iter_words: [{(1)} {(2)} {(3)} {(4)} {(5)} {(6)} {(7)} {(8)} {(9)} {(10)}] do_arg_iter: False body: (DoGroup children: [ (If arms: [ (if_arm cond: [(Sentence child:(C {(killall5)} {(-18)}) terminator:)] action: [(C {(Lit_Other ":")})] spids: [-1 140] ) ] else_action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:alldead) op: Equal rhs: {(1)} spids: [149] ) ] spids: [149] ) (ControlFlow token:) ] spids: [146 156] ) (C {(sleep)} {(1)}) ] spids: [107 165] ) spids: [85 105] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(-z)} {(DQ ($ VSub_Name "$alldead"))} {(Lit_Other "]")}) terminator: ) ] action: [ (C {(log_action_begin_msg)} {(DQ ("Killing all remaining processes"))}) (C {(killall5)} {(-9)}) (C {(log_action_end_msg)} {(1)}) ] spids: [-1 182] ) ] else_action: [ (C {(log_action_begin_msg)} {(DQ ("All processes ended within ") ($ VSub_Name "$seq") (" seconds."))} ) (C {(log_action_end_msg)} {(0)}) ] spids: [205 222] ) ] spids: [48] ) spids: [43 47] ) (Case to_match: {(DQ ($ VSub_Number "$1"))} arms: [ (case_arm pat_list:[{(start)}] action:[(C {(do_start)})] spids:[236237243-1]) (case_arm pat_list: [{(restart)} {(reload)} {(force-reload)}] action: [ (SimpleCommand words: [{(echo)} {(DQ ("Error: argument '") ($ VSub_Number "$1") ("' not supported"))}] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[262])] ) (C {(exit)} {(3)}) ] spids: [246 251 271 -1] ) (case_arm pat_list:[{(stop)}{(status)}] spids:[274277284-1]) (case_arm pat_list: [{(Lit_Other "*")}] action: [ (SimpleCommand words: [{(echo)} {(DQ ("Usage: ") ($ VSub_Number "$0") (" start|stop"))}] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[299])] ) (C {(exit)} {(3)}) ] spids: [287 288 308 -1] ) ] spids: [227 233 310] ) ] )