aboutsummaryrefslogtreecommitdiff
path: root/sh/start-stop-daemon.sh
diff options
context:
space:
mode:
authorWilliam Hubbs <w.d.hubbs@gmail.com>2015-05-08 11:29:49 -0500
committerWilliam Hubbs <w.d.hubbs@gmail.com>2015-05-08 11:39:39 -0500
commitabef2fcb2dbcc277bb05f0d9c674d4b47826f17f (patch)
tree8dff38dd692971f268c9ab0e0c33944b59c06c23 /sh/start-stop-daemon.sh
parent0b435ddd834bd18254c4d3341acdebf0829921f5 (diff)
Make the default start, stop and status functions overridable
This will make it possible to add support for supervision suites such as runit and s6.
Diffstat (limited to 'sh/start-stop-daemon.sh')
-rw-r--r--sh/start-stop-daemon.sh71
1 files changed, 71 insertions, 0 deletions
diff --git a/sh/start-stop-daemon.sh b/sh/start-stop-daemon.sh
new file mode 100644
index 00000000..aae67920
--- /dev/null
+++ b/sh/start-stop-daemon.sh
@@ -0,0 +1,71 @@
+# Default start / stop / status functions
+# Copyright (c) 2007-2009 Roy Marples <roy@marples.name>
+# Released under the 2-clause BSD license.
+
+start()
+{
+ [ -n "$command" ] || return 0
+
+ local _background=
+ ebegin "Starting ${name:-$RC_SVCNAME}"
+ if yesno "${command_background}"; then
+ if [ -z "${pidfile}" ]; then
+ eend 1 "command_background option used but no pidfile specified"
+ return 1
+ fi
+ if [ -n "${command_args_background}" ]; then
+ eend 1 "command_background used with command_args_background"
+ return 1
+ fi
+ _background="--background --make-pidfile"
+ fi
+ if yesno "$start_inactive"; then
+ local _inactive=false
+ service_inactive && _inactive=true
+ mark_service_inactive
+ fi
+ eval start-stop-daemon --start \
+ --exec $command \
+ ${procname:+--name} $procname \
+ ${pidfile:+--pidfile} $pidfile \
+ ${command_user+--user} $command_user \
+ $_background $start_stop_daemon_args \
+ -- $command_args $command_args_background
+ if eend $? "Failed to start $RC_SVCNAME"; then
+ service_set_value "command" "${command}"
+ [ -n "${pidfile}" ] && service_set_value "pidfile" "${pidfile}"
+ [ -n "${procname}" ] && service_set_value "procname" "${procname}"
+ return 0
+ fi
+ if yesno "$start_inactive"; then
+ if ! $_inactive; then
+ mark_service_stopped
+ fi
+ fi
+ return 1
+}
+
+stop()
+{
+ local startcommand="$(service_get_value "command")"
+ local startpidfile="$(service_get_value "pidfile")"
+ local startprocname="$(service_get_value "procname")"
+ command="${startcommand:-$command}"
+ pidfile="${startpidfile:-$pidfile}"
+ procname="${startprocname:-$procname}"
+ [ -n "$command" -o -n "$procname" -o -n "$pidfile" ] || return 0
+ ebegin "Stopping ${name:-$RC_SVCNAME}"
+ start-stop-daemon --stop \
+ ${retry:+--retry} $retry \
+ ${command:+--exec} $command \
+ ${procname:+--name} $procname \
+ ${pidfile:+--pidfile} $pidfile \
+ ${stopsig:+--signal} $stopsig
+
+ eend $? "Failed to stop $RC_SVCNAME"
+}
+
+status()
+{
+ _status
+}