Config reload with SIGHUP.

master
q3k 2012-11-14 15:39:58 +01:00
parent ccfa43fcd5
commit 51a09827dd
2 changed files with 21 additions and 2 deletions

View File

@ -3,6 +3,7 @@
import sys, logging
import tftpy
import re
import signal
LEASES_FILE = "/var/lib/dhcp/dhcpd.leases"
@ -51,6 +52,14 @@ def hook(pattern, match_mac=None):
import hooks
def main():
def sighup_handler(signum, frame):
signal.siginterrupt(signal.SIGHUP, False)
sys.stderr.write("Reloading config...\n")
sys.stderr.flush()
file_hooks = {}
reload(hooks)
signal.signal(signal.SIGHUP, sighup_handler)
server = tftpy.TftpServer("/var/khepri/tftp-root/", dyn_file_func=hook_dispatcher)
try:
server.listen("10.8.1.1", 5000)
@ -59,4 +68,3 @@ def main():
sys.exit(1)
except KeyboardInterrupt:
pass

View File

@ -5,11 +5,22 @@ TftpShared."""
import socket, os, time
import select
import signal
import errno
from TftpShared import *
from TftpPacketTypes import *
from TftpPacketFactory import TftpPacketFactory
from TftpContexts import TftpContextServer
def until_concludes(f, *a, **kw):
while True:
try:
return f(*a, **kw)
except (IOError, OSError, select.error), e:
if e.args[0] == errno.EINTR:
continue
raise
class TftpServer(TftpSession):
"""This class implements a tftp server object. Run the listen() method to
listen for client requests. It takes two optional arguments. tftproot is
@ -81,7 +92,7 @@ class TftpServer(TftpSession):
# Block until some socket has input on it.
log.debug("Performing select on this inputlist: %s" % inputlist)
readyinput, readyoutput, readyspecial = select.select(inputlist,
readyinput, readyoutput, readyspecial = until_concludes(select.select, inputlist,
[],
[],
SOCK_TIMEOUT)