Alon Bar-Lev has uploaded a new change for review.

Change subject: packaging: engine-service: add options for wrappers
......................................................................

packaging: engine-service: add options for wrappers

In order to be used at other environments, with their own init.d layout,

Add:
  --quiet
  --pidfile
  --foreground

Change-Id: I00d868fc51ec73800cae2eb24002feb933744851
Signed-off-by: Alon Bar-Lev <alo...@redhat.com>
---
M packaging/fedora/engine-service.py.in
1 file changed, 71 insertions(+), 30 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/18/13418/1

diff --git a/packaging/fedora/engine-service.py.in 
b/packaging/fedora/engine-service.py.in
index 163c4e9..61de949 100644
--- a/packaging/fedora/engine-service.py.in
+++ b/packaging/fedora/engine-service.py.in
@@ -32,12 +32,17 @@
 import sys
 import syslog
 import time
+from optparse import OptionParser
 
 from Cheetah.Template import Template
 
 
 # The name of the engine:
 engineName = "engine-service"
+
+# Misc
+beQuiet = False
+foreground = False
 
 # The engine system configuration variables:
 engineDefaultsFile = None
@@ -355,19 +360,20 @@
 
 
 def loadEnginePid():
-    if not os.path.exists(enginePidFile):
+    if enginePidFile is None or not os.path.exists(enginePidFile):
         return None
     with open(enginePidFile, "r") as enginePidFd:
         return int(enginePidFd.read())
 
 
 def saveEnginePid(pid):
-    with open(enginePidFile, "w") as enginePidFd:
-        enginePidFd.write(str(pid) + "\n")
+    if enginePidFile is not None:
+        with open(enginePidFile, "w") as enginePidFd:
+            enginePidFd.write(str(pid) + "\n")
 
 
 def removeEnginePid():
-    if os.path.exists(enginePidFile):
+    if enginePidFile is not None and os.path.exists(enginePidFile):
         os.remove(enginePidFile)
 
 
@@ -383,8 +389,7 @@
 
 
 def startEngine():
-    # Load the configuration and perform checks:
-    loadConfig()
+    # perform checks:
     checkInstallation()
 
     # Get the PID:
@@ -546,15 +551,16 @@
         "org.jboss.as.standalone", "-c", os.path.basename(jbossConfigFile),
     ])
 
-    # Fork a new process:
-    enginePid = os.fork()
+    if not foreground:
+        # Fork a new process:
+        enginePid = os.fork()
 
-    # If this is the parent process then the last thing we have to do is
-    # saving the child process PID to the file:
-    if enginePid != 0:
-        syslog.syslog(syslog.LOG_INFO, "Started engine process %d." % 
enginePid)
-        saveEnginePid(enginePid)
-        return
+        # If this is the parent process then the last thing we have to do is
+        # saving the child process PID to the file:
+        if enginePid != 0:
+            syslog.syslog(syslog.LOG_INFO, "Started engine process %d." % 
enginePid)
+            saveEnginePid(enginePid)
+            return
 
     # Change the resource limits while we are root as we won't be
     # able to change them once we assume the engine identity (the
@@ -607,8 +613,7 @@
 
 
 def stopEngine():
-    # Load the configuration and perform checks:
-    loadConfig()
+    # perform checks:
     checkInstallation()
 
     # Load the PID:
@@ -673,9 +678,6 @@
 
 
 def checkEngine():
-    # Load the configuration:
-    loadConfig()
-
     # First check that the engine PID file exists, if it doesn't
     # then we assume that the engine is not running:
     enginePid = loadEnginePid()
@@ -711,15 +713,18 @@
         moveColumn = "\033[60G"
 
     # Inform that we are doing the job:
-    sys.stdout.write(label + " " + engineName + ":")
-    sys.stdout.flush()
+    if not beQuiet:
+        sys.stdout.write(label + " " + engineName + ":")
+        sys.stdout.flush()
 
     # Do the real action:
     try:
         action()
-        sys.stdout.write(moveColumn + " [  " + colorSuccess + "OK" + 
colorNormal + "  ]\n")
+        if not beQuiet:
+            sys.stdout.write(moveColumn + " [  " + colorSuccess + "OK" + 
colorNormal + "  ]\n")
     except Exception:
-        sys.stdout.write(moveColumn + " [" + colorFailure + "FAILED" + 
colorNormal + "]\n")
+        if not beQuiet:
+            sys.stdout.write(moveColumn + " [" + colorFailure + "FAILED" + 
colorNormal + "]\n")
         raise
 
 
@@ -755,15 +760,51 @@
 
 
 def main():
-    # Check the arguments:
-    args = sys.argv[1:]
+    loadConfig()
+
+    parser = OptionParser(
+        usage="usage: %prog [options] start|stop|restart|status",
+    )
+    parser.add_option(
+        "-q", "--quiet",
+        dest="quiet",
+        action="store_true",
+        default=False,
+        help="Quiet mode",
+    )
+    parser.add_option(
+        "--pidfile",
+        dest="pidfile",
+        default=None,
+        metavar="FILE",
+        help="pid file to use",
+    )
+    parser.add_option(
+        "-f", "--foreground",
+        dest="foreground",
+        action="store_true",
+        default=False,
+        help="Do not go into background",
+    )
+    global options
+    (options, args) = parser.parse_args()
+
+    global enginePidFile
+    global foreground
+    global beQuiet
+
+    if options.pidfile is not None:
+        enginePidFile = options.pidfile
+    foreground = options.foreground
+    if foreground:
+        enginePidFile = None
+    beQuiet = options.quiet
+
     if len(args) != 1:
-        showUsage()
-        sys.exit(1)
-    action = args[0].lower()
+        parser.error("action is missing")
+    action = args[0]
     if not action in ["start", "stop", "restart", "status"]:
-        showUsage()
-        sys.exit(1)
+        parser.error("invalid action '%s'" % action)
 
     # Run the action with syslog open and remember to close it
     # regardless of what happens in the middle:


--
To view, visit http://gerrit.ovirt.org/13418
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I00d868fc51ec73800cae2eb24002feb933744851
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Alon Bar-Lev <alo...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to