summaryrefslogtreecommitdiff
path: root/package/base-files/files
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2010-09-19 14:03:32 +0000
committerJo-Philipp Wich <jow@openwrt.org>2010-09-19 14:03:32 +0000
commit4815de3f265b68bd956984fb128299f00e703acf (patch)
tree502de375e2317ae2081f19f2107cfc55cc349891 /package/base-files/files
parent8e9736675fd4b799cb0154a475bab427e7623678 (diff)
downloadmtk-20170518-4815de3f265b68bd956984fb128299f00e703acf.zip
mtk-20170518-4815de3f265b68bd956984fb128299f00e703acf.tar.gz
mtk-20170518-4815de3f265b68bd956984fb128299f00e703acf.tar.bz2
base-files: introduce service_kill() into functions.sh - a convenience wrapper for killing services by pid or pidfile with a grace period for termination before kill
SVN-Revision: 23087
Diffstat (limited to 'package/base-files/files')
-rwxr-xr-xpackage/base-files/files/etc/functions.sh17
1 files changed, 17 insertions, 0 deletions
diff --git a/package/base-files/files/etc/functions.sh b/package/base-files/files/etc/functions.sh
index d5ffc13..c5df499 100755
--- a/package/base-files/files/etc/functions.sh
+++ b/package/base-files/files/etc/functions.sh
@@ -275,4 +275,21 @@ uci_apply_defaults() {
uci commit
}
+service_kill() {
+ local name="${1}"
+ local pid="${2:-$(pidof "$name")}"
+ local grace="${3:-5}"
+
+ [ -f "$pid" ] && pid="$(head -n1 "$pid" 2>/dev/null)"
+
+ for pid in $pid; do
+ [ -d "/proc/$pid" ] || continue
+ local try=0
+ kill -TERM $pid 2>/dev/null && \
+ while grep -qs "$name" "/proc/$pid/cmdline" && [ $((try++)) -lt $grace ]; do sleep 1; done
+ kill -KILL $pid 2>/dev/null && \
+ while grep -qs "$name" "/proc/$pid/cmdline"; do sleep 1; done
+ done
+}
+
[ -z "$IPKG_INSTROOT" -a -f /lib/config/uci.sh ] && . /lib/config/uci.sh