package/base-files: enhance service functions
* allow matching process by name (useful for processes changing it) * check if first argument is executable * fix function name used in error messages SVN-Revision: 28991
This commit is contained in:
parent
5ad763075e
commit
b49aed1520
1 changed files with 27 additions and 13 deletions
|
@ -287,12 +287,15 @@ uci_apply_defaults() {
|
||||||
#
|
#
|
||||||
# Environment variables exposed:
|
# 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 for matching
|
||||||
# SERVICE_USE_PID assume EXEC creates its own pid file and use it
|
# SERVICE_MATCH_EXEC use EXEC command-line for matching (default)
|
||||||
# SERVICE_PID_FILE pid file to use (default to /var/run/EXEC.pid)
|
# SERVICE_MATCH_NAME use EXEC process name for matching
|
||||||
|
# SERVICE_USE_PID assume EXEC create its own pid-file and use it for matching
|
||||||
|
# SERVICE_NAME process name to use (default to EXEC file part)
|
||||||
|
# SERVICE_PID_FILE pid file to use (default to /var/run/$SERVICE_NAME.pid)
|
||||||
# SERVICE_SIG signal to send when using -K
|
# SERVICE_SIG signal to send when using -K
|
||||||
# SERVICE_SIG_RELOAD default signal used for reloading
|
# SERVICE_SIG_RELOAD default signal used when reloading
|
||||||
# SERVICE_SIG_STOP default signal used for stopping
|
# SERVICE_SIG_STOP default signal used when stopping
|
||||||
# SERVICE_STOP_TIME time to wait for a process to stop gracefully before killing it
|
# 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
|
||||||
|
@ -305,9 +308,13 @@ SERVICE_QUIET=1
|
||||||
SERVICE_SIG_RELOAD="HUP"
|
SERVICE_SIG_RELOAD="HUP"
|
||||||
SERVICE_SIG_STOP="TERM"
|
SERVICE_SIG_STOP="TERM"
|
||||||
SERVICE_STOP_TIME=5
|
SERVICE_STOP_TIME=5
|
||||||
|
SERVICE_MATCH_EXEC=1
|
||||||
|
|
||||||
service() {
|
service() {
|
||||||
local ssd
|
local ssd
|
||||||
|
local exec
|
||||||
|
local name
|
||||||
|
local 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
|
||||||
-C)
|
-C)
|
||||||
|
@ -315,24 +322,31 @@ service() {
|
||||||
;;
|
;;
|
||||||
-S)
|
-S)
|
||||||
ssd="$ssd -S${SERVICE_DAEMONIZE:+ -b}${SERVICE_WRITE_PID:+ -m}"
|
ssd="$ssd -S${SERVICE_DAEMONIZE:+ -b}${SERVICE_WRITE_PID:+ -m}"
|
||||||
|
start=1
|
||||||
;;
|
;;
|
||||||
-K)
|
-K)
|
||||||
ssd="$ssd -K${SERVICE_SIG:+ -s $SERVICE_SIG}"
|
ssd="$ssd -K${SERVICE_SIG:+ -s $SERVICE_SIG}"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "ssd: unknow action '$1'" 1>&2
|
echo "service: unknown ACTION '$1'" 1>&2
|
||||||
return 1
|
return 1
|
||||||
esac
|
esac
|
||||||
shift
|
shift
|
||||||
if [ -z "$1" ]; then
|
exec="$1"
|
||||||
echo "ssd: missing arguments" 1>&2
|
[ -n "$exec" ] || {
|
||||||
|
echo "service: missing argument" 1>&2
|
||||||
return 1
|
return 1
|
||||||
fi
|
}
|
||||||
ssd="$ssd -x $1"
|
[ -x "$exec" ] || {
|
||||||
if [ -n "$SERVICE_PID_FILE$SERVICE_USE_PID$SERVICE_WRITE_PID" ]; then
|
echo "service: file '$exec' is not executable" 1>&2
|
||||||
ssd="$ssd -p ${SERVICE_PID_FILE:-/var/run/${1##*/}.pid}"
|
return 1
|
||||||
fi
|
}
|
||||||
|
name="${SERVICE_NAME:-${exec##*/}}"
|
||||||
|
[ -z "$SERVICE_USE_PID$SERVICE_WRITE_PID$SERVICE_PID_FILE" ] \
|
||||||
|
|| ssd="$ssd -p ${SERVICE_PID_FILE:-/var/run/$name.pid}"
|
||||||
|
[ -z "$SERVICE_MATCH_NAME" ] || ssd="$ssd -n $name"
|
||||||
ssd="$ssd${SERVICE_UID:+ -c $SERVICE_UID${SERVICE_GID:+:$SERVICE_GID}}"
|
ssd="$ssd${SERVICE_UID:+ -c $SERVICE_UID${SERVICE_GID:+:$SERVICE_GID}}"
|
||||||
|
[ -z "$SERVICE_MATCH_EXEC$start" ] || ssd="$ssd -x $exec"
|
||||||
shift
|
shift
|
||||||
$ssd${1:+ -- "$@"}
|
$ssd${1:+ -- "$@"}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue