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

Change subject: packaging: engine-service: use python daemon instead of own 
implementation
......................................................................

packaging: engine-service: use python daemon instead of own implementation

Change-Id: I6b533fbdbde47d8fdb62964d60aa22e98c1e57c3
Signed-off-by: Alon Bar-Lev <[email protected]>
---
M packaging/fedora/engine-service.py.in
M packaging/fedora/spec/ovirt-engine.spec.in
2 files changed, 41 insertions(+), 35 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/35/13435/1

diff --git a/packaging/fedora/engine-service.py.in 
b/packaging/fedora/engine-service.py.in
index 97bbebd..5c6b652 100644
--- a/packaging/fedora/engine-service.py.in
+++ b/packaging/fedora/engine-service.py.in
@@ -33,6 +33,7 @@
 import syslog
 import time
 
+import daemon
 from Cheetah.Template import Template
 
 
@@ -545,39 +546,6 @@
         "org.jboss.as.standalone", "-c", os.path.basename(jbossConfigFile),
     ])
 
-    # 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
-
-    # Change the resource limits while we are root as we won't be
-    # able to change them once we assume the engine identity (the
-    # values come from the configuration):
-    setLimit("nofile")
-
-    # This is the child process, first thing we do is assume the engine
-    # identity:
-    if engineGid != os.getgid():
-        os.setgid(engineGid)
-    if engineUid != os.getuid():
-        os.setuid(engineUid)
-
-    # Then close standard input and some other security measures:
-    os.close(0)
-    os.setsid()
-    os.chdir("/")
-
-    # Then open the console log and redirect standard output and errors to it:
-    engineConsoleFd = os.open(engineConsoleLogFile, os.O_CREAT | os.O_WRONLY | 
os.O_APPEND, 0660)
-    os.dup2(engineConsoleFd, 1)
-    os.dup2(engineConsoleFd, 2)
-    os.close(engineConsoleFd)
-
     # Prepare a clean environment:
     engineEnv = {
         "PATH": "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin",
@@ -592,8 +560,45 @@
         "ENGINE_CACHE": engineCacheDir,
     }
 
-    # Finally execute the java virtual machine:
-    os.execvpe(javaLauncher, engineArgs, engineEnv)
+    # Change the resource limits while we are root as we won't be
+    # able to change them once we assume the engine identity (the
+    # values come from the configuration):
+    setLimit("nofile")
+
+    # this is required to allow
+    # writing after user id is changed
+    if enginePidFile is not None:
+        with open(enginePidFile, 'w'):
+            pass
+        os.chown(enginePidFile, engineUid, engineGid)
+
+    #
+    # This to allow current pretty output
+    #
+    if os.fork() != 0:
+        return
+
+    engineConsoleLog = open(engineConsoleLogFile, "w+")
+
+    with daemon.DaemonContext(
+        detach_process=True,
+        signal_map={
+            signal.SIGTERM: 'terminate',
+            signal.SIGHUP: None,
+        },
+        uid=engineUid,
+        gid=engineGid,
+        stdout=engineConsoleLog,
+        stderr=engineConsoleLog,
+    ):
+        saveEnginePid(os.getpid())
+        os.execvpe(
+            file=javaLauncher,
+            args=engineArgs,
+            env=engineEnv,
+        )
+
+    raise Exception("Can't execute \"%s\"." % javaLauncher)
 
 
 def stopEngine():
diff --git a/packaging/fedora/spec/ovirt-engine.spec.in 
b/packaging/fedora/spec/ovirt-engine.spec.in
index 91228ce..ea54f7e 100644
--- a/packaging/fedora/spec/ovirt-engine.spec.in
+++ b/packaging/fedora/spec/ovirt-engine.spec.in
@@ -205,6 +205,7 @@
 Requires: nfs-utils
 Requires: python-cheetah
 Requires: yum
+Requires: python-daemon
 
 %description setup
 Setup and upgrade scripts for %{product_name_short}


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6b533fbdbde47d8fdb62964d60aa22e98c1e57c3
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Alon Bar-Lev <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to