extras-buildsys/server main.py,1.5,1.6

Daniel Williams (dcbw) fedora-extras-commits at redhat.com
Mon Jul 11 03:23:24 UTC 2005


Author: dcbw

Update of /cvs/fedora/extras-buildsys/server
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv21781/server

Modified Files:
	main.py 
Log Message:
2005-07-10  Dan Williams <dcbw at redhat.com>

    Patch from Ignacio Vazquez-Abrams <ivazquez at ivazquez.net>
    * Add initscript/daemon support for the server




Index: main.py
===================================================================
RCS file: /cvs/fedora/extras-buildsys/server/main.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- main.py	10 Jul 2005 03:44:37 -0000	1.5
+++ main.py	11 Jul 2005 03:23:22 -0000	1.6
@@ -60,12 +60,35 @@
 #################################################################
 
 if __name__ == '__main__':
-    if len(sys.argv) < 2:
-        print "Usage:\n"
-        print "   %s <hostname>\n" % sys.argv[0]
+    usage = "Usage: %s  [-p <pidfile>] [-l <logfile>] [-d] <hostname>" % sys.argv[0]
+    parser = OptionParser(usage=usage)
+    parser.add_option("-p", "--pidfile", default=None,
+        help='file to write the PID to')
+    parser.add_option("-l", "--logfile", default=None,
+        help="location of file to write log output to")
+    parser.add_option("-d", "--daemon", default=False, action="store_true",
+        help="daemonize (i.e., detach from the terminal)")
+    (opts, args) = parser.parse_args()
+
+    if (not len(args) == 1):
+        print "Must specify a single hostname."
         sys.exit(1)
 
-    hostname = sys.argv[1]
+    hostname = args[0]
+
+    if opts.daemon:
+        ret=daemonize.createDaemon()
+        if ret:
+            print "Daemonizing failed!"
+            sys.exit(2)
+
+    if opts.pidfile:
+        open(opts.pidfile, 'w').write('%d\n' % os.getpid())
+
+    if opts.logfile:
+        log=open(opts.logfile, 'a')
+        sys.stdout=log
+        sys.stderr=log
 
     builder_manager = BuilderManager.BuilderManager()
 




More information about the fedora-extras-commits mailing list