Commit 5f575b85 authored by Cédric Le Ninivin's avatar Cédric Le Ninivin

equeue: will remove socket on start

parent e025bfd0
...@@ -119,6 +119,14 @@ class EqueueServer(SocketServer.ThreadingUnixStreamServer): ...@@ -119,6 +119,14 @@ class EqueueServer(SocketServer.ThreadingUnixStreamServer):
else: else:
self.logger.info("%s already runned.", command) self.logger.info("%s already runned.", command)
# Well the following function is made for schrodinger's files,
# It will work if the file exists or not
def remove_existing_file(path):
try:
os.remove(path)
except OSError, e:
if e.errno != errno.ENOENT:
raise
def main(): def main():
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
...@@ -144,16 +152,13 @@ def main(): ...@@ -144,16 +152,13 @@ def main():
signal.signal(signal.SIGHUP, lambda *args: sys.exit(-1)) signal.signal(signal.SIGHUP, lambda *args: sys.exit(-1))
signal.signal(signal.SIGTERM, lambda *args: sys.exit()) signal.signal(signal.SIGTERM, lambda *args: sys.exit())
remove_existing_file(socketpath)
try: try:
server = EqueueServer(socketpath, **{'equeue_options':args}) server = EqueueServer(socketpath, **{'equeue_options':args})
server.logger.info("Starting server on %r", socketpath) server.logger.info("Starting server on %r", socketpath)
server.serve_forever() server.serve_forever()
finally: finally:
try: remove_existing_file(socketpath)
os.remove(socketpath)
except OSError, e:
if e.errno != errno.ENOENT:
raise
if __name__ == '__main__': if __name__ == '__main__':
main() main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment