Linux Standard Base[1] states that for init scripts:

* status command for a stopped service should have a return code of 3
* starting an already started service or stopping an already stopped
service should be considered as successful

The trivial patch below makes openrc comply with LSB.  I am not aware of
any service depending on the changed behaviour.

Use case:  One can use Gentoo init scripts with cluster management
software - such as sys-cluster/pacemaker - instead of writing a resource
agent or trying to work around their limitations for each managed
service.

[1]
http://refspecs.freestandards.org/LSB_3.1.0/LSB-Core-generic/LSB-Core-generic/iniscrptact.html


Signed-off-by: Eray Aslan <[email protected]>
---
 sh/runscript.sh.in |    2 +-
 src/rc/runscript.c |   12 ++++++++----
 2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/sh/runscript.sh.in b/sh/runscript.sh.in
index 3d7252a..ea40573 100644
--- a/sh/runscript.sh.in
+++ b/sh/runscript.sh.in
@@ -89,7 +89,7 @@ _status()
                return 0
        else
                einfo "status: stopped"
-               return 1
+               return 3
        fi
 }
 
diff --git a/src/rc/runscript.c b/src/rc/runscript.c
index f3f0517..a264535 100644
--- a/src/rc/runscript.c
+++ b/src/rc/runscript.c
@@ -596,8 +596,10 @@ svc_start_check(void)
        fcntl(exclusive_fd, F_SETFD,
            fcntl(exclusive_fd, F_GETFD, 0) | FD_CLOEXEC);
 
-       if (state & RC_SERVICE_STARTED)
-               ewarnx("WARNING: %s has already been started", applet);
+       if (state & RC_SERVICE_STARTED) {
+               einfo("%s has already been started", applet);
+               exit(EXIT_SUCCESS);
+       }
        else if (state & RC_SERVICE_INACTIVE && !in_background)
                ewarnx("WARNING: %s has already started, but is inactive",
                    applet);
@@ -845,8 +847,10 @@ svc_stop_check(RC_SERVICE *state)
        fcntl(exclusive_fd, F_SETFD,
            fcntl(exclusive_fd, F_GETFD, 0) | FD_CLOEXEC);
 
-       if (*state & RC_SERVICE_STOPPED)
-               ewarnx("WARNING: %s is already stopped", applet);
+       if (*state & RC_SERVICE_STOPPED) {
+               einfo("%s is already stopped", applet);
+               exit(EXIT_SUCCESS);
+       }
 
        rc_service_mark(service, RC_SERVICE_STOPPING);
        hook_out = RC_HOOK_SERVICE_STOP_OUT;
-- 
1.7.3.4

Attachment: pgpUIPqeqKJny.pgp
Description: PGP signature

Reply via email to