projects
/
ganeti-local
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add --uid-pool option to gnt-cluster init
[ganeti-local]
/
lib
/
daemon.py
diff --git
a/lib/daemon.py
b/lib/daemon.py
index
09c1393
..
ff77089
100644
(file)
--- a/
lib/daemon.py
+++ b/
lib/daemon.py
@@
-30,6
+30,7
@@
import logging
import sched
import time
import socket
import sched
import time
import socket
+import select
import sys
from ganeti import utils
import sys
from ganeti import utils
@@
-91,20
+92,23
@@
class AsyncUDPSocket(asyncore.dispatcher):
# differ and treat all messages equally.
pass
# differ and treat all messages equally.
pass
+ def do_read(self):
+ try:
+ payload, address = self.recvfrom(constants.MAX_UDP_DATA_SIZE)
+ except socket.error, err:
+ if err.errno == errno.EINTR:
+ # we got a signal while trying to read. no need to do anything,
+ # handle_read will be called again if there is data on the socket.
+ return
+ else:
+ raise
+ ip, port = address
+ self.handle_datagram(payload, ip, port)
+
# this method is overriding an asyncore.dispatcher method
def handle_read(self):
try:
# this method is overriding an asyncore.dispatcher method
def handle_read(self):
try:
- try:
- payload, address = self.recvfrom(constants.MAX_UDP_DATA_SIZE)
- except socket.error, err:
- if err.errno == errno.EINTR:
- # we got a signal while trying to read. no need to do anything,
- # handle_read will be called again if there is data on the socket.
- return
- else:
- raise
- ip, port = address
- self.handle_datagram(payload, ip, port)
+ self.do_read()
except: # pylint: disable-msg=W0702
# we need to catch any exception here, log it, but proceed, because even
# if we failed handling a single request, we still want to continue.
except: # pylint: disable-msg=W0702
# we need to catch any exception here, log it, but proceed, because even
# if we failed handling a single request, we still want to continue.
@@
-153,6
+157,22
@@
class AsyncUDPSocket(asyncore.dispatcher):
constants.MAX_UDP_DATA_SIZE))
self._out_queue.append((ip, port, payload))
constants.MAX_UDP_DATA_SIZE))
self._out_queue.append((ip, port, payload))
+ def process_next_packet(self, timeout=0):
+ """Process the next datagram, waiting for it if necessary.
+
+ @type timeout: float
+ @param timeout: how long to wait for data
+ @rtype: boolean
+ @return: True if some data has been handled, False otherwise
+
+ """
+ result = utils.WaitForFdCondition(self, select.POLLIN, timeout)
+ if result is not None and result & select.POLLIN:
+ self.do_read()
+ return True
+ else:
+ return False
+
class Mainloop(object):
"""Generic mainloop for daemons
class Mainloop(object):
"""Generic mainloop for daemons
@@
-245,6
+265,12
@@
def GenericMain(daemon_name, optionparser, dirs, check_fn, exec_fn):
optionparser.add_option("-d", "--debug", dest="debug",
help="Enable some debug messages",
default=False, action="store_true")
optionparser.add_option("-d", "--debug", dest="debug",
help="Enable some debug messages",
default=False, action="store_true")
+ optionparser.add_option("--syslog", dest="syslog",
+ help="Enable logging to syslog (except debug"
+ " messages); one of 'no', 'yes' or 'only' [%s]" %
+ constants.SYSLOG_USAGE,
+ default=constants.SYSLOG_USAGE,
+ choices=["no", "yes", "only"])
if daemon_name in constants.DAEMONS_PORTS:
# for networked daemons we also allow choosing the bind port and address.
# by default we use the port provided by utils.GetDaemonPort, and bind to
if daemon_name in constants.DAEMONS_PORTS:
# for networked daemons we also allow choosing the bind port and address.
# by default we use the port provided by utils.GetDaemonPort, and bind to
@@
-296,7
+322,9
@@
def GenericMain(daemon_name, optionparser, dirs, check_fn, exec_fn):
utils.SetupLogging(logfile=constants.DAEMONS_LOGFILES[daemon_name],
debug=options.debug,
stderr_logging=not options.fork,
utils.SetupLogging(logfile=constants.DAEMONS_LOGFILES[daemon_name],
debug=options.debug,
stderr_logging=not options.fork,
- multithreaded=multithread)
+ multithreaded=multithread,
+ program=daemon_name,
+ syslog=options.syslog)
logging.info("%s daemon startup", daemon_name)
exec_fn(options, args)
finally:
logging.info("%s daemon startup", daemon_name)
exec_fn(options, args)
finally: