2006-10-05 04:05:48 +08:00
|
|
|
#!/bin/sh
|
2012-06-14 01:10:41 +08:00
|
|
|
# Copyright (C) 2006-2012 OpenWrt.org
|
2006-10-16 05:03:30 +08:00
|
|
|
|
2012-03-20 22:29:50 +08:00
|
|
|
. $IPKG_INSTROOT/lib/functions.sh
|
|
|
|
. $IPKG_INSTROOT/lib/functions/service.sh
|
2006-10-16 05:03:30 +08:00
|
|
|
|
2009-07-26 20:34:09 +08:00
|
|
|
initscript=$1
|
|
|
|
action=${2:-help}
|
|
|
|
shift 2
|
|
|
|
|
2006-10-05 04:05:48 +08:00
|
|
|
start() {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
stop() {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
reload() {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
restart() {
|
2006-12-20 13:26:39 +08:00
|
|
|
trap '' TERM
|
2008-01-25 18:59:40 +08:00
|
|
|
stop "$@"
|
|
|
|
start "$@"
|
2006-10-05 04:05:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
boot() {
|
2008-01-25 18:59:40 +08:00
|
|
|
start "$@"
|
2006-10-05 04:05:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
shutdown() {
|
2010-12-13 16:01:21 +08:00
|
|
|
stop
|
2006-10-05 04:05:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
disable() {
|
2006-10-16 05:03:30 +08:00
|
|
|
name="$(basename "${initscript}")"
|
2006-10-16 05:22:51 +08:00
|
|
|
rm -f "$IPKG_INSTROOT"/etc/rc.d/S??$name
|
2007-05-10 18:38:53 +08:00
|
|
|
rm -f "$IPKG_INSTROOT"/etc/rc.d/K??$name
|
2006-10-05 04:05:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
enable() {
|
2006-10-16 05:03:30 +08:00
|
|
|
name="$(basename "${initscript}")"
|
2006-10-05 04:05:48 +08:00
|
|
|
disable
|
2011-07-27 17:02:10 +08:00
|
|
|
[ -n "$START" -o -n "$STOP" ] || {
|
|
|
|
echo "/etc/init.d/$name does not have a START or STOP value"
|
|
|
|
return 1
|
|
|
|
}
|
2008-09-23 20:35:34 +08: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-05 04:05:48 +08:00
|
|
|
}
|
|
|
|
|
2006-12-09 01:56:05 +08:00
|
|
|
enabled() {
|
|
|
|
name="$(basename "${initscript}")"
|
|
|
|
[ -x "$IPKG_INSTROOT/etc/rc.d/S${START}${name##S[0-9][0-9]}" ]
|
|
|
|
}
|
|
|
|
|
2006-10-05 04:05:48 +08:00
|
|
|
depends() {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
help() {
|
|
|
|
cat <<EOF
|
2006-10-05 04:09:14 +08:00
|
|
|
Syntax: $initscript [command]
|
2006-10-05 04:05:48 +08: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-16 05:03:30 +08:00
|
|
|
enable Enable service autostart
|
|
|
|
disable Disable service autostart
|
2006-10-05 04:05:48 +08:00
|
|
|
$EXTRA_HELP
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
2012-12-23 02:56:09 +08:00
|
|
|
# for procd
|
|
|
|
start_service() {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2013-09-18 05:45:34 +08:00
|
|
|
stop_service() {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2013-07-12 01:00:54 +08:00
|
|
|
service_triggers() {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2013-09-18 05:45:34 +08:00
|
|
|
service_running() {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2012-06-14 01:10:41 +08:00
|
|
|
${INIT_TRACE:+set -x}
|
|
|
|
|
2006-10-05 04:05:48 +08:00
|
|
|
. "$initscript"
|
|
|
|
|
2012-12-23 02:56:09 +08:00
|
|
|
[ -n "$USE_PROCD" ] && {
|
2013-09-18 05:45:34 +08:00
|
|
|
EXTRA_COMMANDS="${EXTRA_COMMANDS} running"
|
|
|
|
|
2012-12-23 02:56:09 +08:00
|
|
|
. $IPKG_INSTROOT/lib/functions/procd.sh
|
2013-07-12 01:00:21 +08:00
|
|
|
basescript=$(readlink "$initscript")
|
2012-12-23 02:56:09 +08:00
|
|
|
rc_procd() {
|
2013-07-12 01:00:21 +08:00
|
|
|
procd_open_service "$(basename ${basescript:-$initscript})" "$initscript"
|
2012-12-23 02:56:09 +08:00
|
|
|
"$@"
|
|
|
|
procd_close_service
|
|
|
|
}
|
|
|
|
|
|
|
|
start() {
|
|
|
|
rc_procd start_service "$@"
|
2014-06-26 19:43:30 +08:00
|
|
|
if eval "type service_started" 2>/dev/null >/dev/null; then
|
|
|
|
service_started
|
|
|
|
fi
|
2012-12-23 02:56:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
stop() {
|
2013-09-18 05:45:34 +08:00
|
|
|
stop_service "$@"
|
2014-06-02 20:42:44 +08:00
|
|
|
procd_kill "$(basename ${basescript:-$initscript})" "$1"
|
2012-12-23 02:56:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
reload() {
|
2013-09-18 05:45:34 +08:00
|
|
|
if eval "type reload_service" 2>/dev/null >/dev/null; then
|
|
|
|
reload_service "$@"
|
|
|
|
else
|
2014-07-03 14:21:49 +08:00
|
|
|
start
|
2013-09-18 05:45:34 +08:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
running() {
|
|
|
|
service_running "$@"
|
2012-12-23 02:56:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-26 20:34:09 +08: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 11:58:17 +08:00
|
|
|
[ "$action" = "reload" ] && action='eval reload "$@" || restart "$@" && :'
|
2009-07-26 20:34:09 +08:00
|
|
|
$action "$@"
|