extras-buildsys/builder builder.py,1.10,1.11
Daniel Williams (dcbw)
fedora-extras-commits at redhat.com
Sun Jul 10 04:48:40 UTC 2005
Author: dcbw
Update of /cvs/fedora/extras-buildsys/builder
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv20652/builder
Modified Files:
builder.py
Log Message:
2005-07-09 Dan Williams <dcbw at redhat.com>
Patch from Ignacio Vazquez-Abrams <ivazquez at ivazquez.net>
* Add initscript/daemonize support for the builder
Index: builder.py
===================================================================
RCS file: /cvs/fedora/extras-buildsys/builder/builder.py,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- builder.py 10 Jul 2005 03:44:35 -0000 1.10
+++ builder.py 10 Jul 2005 04:48:38 -0000 1.11
@@ -34,6 +34,7 @@
from plague import AuthedXMLRPCServer
from plague import lighttpdManager
from plague import HTTPServer
+from plague import daemonize
# Load in the config
@@ -596,11 +597,40 @@
if __name__ == '__main__':
- if len(sys.argv) < 3:
+ state={'opts': True, 'host': None, 'archs': [],
+ 'daemon': False, 'pidfile': None, 'logfile': None}
+
+ for i in sys.argv[1:]:
+ if state['logfile']=='':
+ state['logfile']=i
+ continue
+ if state['pidfile']=='':
+ state['pidfile']=i
+ continue
+ if i.startswith('-'):
+ if state['opts']:
+ if i=='-d':
+ state['daemon']=True
+ elif i=='-p':
+ state['pidfile']=''
+ elif i=='-l':
+ state['logfile']=''
+ elif i=='--':
+ state['opts']=False
+ continue
+ if not state['host']:
+ state['host']=i
+ else:
+ state['archs'].append(i)
+
+ if not state['host'] or not state['archs'] or (state['pidfile']=='') or (state['logfile']==''):
print "Usage:\n"
- print " %s <hostname> <archlist>\n" % sys.argv[0]
+ print " %s <hostname> <archlist> [-p <pidfile>] [-l <logfile>] [-d]\n" % sys.argv[0]
print " <hostname> - hostname or IP address of this machine"
print " <archlist> - space-separated list of arches this machine can build"
+ print " <pidfile> - file to write the PID to"
+ print " <logfile> - file to write messages to instead of stdout"
+ print " -d - daemonize (i.e., detach from the terminal)"
# pretty-print the available archlist
archlist = ""
@@ -613,8 +643,22 @@
print " Available arches: [ %s ]\n" % archlist
sys.exit(1)
- g_our_hostname = sys.argv[1]
- localarches = sys.argv[2:]
+ g_our_hostname = state['host']
+ localarches = state['archs']
+
+ if state['daemon']:
+ ret=daemonize.createDaemon()
+ if ret:
+ print "Daemonizing failed!"
+ sys.exit(2)
+
+ if state['pidfile']:
+ open(state['pidfile'], 'w').write('%d\n' % os.getpid())
+
+ if state['logfile']:
+ log=open(state['logfile'], 'a')
+ sys.stdout=log
+ sys.stderr=log
work_dir = config_opts['builder_work_dir']
if not os.path.exists(work_dir) or not os.access(work_dir, os.R_OK):
More information about the fedora-extras-commits
mailing list