From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <gentoo-commits+bounces-917546-garchives=archives.gentoo.org@lists.gentoo.org>
Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by finch.gentoo.org (Postfix) with ESMTPS id 865AC139085
	for <garchives@archives.gentoo.org>; Sat, 17 Dec 2016 22:57:12 +0000 (UTC)
Received: from pigeon.gentoo.org (localhost [127.0.0.1])
	by pigeon.gentoo.org (Postfix) with SMTP id D8FAEE0C21;
	Sat, 17 Dec 2016 22:57:06 +0000 (UTC)
Received: from smtp.gentoo.org (dev.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by pigeon.gentoo.org (Postfix) with ESMTPS id B9E23E0C21
	for <gentoo-commits@lists.gentoo.org>; Sat, 17 Dec 2016 22:57:06 +0000 (UTC)
Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by smtp.gentoo.org (Postfix) with ESMTPS id D0F18340AC7
	for <gentoo-commits@lists.gentoo.org>; Sat, 17 Dec 2016 22:57:05 +0000 (UTC)
Received: from localhost.localdomain (localhost [127.0.0.1])
	by oystercatcher.gentoo.org (Postfix) with ESMTP id 6DB9424DE
	for <gentoo-commits@lists.gentoo.org>; Sat, 17 Dec 2016 22:57:04 +0000 (UTC)
From: "William Hubbs" <williamh@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Content-Transfer-Encoding: 8bit
Content-type: text/plain; charset=UTF-8
Reply-To: gentoo-dev@lists.gentoo.org, "William Hubbs" <williamh@gentoo.org>
Message-ID: <1482015011.f27d60add9ee1ef8a90ea0034edf6f4e4e6d0ed8.williamh@OpenRC>
Subject: [gentoo-commits] proj/openrc:master commit in: sh/
X-VCS-Repository: proj/openrc
X-VCS-Files: sh/openrc-run.sh.in
X-VCS-Directories: sh/
X-VCS-Committer: williamh
X-VCS-Committer-Name: William Hubbs
X-VCS-Revision: f27d60add9ee1ef8a90ea0034edf6f4e4e6d0ed8
X-VCS-Branch: master
Date: Sat, 17 Dec 2016 22:57:04 +0000 (UTC)
Precedence: bulk
List-Post: <mailto:gentoo-commits@lists.gentoo.org>
List-Help: <mailto:gentoo-commits+help@lists.gentoo.org>
List-Unsubscribe: <mailto:gentoo-commits+unsubscribe@lists.gentoo.org>
List-Subscribe: <mailto:gentoo-commits+subscribe@lists.gentoo.org>
List-Id: Gentoo Linux mail <gentoo-commits.gentoo.org>
X-BeenThere: gentoo-commits@lists.gentoo.org
X-Archives-Salt: 46e3d2e7-d1b6-4a06-81d9-3ba8a3806636
X-Archives-Hash: 9329553530082795763afe2ca8f129d7

commit:     f27d60add9ee1ef8a90ea0034edf6f4e4e6d0ed8
Author:     Robin H. Johnson <robbat2 <AT> gentoo <DOT> org>
AuthorDate: Thu Dec 15 22:43:34 2016 +0000
Commit:     William Hubbs <williamh <AT> gentoo <DOT> org>
CommitDate: Sat Dec 17 22:50:11 2016 +0000
URL:        https://gitweb.gentoo.org/proj/openrc.git/commit/?id=f27d60ad

sh/openrc-run.sh: expose default start/stop/status

Supervisor setups break easily when start/stop/status functions are not
default.

Applications that write multiple PIDs to a pidfile (eg HAProxy as
described in bug 601540), can also benefit from being able to call the
default start/stop/status with modified environment variables.

Expose the default start/stop/status functions as
default_start/stop/status, and use them for the defaults
start/stop/status.

Trivial usage example:
```
  stop()
  {
    t=$(mktemp)
    for pid in $(cat $pidfile) ; do
      echo $pid >$t
      pidfile=$t default_stop
    done
    rm -f $t
  }
```

X-Gentoo-Bug: 601540
X-Gentoo-Bug-URL: https://bugs.gentoo.org/601540
Signed-off-by: Robin H. Johnson <robbat2 <AT> gentoo.org>

 sh/openrc-run.sh.in | 27 +++++++++++++++++++++++----
 1 file changed, 23 insertions(+), 4 deletions(-)

diff --git a/sh/openrc-run.sh.in b/sh/openrc-run.sh.in
index 4cbfb16..f5ffe17 100644
--- a/sh/openrc-run.sh.in
+++ b/sh/openrc-run.sh.in
@@ -146,10 +146,9 @@ _status()
 	fi
 }
 
-# Template start / stop / status functions
 # These functions select the appropriate function to call from the
 # supervisor modules
-start()
+default_start()
 {
 	local func=ssd_start
 	case "$supervisor" in
@@ -163,7 +162,7 @@ start()
 	$func
 }
 
-stop()
+default_stop()
 {
 	local func=ssd_stop
 	case "$supervisor" in
@@ -177,7 +176,7 @@ stop()
 	$func
 }
 
-status()
+default_status()
 {
 	local func=ssd_status
 	case "$supervisor" in
@@ -191,6 +190,26 @@ status()
 	$func
 }
 
+# Template start / stop / status functions
+# package init scripts may override these, but the bodies are as minimal as
+# possible, so that the init scripts can creatively wrap default_*
+# functions.
+start()
+{
+	default_start
+}
+
+stop()
+{
+	default_stop
+}
+
+status()
+{
+	default_status
+}
+
+# Start debug output
 yesno $RC_DEBUG && set -x
 
 # Load configuration settings. First the global ones, then any