All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Charles Coffing" <ccoffing@novell.com>
To: xen-devel@lists.sourceforge.net
Subject: [PATCH]  better daemon-ization of xend
Date: Fri, 17 Sep 2004 14:45:11 -0600	[thread overview]
Message-ID: <s14af880.078@sinclair.provo.novell.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 808 bytes --]

The attached patch tidies up how xend becomes a daemon, and it hooks up
the "restart" and "status" commands.


Details:

I attempted to start xend from SuSE's YaST, but YaST hung waiting on
xend to start.  Turns out that xend wasn't quite becoming a daemon. 
setsid was conditionally called for xend, and never called for xfrd. 
Stdin, stdout, and stderr were left open and this is what hung YaST.

Daemon.(start|status) now return LSB-defined error codes.  I realize the
python scripts are probably meant to be cross platform, but it seemed
cleaner to inheirit a few LSB error codes here, rather than create my
own and then try to remap them up in /etc/init.d/xend.

I still suspect Linux distributions will write their own
/etc/init.d/xend scripts, but at least now the stock one behaves a
little better.


[-- Attachment #2: xend.diff --]
[-- Type: application/octet-stream, Size: 3387 bytes --]

--- xeno-unstable.bk/tools/misc/xend	2004-09-09 15:34:50.000000000 -0600
+++ xeno-unstable.bk.new/tools/misc/xend	2004-09-17 04:40:15.000000000 -0600
@@ -8,11 +8,12 @@
    Provides console server and HTTP management api.
 
    Run:
-
    xend start
 
-   The daemon is stopped with:
+   Restart:
+   xend restart
 
+   The daemon is stopped with:
    xend stop
 
    The daemon should reconnect to device control interfaces
@@ -107,6 +108,8 @@
         return daemon.stop()
     elif sys.argv[1] == 'restart':
         return daemon.stop() or daemon.start()
+    elif sys.argv[1] == 'status':
+        return daemon.status()
     else:
         print 'not an option:', sys.argv[1]
     return 1
--- xeno-unstable.bk/tools/python/xen/xend/server/SrvDaemon.py	2004-09-09 15:34:50.000000000 -0600
+++ xeno-unstable.bk.new/tools/python/xen/xend/server/SrvDaemon.py	2004-09-17 12:20:48.000000000 -0600
@@ -42,7 +42,7 @@
 import domain
 from params import *
 
-DEBUG = 1
+DEBUG = 0
 
 class NotifierProtocol(protocol.Protocol):
     """Asynchronous handler for i/o on the notifier (event channel).
@@ -419,6 +419,18 @@
         self.cleanup_xend(kill=kill)
         self.cleanup_xfrd(kill=kill)
             
+    def status(self):
+        """Returns the status of the xend and xfrd daemons.
+        The return value is defined by the LSB:
+        0  Running
+        3  Not running
+        """
+        if (self.cleanup_process(XEND_PID_FILE, "xend", False) == 0 or
+            self.cleanup_process(XFRD_PID_FILE, "xfrd", False) == 0):
+            return 3
+        else:
+            return 0
+
     def install_child_reaper(self):
         #signal.signal(signal.SIGCHLD, self.onSIGCHLD)
         # Ensure that zombie children are automatically reaped.
@@ -451,22 +463,36 @@
             pass
         else:
             # Child
-            self.set_user()
             os.execl("/usr/sbin/xfrd", "xfrd")
             
     def start(self, trace=0):
+        """Attempts to start the daemons.
+        The return value is defined by the LSB:
+        0  Success
+        4  Insufficient privileges
+        """
         xend_pid = self.cleanup_xend()
         xfrd_pid = self.cleanup_xfrd()
-        if xfrd_pid == 0:
-            self.start_xfrd()
-        if xend_pid > 0:
-            return 1
 
         # Detach from TTY.
         if not DEBUG:
             os.setsid()
+            sys.stdin.close();
+            sys.stdout.close();
+            sys.stderr.close();
+            os.close(0);
+            os.close(1);
+            os.close(2);
         if self.set_user():
-            return 1
+            return 4
+        os.chdir("/")
+
+        if xfrd_pid == 0:
+            self.start_xfrd()
+        if xend_pid > 0:
+            # Trying to run an already-running service is a success.
+            return 0
+
         self.install_child_reaper()
 
         if self.fork_pid(XEND_PID_FILE):
--- xeno-unstable.bk/tools/examples/init.d/xend	2004-09-16 09:41:43.000000000 -0600
+++ xeno-unstable.bk.new/tools/examples/init.d/xend	2004-09-17 12:19:05.000000000 -0600
@@ -10,15 +10,15 @@
 case "$1" in
   start)
 	xend start
-	exit $?
 	;;
   stop)
 	xend stop
-	exit $?
 	;;
   status)
+	xend status
 	;;
   restart|reload)
+	xend restart
 	;;
   *)
 	# do not advertise unreasonable commands that there is no reason
@@ -27,5 +27,5 @@
 	exit 1
 esac
 
-exit 0
+exit $?
 

                 reply	other threads:[~2004-09-17 20:45 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=s14af880.078@sinclair.provo.novell.com \
    --to=ccoffing@novell.com \
    --cc=xen-devel@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.