2006-10-04 20:05:48 +00:00
|
|
|
#!/bin/sh
|
2011-11-07 22:58:27 +00:00
|
|
|
# Copyright (C) 2006-2011 OpenWrt.org
|
2006-10-15 21:03:30 +00:00
|
|
|
|
|
|
|
. $IPKG_INSTROOT/etc/functions.sh
|
|
|
|
|
2009-07-26 12:34:09 +00:00
|
|
|
initscript=$1
|
|
|
|
action=${2:-help}
|
|
|
|
shift 2
|
|
|
|
|
2011-11-07 22:58:27 +00:00
|
|
|
#
|
|
|
|
# service: simple wrapper around start-stop-daemon
|
|
|
|
#
|
|
|
|
# Usage: service ACTION EXEC ARGS...
|
|
|
|
#
|
|
|
|
# Action:
|
|
|
|
# -S,--start start EXEC, passing it ARGS as its arguments
|
|
|
|
# -K,--stop stop EXEC (send it a $SERVICE_SIG_STOP signal)
|
|
|
|
# -R,--reload reload EXEC (send it a $SERVICE_SIG_RELOAD signal)
|
|
|
|
#
|
|
|
|
# Environment variables used:
|
|
|
|
# SERVICE_DAEMONIZE run EXEC in background
|
|
|
|
# SERVICE_WRITE_PID create a 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_SIG_RELOAD signal used for reloading
|
|
|
|
# SERVICE_SIG_STOP signal used for stopping
|
|
|
|
# SERVICE_UID user EXEC should be run as
|
|
|
|
# SERVICE_GID group EXEC should be run as
|
|
|
|
#
|
|
|
|
# SERVICE_DEBUG don't do anything, but show what would be done
|
|
|
|
# SERVICE_QUIET don't print anything
|
|
|
|
#
|
|
|
|
|
|
|
|
SERVICE_QUIET=1
|
|
|
|
SERVICE_SIG_RELOAD="HUP"
|
|
|
|
SERVICE_SIG_STOP="TERM"
|
|
|
|
|
|
|
|
service() {
|
|
|
|
local ssd
|
|
|
|
local ssd_pid_file
|
|
|
|
local ssd_sig
|
|
|
|
local ssd_start
|
|
|
|
ssd="${SERVICE_DEBUG:+echo }start-stop-daemon${SERVICE_QUIET:+ -q}"
|
|
|
|
case "$1" in
|
|
|
|
-S|--start|start)
|
|
|
|
ssd="$ssd -S"
|
|
|
|
ssd_start=1
|
|
|
|
;;
|
|
|
|
-K|--stop|stop)
|
|
|
|
ssd="$ssd -K"
|
|
|
|
ssd_sig="$SERVICE_SIG_STOP"
|
|
|
|
;;
|
|
|
|
-R|--reload|reload)
|
|
|
|
ssd="$ssd -K"
|
|
|
|
ssd_sig="$SERVICE_SIG_RELOAD"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "ssd: unknow action '$1'" 1>&2
|
|
|
|
return 1
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
if [ -z "$1" ]; then
|
|
|
|
echo "ssd: missing arguments" 1>&2
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
ssd="$ssd -x $1"
|
|
|
|
if [ -n "$SERVICE_PID_FILE$SERVICE_USE_PID$SERVICE_WRITE_PID" ]; then
|
|
|
|
ssd="$ssd -p ${SERVICE_PID_FILE:-/var/run/${1##*/}.pid}"
|
|
|
|
fi
|
|
|
|
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
|
|
|
|
$ssd${1:+ -- "$@"}
|
|
|
|
}
|
|
|
|
|
|
|
|
service_start() {
|
|
|
|
service -S "$@"
|
|
|
|
}
|
|
|
|
|
|
|
|
service_stop() {
|
|
|
|
service -K "$@"
|
|
|
|
}
|
|
|
|
|
|
|
|
service_reload() {
|
|
|
|
service -R "$@"
|
|
|
|
}
|
|
|
|
|
2006-10-04 20:05:48 +00:00
|
|
|
start() {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
stop() {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
reload() {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
restart() {
|
2006-12-20 05:26:39 +00:00
|
|
|
trap '' TERM
|
2008-01-25 10:59:40 +00:00
|
|
|
stop "$@"
|
|
|
|
start "$@"
|
2006-10-04 20:05:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
boot() {
|
2008-01-25 10:59:40 +00:00
|
|
|
start "$@"
|
2006-10-04 20:05:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
shutdown() {
|
2010-12-13 08:01:21 +00:00
|
|
|
stop
|
2006-10-04 20:05:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
disable() {
|
2006-10-15 21:03:30 +00:00
|
|
|
name="$(basename "${initscript}")"
|
2006-10-15 21:22:51 +00:00
|
|
|
rm -f "$IPKG_INSTROOT"/etc/rc.d/S??$name
|
2007-05-10 10:38:53 +00:00
|
|
|
rm -f "$IPKG_INSTROOT"/etc/rc.d/K??$name
|
2006-10-04 20:05:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
enable() {
|
2006-10-15 21:03:30 +00:00
|
|
|
name="$(basename "${initscript}")"
|
2006-10-04 20:05:48 +00:00
|
|
|
disable
|
2011-07-27 09:02:10 +00:00
|
|
|
[ -n "$START" -o -n "$STOP" ] || {
|
|
|
|
echo "/etc/init.d/$name does not have a START or STOP value"
|
|
|
|
return 1
|
|
|
|
}
|
2008-09-23 12:35:34 +00:00
|
|
|
[ "$START" ] && ln -s "../init.d/$name" "$IPKG_INSTROOT/etc/rc.d/S${START}${name##S[0-9][0-9]}"
|
|
|
|
[ "$STOP" ] && ln -s "../init.d/$name" "$IPKG_INSTROOT/etc/rc.d/K${STOP}${name##K[0-9][0-9]}"
|
2006-10-04 20:05:48 +00:00
|
|
|
}
|
|
|
|
|
2006-12-08 17:56:05 +00:00
|
|
|
enabled() {
|
|
|
|
name="$(basename "${initscript}")"
|
|
|
|
[ -x "$IPKG_INSTROOT/etc/rc.d/S${START}${name##S[0-9][0-9]}" ]
|
|
|
|
}
|
|
|
|
|
2006-10-04 20:05:48 +00:00
|
|
|
depends() {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
help() {
|
|
|
|
cat <<EOF
|
2006-10-04 20:09:14 +00:00
|
|
|
Syntax: $initscript [command]
|
2006-10-04 20:05:48 +00:00
|
|
|
|
|
|
|
Available commands:
|
|
|
|
start Start the service
|
|
|
|
stop Stop the service
|
|
|
|
restart Restart the service
|
|
|
|
reload Reload configuration files (or restart if that fails)
|
2006-10-15 21:03:30 +00:00
|
|
|
enable Enable service autostart
|
|
|
|
disable Disable service autostart
|
2006-10-04 20:05:48 +00:00
|
|
|
$EXTRA_HELP
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
. "$initscript"
|
|
|
|
|
2009-07-26 12:34:09 +00:00
|
|
|
ALL_COMMANDS="start stop reload restart boot shutdown enable disable enabled depends ${EXTRA_COMMANDS}"
|
|
|
|
list_contains ALL_COMMANDS "$action" || action=help
|
2010-03-29 03:58:17 +00:00
|
|
|
[ "$action" = "reload" ] && action='eval reload "$@" || restart "$@" && :'
|
2009-07-26 12:34:09 +00:00
|
|
|
$action "$@"
|