2006-10-04 20:05:48 +00:00
|
|
|
#!/bin/sh
|
2012-06-13 17:10:41 +00:00
|
|
|
# Copyright (C) 2006-2012 OpenWrt.org
|
2006-10-15 21:03:30 +00:00
|
|
|
|
2012-03-20 14:29:50 +00:00
|
|
|
. $IPKG_INSTROOT/lib/functions.sh
|
|
|
|
. $IPKG_INSTROOT/lib/functions/service.sh
|
2006-10-15 21:03:30 +00:00
|
|
|
|
2009-07-26 12:34:09 +00:00
|
|
|
initscript=$1
|
|
|
|
action=${2:-help}
|
|
|
|
shift 2
|
|
|
|
|
2006-10-04 20:05:48 +00:00
|
|
|
start() {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
stop() {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
reload() {
|
2017-03-31 06:44:19 +00:00
|
|
|
restart
|
2006-10-04 20:05:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
restart() {
|
2006-12-20 05:26:39 +00:00
|
|
|
trap '' TERM
|
2008-01-25 10:59:40 +00:00
|
|
|
stop "$@"
|
2018-11-22 10:35:08 +00:00
|
|
|
trap - TERM
|
2008-01-25 10:59:40 +00:00
|
|
|
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() {
|
2017-12-22 11:04:46 +00:00
|
|
|
err=1
|
2006-10-15 21:03:30 +00:00
|
|
|
name="$(basename "${initscript}")"
|
2017-12-22 11:04:46 +00:00
|
|
|
[ "$START" ] && \
|
|
|
|
ln -sf "../init.d/$name" "$IPKG_INSTROOT/etc/rc.d/S${START}${name##S[0-9][0-9]}" && \
|
|
|
|
err=0
|
|
|
|
[ "$STOP" ] && \
|
|
|
|
ln -sf "../init.d/$name" "$IPKG_INSTROOT/etc/rc.d/K${STOP}${name##K[0-9][0-9]}" && \
|
|
|
|
err=0
|
|
|
|
return $err
|
2006-10-04 20:05:48 +00:00
|
|
|
}
|
|
|
|
|
2006-12-08 17:56:05 +00:00
|
|
|
enabled() {
|
|
|
|
name="$(basename "${initscript}")"
|
2021-06-07 17:25:06 +00:00
|
|
|
name="${name##[SK][0-9][0-9]}"
|
|
|
|
{
|
|
|
|
[ -z "${START:-}" ] || [ -L "$IPKG_INSTROOT/etc/rc.d/S${START}$name" ]
|
|
|
|
} && {
|
|
|
|
[ -z "${STOP:-}" ] || [ -L "$IPKG_INSTROOT/etc/rc.d/K${STOP}$name" ]
|
|
|
|
}
|
2006-12-08 17:56:05 +00:00
|
|
|
}
|
|
|
|
|
2006-10-04 20:05:48 +00:00
|
|
|
depends() {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2020-11-16 16:30:43 +00:00
|
|
|
ALL_HELP=""
|
|
|
|
ALL_COMMANDS="boot shutdown depends"
|
2020-07-24 06:44:03 +00:00
|
|
|
extra_command() {
|
|
|
|
local cmd="$1"
|
|
|
|
local help="$2"
|
|
|
|
|
|
|
|
local extra="$(printf "%-16s%s" "${cmd}" "${help}")"
|
2020-11-16 16:30:43 +00:00
|
|
|
ALL_HELP="${ALL_HELP}\t${extra}\n"
|
|
|
|
ALL_COMMANDS="${ALL_COMMANDS} ${cmd}"
|
2020-07-24 06:44:03 +00:00
|
|
|
}
|
|
|
|
|
2006-10-04 20:05:48 +00:00
|
|
|
help() {
|
|
|
|
cat <<EOF
|
2006-10-04 20:09:14 +00:00
|
|
|
Syntax: $initscript [command]
|
2006-10-04 20:05:48 +00:00
|
|
|
|
|
|
|
Available commands:
|
|
|
|
EOF
|
2020-11-16 16:30:43 +00:00
|
|
|
echo -e "$ALL_HELP"
|
2006-10-04 20:05:48 +00:00
|
|
|
}
|
|
|
|
|
2012-12-22 18:56:09 +00:00
|
|
|
# for procd
|
|
|
|
start_service() {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2013-09-17 21:45:34 +00:00
|
|
|
stop_service() {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2013-07-11 17:00:54 +00:00
|
|
|
service_triggers() {
|
|
|
|
return 0
|
2017-10-25 16:05:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
service_data() {
|
|
|
|
return 0
|
2013-07-11 17:00:54 +00:00
|
|
|
}
|
|
|
|
|
2013-09-17 21:45:34 +00:00
|
|
|
service_running() {
|
2019-07-23 10:06:29 +00:00
|
|
|
local service="${1:-$(basename $initscript)}"
|
|
|
|
local instance="${2:-*}"
|
|
|
|
procd_running "$service" "$instance" "$@"
|
2013-09-17 21:45:34 +00:00
|
|
|
}
|
|
|
|
|
2012-06-13 17:10:41 +00:00
|
|
|
${INIT_TRACE:+set -x}
|
|
|
|
|
2020-07-24 06:44:03 +00:00
|
|
|
extra_command "start" "Start the service"
|
|
|
|
extra_command "stop" "Stop the service"
|
|
|
|
extra_command "restart" "Restart the service"
|
|
|
|
extra_command "reload" "Reload configuration files (or restart if service does not implement reload)"
|
|
|
|
extra_command "enable" "Enable service autostart"
|
|
|
|
extra_command "disable" "Disable service autostart"
|
|
|
|
extra_command "enabled" "Check if service is started on boot"
|
|
|
|
|
2006-10-04 20:05:48 +00:00
|
|
|
. "$initscript"
|
|
|
|
|
2012-12-22 18:56:09 +00:00
|
|
|
[ -n "$USE_PROCD" ] && {
|
2020-07-24 06:44:03 +00:00
|
|
|
extra_command "running" "Check if service is running"
|
|
|
|
extra_command "status" "Service status"
|
|
|
|
extra_command "trace" "Start with syscall trace"
|
2013-09-17 21:45:34 +00:00
|
|
|
|
2012-12-22 18:56:09 +00:00
|
|
|
. $IPKG_INSTROOT/lib/functions/procd.sh
|
2013-07-11 17:00:21 +00:00
|
|
|
basescript=$(readlink "$initscript")
|
2012-12-22 18:56:09 +00:00
|
|
|
rc_procd() {
|
2016-10-13 10:52:05 +00:00
|
|
|
local method="set"
|
|
|
|
[ -n "$2" ] && method="add"
|
2013-07-11 17:00:21 +00:00
|
|
|
procd_open_service "$(basename ${basescript:-$initscript})" "$initscript"
|
2012-12-22 18:56:09 +00:00
|
|
|
"$@"
|
2016-10-13 10:52:05 +00:00
|
|
|
procd_close_service "$method"
|
2012-12-22 18:56:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
start() {
|
|
|
|
rc_procd start_service "$@"
|
2014-06-26 11:43:30 +00:00
|
|
|
if eval "type service_started" 2>/dev/null >/dev/null; then
|
|
|
|
service_started
|
|
|
|
fi
|
2012-12-22 18:56:09 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 10:58:17 +00:00
|
|
|
trace() {
|
|
|
|
TRACE_SYSCALLS=1
|
|
|
|
start "$@"
|
|
|
|
}
|
|
|
|
|
2012-12-22 18:56:09 +00:00
|
|
|
stop() {
|
2017-12-14 21:55:08 +00:00
|
|
|
procd_lock
|
2013-09-17 21:45:34 +00:00
|
|
|
stop_service "$@"
|
2014-06-02 12:42:44 +00:00
|
|
|
procd_kill "$(basename ${basescript:-$initscript})" "$1"
|
2019-01-30 13:58:47 +00:00
|
|
|
if eval "type service_stopped" 2>/dev/null >/dev/null; then
|
|
|
|
service_stopped
|
|
|
|
fi
|
2012-12-22 18:56:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
reload() {
|
2013-09-17 21:45:34 +00:00
|
|
|
if eval "type reload_service" 2>/dev/null >/dev/null; then
|
2017-12-14 21:55:08 +00:00
|
|
|
procd_lock
|
2013-09-17 21:45:34 +00:00
|
|
|
reload_service "$@"
|
|
|
|
else
|
2017-05-19 13:19:20 +00:00
|
|
|
start
|
2013-09-17 21:45:34 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
running() {
|
|
|
|
service_running "$@"
|
2012-12-22 18:56:09 +00:00
|
|
|
}
|
2018-09-12 01:35:09 +00:00
|
|
|
|
|
|
|
status() {
|
|
|
|
if eval "type status_service" 2>/dev/null >/dev/null; then
|
|
|
|
status_service "$@"
|
|
|
|
else
|
|
|
|
_procd_status "$(basename ${basescript:-$initscript})" "$1"
|
|
|
|
fi
|
|
|
|
}
|
2012-12-22 18:56:09 +00:00
|
|
|
}
|
|
|
|
|
2020-11-16 16:30:43 +00:00
|
|
|
ALL_COMMANDS="${ALL_COMMANDS} ${EXTRA_COMMANDS}"
|
|
|
|
ALL_HELP="${ALL_HELP}${EXTRA_HELP}"
|
2009-07-26 12:34:09 +00:00
|
|
|
list_contains ALL_COMMANDS "$action" || action=help
|
|
|
|
$action "$@"
|