2 # Begin $rc_base/init.d/functions - Run Level Control Functions
4 # Based on functions script from LFS-3.1 and earlier.
5 # Rewritten by Gerard Beekmans - gerard@linuxfromscratch.org
7 # With code based on Matthias Benkmann's simpleinit-msb @
8 # http://winterdrache.de/linux/newboot/index.html
10 # Number of seconds between term signal and kill signal when stopping processes
14 export PATH
="/bin:/usr/bin:/sbin:/usr/sbin"
18 COLUMNS
=${COLUMNS##* }
19 # When using remote connections, such as a serial port, stty size returns 0
20 if [ "$COLUMNS" = "0" ]; then COLUMNS
=80; fi
22 # Measurements for positioning result messages
23 COL
=$
(($COLUMNS - 10))
24 WCOL
=$
(($COLUMNS - 30))
26 # Set Cursur Position Commands, used via echo -e
27 SET_COL
="\\033[${COL}G"
28 SET_WCOL
="\\033[${WCOL}G"
31 # Set color commands, used via echo -e
39 echo -e "$CURS_UP$SET_COL"["$SUCCESS"" OK ""$NORMAL"]
44 echo -e "$CURS_UP$SET_COL"["$FAILURE"FAILED
"$NORMAL"]
49 echo -e "$CURS_UP$SET_WCOL$@$SET_COL"["$WARNING" WARN
"$NORMAL"]
52 # $i is inherited by the rc script
57 echo "You should not be reading this error message. It means"
58 echo "that an unforseen error took place in $i,"
59 echo "which exited with a return value of $error_value"
61 echo "If you're able to track this error down to a bug in one"
62 echo "of the files provided by the LFS book, please be so kind"
63 echo "to inform us at lfs-dev@linuxfromscratch.org"
67 echo "Press Enter to continue..."
71 # $i is inherited by the rc script
76 echo "$i is not a valid symlink"
82 echo "$i is not executable, skipping"
91 if [ $error_value = 0 ]
107 echo "Usage: $0 {success|warning|failure}"
118 echo_warning
"Already running"
121 echo_warning
"Not running"
131 # Returns all of the pid #'s for $1 process
142 if [ $pid -ne $$
] && [ $pid -ne $PPID ]
144 pidlist
="$pidlist $pid"
149 # Starts a program if it is currently not running
154 echo "Usage: loadproc {program}"
165 print_status warning running
169 # Stops a process if it is running
174 echo "Usage: killproc {program} [signal]"
183 signal
=${signal##SIG}
189 if [ -n "$pidlist" ]; then
194 kill -$signal $pid 2>/dev
/null
196 while [ $i -lt $KILLDELAY ]; do
197 kill -0 $pid 2>/dev
/null ||
break
202 if [ -n "$fallback" ]; then kill -$fallback $pid 2>/dev
/null
; fi
204 kill -0 $pid 2>/dev
/null
211 if [ -n "$pidlist" ]; then
215 rm -f /var
/run
/$base.pid
221 print_status warning not_running
229 echo "Usage: reloadproc {program} [signal]"
237 signal
=${signal##SIG}
249 kill -$signal $pid || failure
=1
255 print_status warning not_running
263 echo "Usage: statusproc {program}"
272 echo "$base is running with Process ID(s) $pidlist"
274 if [ -s /var
/run
/$base.pid
]
276 echo "$1 is not running but /var/run/$base.pid exists"
279 echo "$1 is not running"
284 # End $rc_base/init.d/functions