public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "William Hubbs" <williamh@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/openrc:master commit in: sh/, etc/
Date: Fri,  8 May 2015 17:11:15 +0000 (UTC)	[thread overview]
Message-ID: <1431103179.abef2fcb2dbcc277bb05f0d9c674d4b47826f17f.williamh@OpenRC> (raw)

commit:     abef2fcb2dbcc277bb05f0d9c674d4b47826f17f
Author:     William Hubbs <w.d.hubbs <AT> gmail <DOT> com>
AuthorDate: Fri May  8 16:29:49 2015 +0000
Commit:     William Hubbs <williamh <AT> gentoo <DOT> org>
CommitDate: Fri May  8 16:39:39 2015 +0000
URL:        https://gitweb.gentoo.org/proj/openrc.git/commit/?id=abef2fcb

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.

 etc/rc.conf.in          |  6 ++++
 sh/Makefile             |  2 +-
 sh/openrc-run.sh.in     | 75 ++++++-------------------------------------------
 sh/start-stop-daemon.sh | 71 ++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 87 insertions(+), 67 deletions(-)

diff --git a/etc/rc.conf.in b/etc/rc.conf.in
index 69a5cf2..b16aaff 100644
--- a/etc/rc.conf.in
+++ b/etc/rc.conf.in
@@ -77,6 +77,12 @@
 #rc_crashed_stop=NO
 #rc_crashed_start=YES
 
+# Set rc_supervisor to use a program to monitor your daemons and restart
+# them when they crash.
+# Leaving this undefined uses start-stop-daemon, which is OpenRC's
+# default.
+#rc_supervisor=""
+
 # Set rc_nocolor to yes if you do not want colors displayed in OpenRC
 # output.
 #rc_nocolor=NO

diff --git a/sh/Makefile b/sh/Makefile
index ee9d74d..3f8881e 100644
--- a/sh/Makefile
+++ b/sh/Makefile
@@ -1,7 +1,7 @@
 DIR=	${LIBEXECDIR}/sh
 SRCS=	init.sh.in functions.sh.in gendepends.sh.in \
 	openrc-run.sh.in rc-functions.sh.in tmpfiles.sh.in ${SRCS-${OS}}
-INC=	rc-mount.sh functions.sh rc-functions.sh
+INC=	rc-mount.sh functions.sh rc-functions.sh start-stop-daemon.sh
 BIN=	gendepends.sh init.sh openrc-run.sh tmpfiles.sh ${BIN-${OS}}
 
 INSTALLAFTER=	_installafter

diff --git a/sh/openrc-run.sh.in b/sh/openrc-run.sh.in
index e279f11..4d286b2 100644
--- a/sh/openrc-run.sh.in
+++ b/sh/openrc-run.sh.in
@@ -125,72 +125,6 @@ _status()
 	fi
 }
 
-# Template start / stop / status functions
-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
-		_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 \
-		${chroot:+--chroot} $chroot \
-		${procname:+--name} $procname \
-		${pidfile:+--pidfile} $pidfile \
-		$_background $start_stop_daemon_args \
-		-- $command_args
-	if eend $? "Failed to start $RC_SVCNAME"; then
-		service_set_value "command" "${command}"
-		[ -n "${chroot}" ] && service_set_value "chroot" "${chroot}"
-		[ -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 startchroot="$(service_get_value "chroot")"
-	local startpidfile="$(service_get_value "pidfile")"
-	local startprocname="$(service_get_value "procname")"
-	command="${startcommand:-$command}"
-	chroot="${startchroot:-$chroot}"
-	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} $chroot$pidfile \
-		${stopsig:+--signal} $stopsig
-	eend $? "Failed to stop $RC_SVCNAME"
-}
-
-status()
-{
-	_status
-}
-
 yesno $RC_DEBUG && set -x
 
 _conf_d=${RC_SERVICE%/*}/../conf.d
@@ -212,6 +146,15 @@ unset _conf_d
 # Load any system overrides
 sourcex -e "@SYSCONFDIR@/rc.conf"
 
+# load a service supervisor
+sourcex "@LIBEXECDIR@/sh/start-stop-daemon.sh"
+if [ -n "$rc_supervisor" ]; then
+	if ! sourcex -e "@LIBEXECDIR@/sh/${rc_supervisor}.sh"; then
+		ewarn "$rc_supervisor is an invalid value for rc_supervisor"
+		ewarn "Using the default."
+	fi
+fi
+
 # Set verbose mode
 if yesno "${rc_verbose:-$RC_VERBOSE}"; then
 	EINFO_VERBOSE=yes

diff --git a/sh/start-stop-daemon.sh b/sh/start-stop-daemon.sh
new file mode 100644
index 0000000..aae6792
--- /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
+}


             reply	other threads:[~2015-05-08 17:11 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-08 17:11 William Hubbs [this message]
  -- strict thread matches above, loose matches on Subject: below --
2017-09-15 18:31 [gentoo-commits] proj/openrc:master commit in: sh/, etc/ William Hubbs
2016-12-17 22:57 William Hubbs
2015-10-06 21:34 William Hubbs
2013-04-25 22:02 William Hubbs
2013-03-12 18:10 William Hubbs
2013-02-19 23:11 William Hubbs
2012-11-12 17:00 William Hubbs
2011-11-17 22:46 William Hubbs
2011-11-17 22:36 William Hubbs

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1431103179.abef2fcb2dbcc277bb05f0d9c674d4b47826f17f.williamh@OpenRC \
    --to=williamh@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox