Răsfoiți Sursa

Bug 668862 - init scripts return wrong error code

The dirsrv init script returns an exit code of 0 when no instances
are configured or if an invalid instance name is specified.  This
patch makes the dirsrv init script return the proper exit codes.
The exit codes for the status action are different than the codes
for non-status actions per the Fedora SysV init script packaging
guidelines.

In addition, the dirsrv and dirsrv-snmp inistscripts need to return
a non-0 exit code when networking is disabled or if the binaries
do not exist.  This patch handles those cases as well.
Nathan Kinder 15 ani în urmă
părinte
comite
5a41728cf7
2 a modificat fișierele cu 48 adăugiri și 8 ștergeri
  1. 31 5
      wrappers/initscript.in
  2. 17 3
      wrappers/ldap-agent-initscript.in

+ 31 - 5
wrappers/initscript.in

@@ -23,7 +23,13 @@ fi
 if [ "${NETWORKING}" = "no" ]
 if [ "${NETWORKING}" = "no" ]
 then
 then
     echo "Networking is down"
     echo "Networking is down"
-    exit 0
+    if [ "$1" = "status" ]; then
+        # exit code 4 means unknown status for status action
+        exit 4
+    else
+        # exit code 1 means unspecified error for non-status actions
+        exit 1
+    fi
 fi
 fi
 
 
 # figure out which echo we're using
 # figure out which echo we're using
@@ -87,8 +93,16 @@ piddir="@localstatedir@/run/@package_name@"
 # Instance basedir
 # Instance basedir
 instbase="@instconfigdir@"
 instbase="@instconfigdir@"
 
 
-
-[ -f $exec ] || exit 0
+# Check that ns-slapd exists
+if [ ! -f $exec ] ; then
+    if [ "$1" = "status" ]; then
+        # exit code 4 means unknown status for status action
+        exit 4
+    else
+        # exit code 5 means program is not installed for non-status actions
+        exit 5
+    fi
+fi
 
 
 
 
 umask 077
 umask 077
@@ -107,7 +121,13 @@ done
 
 
 if [ -z "$INSTANCES" ]; then
 if [ -z "$INSTANCES" ]; then
     echo "  *** Error: no $prog instances configured"
     echo "  *** Error: no $prog instances configured"
-    exit 0
+    if [ "$1" = "status" ]; then
+        # exit code 4 means unknown status for status action
+        exit 4
+    else
+        # exit code 6 means program is not configured for non-status actions
+        exit 6
+    fi
 fi
 fi
 
 
 if [ -n "$2" ]; then
 if [ -n "$2" ]; then
@@ -119,7 +139,13 @@ if [ -n "$2" ]; then
    if [ "$2" != "$INSTANCES" ]; then
    if [ "$2" != "$INSTANCES" ]; then
       echo_n "$2 is an invalid @package_name@ instance"
       echo_n "$2 is an invalid @package_name@ instance"
       failure; echo
       failure; echo
-      exit 1
+      if [ "$1" = "status" ]; then
+          # exit code 4 means unknown status for status action
+          exit 4
+      else
+          # exit code 2 means invalid argument for non-status actions
+          exit 2
+      fi
    fi
    fi
 fi
 fi
 
 

+ 17 - 3
wrappers/ldap-agent-initscript.in

@@ -22,7 +22,13 @@ fi
 if [ "${NETWORKING}" = "no" ]
 if [ "${NETWORKING}" = "no" ]
 then
 then
     echo "Networking is down"
     echo "Networking is down"
-    exit 0
+    if [ "$1" = "status" ]; then
+        # exit code 4 means unknown status for status action
+        exit 4
+    else
+        # exit code 1 means unspecified error for non-status actions
+        exit 1
+    fi
 fi
 fi
 
 
 # figure out which echo we're using
 # figure out which echo we're using
@@ -61,8 +67,16 @@ pidfile="@localstatedir@/run/ldap-agent.pid"
 configfile="@sysconfdir@/@package_name@/config/ldap-agent.conf"
 configfile="@sysconfdir@/@package_name@/config/ldap-agent.conf"
 
 
 
 
-
-[ -f $exec ] || exit 0
+# Check if ldap-agent exists
+if [ ! -f $exec ]; then
+    if [ "$1" = "status" ]; then
+        # exit code 4 means unknown status for status action
+        exit 4
+    else
+        # exit code 5 means program is not installed for non-status actions
+        exit 5
+    fi
+fi
 
 
 
 
 umask 077
 umask 077