* Moved update-rc to /usr/sbin * init-functions now exports container variable * init.d scripts should now act appropriately in containers * Removed localnet init script - should be performed by iftools init * Added REPO to Makefile
154 lines
2.8 KiB
Plaintext
154 lines
2.8 KiB
Plaintext
# /lib/lsb/init-functions - shell functions and variables for init scripts
|
|
|
|
#
|
|
# This sets some environment variables that init scripts can use
|
|
# to determine if we're running in a container
|
|
#
|
|
# Most likely just checking for the presence of $container would
|
|
# be enough
|
|
#
|
|
|
|
chkcontainer=$(sed 's/\x0/\n/g' < /proc/1/environ|grep -ia '^container\|^LXC')
|
|
[ -n "$chkcontainer" ] && export $chkcontainer
|
|
|
|
COL52="\\033[52G"
|
|
|
|
# killproc() [-p pidfile] pathname [signal]
|
|
# send either the specified [signal] or SIGTERM to a process
|
|
|
|
killproc() {
|
|
local pidfile pathname pids
|
|
local signal="-TERM"
|
|
|
|
while true; do
|
|
case "$1" in
|
|
-p)
|
|
pidfile="$2"
|
|
shift 2
|
|
;;
|
|
*)
|
|
pathname="$1"
|
|
signal="$2"
|
|
break
|
|
;;
|
|
esac
|
|
done
|
|
|
|
[ -r "$pidfile" ] && pids=$(pidofproc -p "$pidfile" "$pathname")
|
|
[ -z "$pids" ] && pids=$(pidofproc "$pathname")
|
|
[ -z "$pids" ] && [ -n "$signal" ] && return 1
|
|
[ -z "$pids" ] && return 0
|
|
|
|
for pid in $pids; do
|
|
kill -0 "$pid" 2>/dev/null || continue
|
|
kill "$signal" "$pid" 2>/dev/null || continue
|
|
|
|
for i in {1..10}; do
|
|
sleep 0.1
|
|
|
|
kill -0 "$pid" 2>/dev/null || break
|
|
done
|
|
|
|
if [ -z "$signal" ]; then
|
|
kill -0 "$pid" 2>/dev/null || return 0
|
|
kill -KILL "$pid"
|
|
fi
|
|
done
|
|
|
|
return $?
|
|
}
|
|
|
|
log_init_msg() {
|
|
[ -z "$1" ] && return 1
|
|
|
|
echo -n "$1"
|
|
}
|
|
|
|
log_failure_msg() {
|
|
echo "$COL52[ FAIL ]"
|
|
|
|
return
|
|
}
|
|
|
|
log_success_msg() {
|
|
echo "$COL52[ OK ]"
|
|
|
|
return
|
|
}
|
|
|
|
log_warning_msg() {
|
|
echo "$COL52[ WARN ]"
|
|
|
|
return
|
|
}
|
|
|
|
# pidofproc() [-p pidfile] pathname
|
|
# return one or more PIDs for the specified pathname
|
|
|
|
pidofproc() {
|
|
local pidfile pathname pids pidlist
|
|
|
|
while true; do
|
|
case "$1" in
|
|
-p)
|
|
pidfile="$2"
|
|
shift 2
|
|
;;
|
|
*)
|
|
pathname="$1"
|
|
break
|
|
;;
|
|
esac
|
|
done
|
|
|
|
[ -r "$pidfile" ] && pids=$(head -1 $pidfile) || pids=$(pidof $pathname)
|
|
|
|
for pid in $pids; do
|
|
kill -0 "$pid" 2>/dev/null && pidlist="$pidlist $pid "
|
|
done
|
|
|
|
[ -z "$pidlist" ] && return 1 || echo $pidlist && return 0
|
|
}
|
|
|
|
# start_daemon() [-f] [-n nicelevel] [-p pidfile] pathname [args...]
|
|
# start a daemon
|
|
|
|
start_daemon() {
|
|
local force pidfile pathname args
|
|
local nicelevel=0
|
|
|
|
while true; do
|
|
case "$1" in
|
|
-f)
|
|
force=1
|
|
;;
|
|
-n)
|
|
nicelevel="$2"
|
|
shift 2
|
|
;;
|
|
-p)
|
|
pidfile="$2"
|
|
shift 2
|
|
;;
|
|
*)
|
|
pathname="$1"
|
|
shift 1
|
|
args="$@"
|
|
break
|
|
;;
|
|
esac
|
|
done
|
|
|
|
if [ -n "$pidfile" ]; then
|
|
pidofproc -p "$pidfile" "$pathname" >/dev/null && return 0
|
|
|
|
[ -f "$pidfile" ] && rm "$pidfile"
|
|
else
|
|
pidofproc "$pathname" >/dev/null && return 0
|
|
fi
|
|
|
|
[ -n "$args" ] && nice -n "$nicelevel" "$pathname" "$args" || \
|
|
nice -n "$nicelevel" "$pathname"
|
|
}
|
|
|