package/base-files: enhance & cleanup service wrappers
* add service_check function for checking if a process is alive * add service_signal for sending arbitrary signals to a process * change service_stop to send a TERM signal first, wait for the process to die and send a KILL signal if it doen't * have service_kill print a warning on STDERR stating it has been deprecated git-svn-id: svn://svn.openwrt.org/openwrt/trunk@28865 3c298f89-4303-0410-b956-a3cf2f4a3e73master
parent
b86726c283
commit
ff9120ca00
|
@ -10,7 +10,7 @@ include $(TOPDIR)/rules.mk
|
||||||
include $(INCLUDE_DIR)/kernel.mk
|
include $(INCLUDE_DIR)/kernel.mk
|
||||||
|
|
||||||
PKG_NAME:=base-files
|
PKG_NAME:=base-files
|
||||||
PKG_RELEASE:=90
|
PKG_RELEASE:=91
|
||||||
|
|
||||||
PKG_FILE_DEPENDS:=$(PLATFORM_DIR)/ $(GENERIC_PLATFORM_DIR)/base-files/
|
PKG_FILE_DEPENDS:=$(PLATFORM_DIR)/ $(GENERIC_PLATFORM_DIR)/base-files/
|
||||||
PKG_BUILD_DEPENDS:=opkg/host
|
PKG_BUILD_DEPENDS:=opkg/host
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# Copyright (C) 2006 OpenWrt.org
|
# Copyright (C) 2006-2011 OpenWrt.org
|
||||||
# Copyright (C) 2006 Fokus Fraunhofer <carsten.tittel@fokus.fraunhofer.de>
|
# Copyright (C) 2006 Fokus Fraunhofer <carsten.tittel@fokus.fraunhofer.de>
|
||||||
|
|
||||||
|
|
||||||
|
@ -281,17 +281,19 @@ uci_apply_defaults() {
|
||||||
# Usage: service ACTION EXEC ARGS...
|
# Usage: service ACTION EXEC ARGS...
|
||||||
#
|
#
|
||||||
# Action:
|
# Action:
|
||||||
# -S,--start start EXEC, passing it ARGS as its arguments
|
# -C check if EXEC is alive
|
||||||
# -K,--stop stop EXEC (send it a $SERVICE_SIG_STOP signal)
|
# -S start EXEC, passing it ARGS as its arguments
|
||||||
# -R,--reload reload EXEC (send it a $SERVICE_SIG_RELOAD signal)
|
# -K kill EXEC, sending it a TERM signal if not specified otherwise
|
||||||
#
|
#
|
||||||
# Environment variables used:
|
# Environment variables exposed:
|
||||||
# SERVICE_DAEMONIZE run EXEC in background
|
# SERVICE_DAEMONIZE run EXEC in background
|
||||||
# SERVICE_WRITE_PID create a pid file and use it
|
# SERVICE_WRITE_PID create a pid file and use it
|
||||||
# SERVICE_USE_PID assume EXEC creates its own pid file and use it
|
# SERVICE_USE_PID assume EXEC creates its own pid file and use it
|
||||||
# SERVICE_PID_FILE pid file to use (default to /var/run/EXEC.pid)
|
# SERVICE_PID_FILE pid file to use (default to /var/run/EXEC.pid)
|
||||||
# SERVICE_SIG_RELOAD signal used for reloading
|
# SERVICE_SIG signal to send when using -K
|
||||||
# SERVICE_SIG_STOP signal used for stopping
|
# SERVICE_SIG_RELOAD default signal used for reloading
|
||||||
|
# SERVICE_SIG_STOP default signal used for stopping
|
||||||
|
# SERVICE_STOP_TIME time to wait for a process to stop gracefully before killing it
|
||||||
# SERVICE_UID user EXEC should be run as
|
# SERVICE_UID user EXEC should be run as
|
||||||
# SERVICE_GID group EXEC should be run as
|
# SERVICE_GID group EXEC should be run as
|
||||||
#
|
#
|
||||||
|
@ -302,25 +304,20 @@ uci_apply_defaults() {
|
||||||
SERVICE_QUIET=1
|
SERVICE_QUIET=1
|
||||||
SERVICE_SIG_RELOAD="HUP"
|
SERVICE_SIG_RELOAD="HUP"
|
||||||
SERVICE_SIG_STOP="TERM"
|
SERVICE_SIG_STOP="TERM"
|
||||||
|
SERVICE_STOP_TIME=5
|
||||||
|
|
||||||
service() {
|
service() {
|
||||||
local ssd
|
local ssd
|
||||||
local ssd_pid_file
|
|
||||||
local ssd_sig
|
|
||||||
local ssd_start
|
|
||||||
ssd="${SERVICE_DEBUG:+echo }start-stop-daemon${SERVICE_QUIET:+ -q}"
|
ssd="${SERVICE_DEBUG:+echo }start-stop-daemon${SERVICE_QUIET:+ -q}"
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-S|--start|start)
|
-C)
|
||||||
ssd="$ssd -S"
|
ssd="$ssd -K -t"
|
||||||
ssd_start=1
|
|
||||||
;;
|
;;
|
||||||
-K|--stop|stop)
|
-S)
|
||||||
ssd="$ssd -K"
|
ssd="$ssd -S${SERVICE_DAEMONIZE:+ -b}${SERVICE_WRITE_PID:+ -m}"
|
||||||
ssd_sig="$SERVICE_SIG_STOP"
|
|
||||||
;;
|
;;
|
||||||
-R|--reload|reload)
|
-K)
|
||||||
ssd="$ssd -K"
|
ssd="$ssd -K${SERVICE_SIG:+ -s $SERVICE_SIG}"
|
||||||
ssd_sig="$SERVICE_SIG_RELOAD"
|
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "ssd: unknow action '$1'" 1>&2
|
echo "ssd: unknow action '$1'" 1>&2
|
||||||
|
@ -336,28 +333,45 @@ service() {
|
||||||
ssd="$ssd -p ${SERVICE_PID_FILE:-/var/run/${1##*/}.pid}"
|
ssd="$ssd -p ${SERVICE_PID_FILE:-/var/run/${1##*/}.pid}"
|
||||||
fi
|
fi
|
||||||
ssd="$ssd${SERVICE_UID:+ -c $SERVICE_UID${SERVICE_GID:+:$SERVICE_GID}}"
|
ssd="$ssd${SERVICE_UID:+ -c $SERVICE_UID${SERVICE_GID:+:$SERVICE_GID}}"
|
||||||
if [ -n "$ssd_start" ]; then
|
|
||||||
ssd="$ssd${SERVICE_DAEMONIZE:+ -b}${SERVICE_WRITE_PID:+ -m}"
|
|
||||||
else
|
|
||||||
ssd="$ssd${ssd_sig:+ -s $ssd_sig}"
|
|
||||||
fi
|
|
||||||
shift
|
shift
|
||||||
$ssd${1:+ -- "$@"}
|
$ssd${1:+ -- "$@"}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
service_check() {
|
||||||
|
service -C "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
service_signal() {
|
||||||
|
SERVICE_SIG="${SERVICE_SIG:-USR1}" service -K "$@"
|
||||||
|
}
|
||||||
|
|
||||||
service_start() {
|
service_start() {
|
||||||
service -S "$@"
|
service -S "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
service_stop() {
|
service_stop() {
|
||||||
service -K "$@"
|
local try
|
||||||
|
SERVICE_SIG="${SERVICE_SIG:-$SERVICE_SIG_STOP}" service -K "$@"
|
||||||
|
while [ $((try++)) -lt $SERVICE_STOP_TIME ]; do
|
||||||
|
service -C "$@" || return 0
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
SERVICE_SIG="KILL" service -K "$@"
|
||||||
|
sleep 1
|
||||||
|
! service -C "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
service_reload() {
|
service_reload() {
|
||||||
service -R "$@"
|
SERVICE_SIG="${SERVICE_SIG:-$SERVICE_SIG_RELOAD}" service -K "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
service_kill() {
|
service_kill() {
|
||||||
|
cat 1>&2 << __END_OF_WARNING__
|
||||||
|
#
|
||||||
|
# WARNING: the 'service_kill' function is now deprecated and might be
|
||||||
|
# removed soon. Consider using the other new service_* wrappers instead.
|
||||||
|
#
|
||||||
|
__END_OF_WARNING__
|
||||||
local name="${1}"
|
local name="${1}"
|
||||||
local pid="${2:-$(pidof "$name")}"
|
local pid="${2:-$(pidof "$name")}"
|
||||||
local grace="${3:-5}"
|
local grace="${3:-5}"
|
||||||
|
|
Loading…
Reference in New Issue