Commit ede88c92 authored by Sigmund Augdal's avatar Sigmund Augdal

Port from python-daemon to daemonize library (which seems to work with python3)

parent d08e1f69
......@@ -5,27 +5,19 @@ import logging
import logging.handlers
import time
import argparse
import daemon
from daemonize import Daemonize
import sys
import tempfile
try:
from daemon.pidfile import TimeoutPIDLockFile
except ImportError:
from daemon.pidlockfile import TimeoutPIDLockFile
from nova_router import security_groups
CONF_FILE = "/etc/haproxy/haproxy.cfg"
class Generator(object):
def __init__(self, cert, key, cacert, logfile=None):
self.etcd_client = etcd.Etcd(ssl_key=key, ssl_cert=cert, verify=cacert)
if logfile:
handler = logging.handlers.RotatingFileHandler(logfile, maxBytes=10*1024**3,
backupCount=5)
logging.getLogger("").addHandler(handler)
self.range = [150, 200]
self.prefix = "158.38.213."
def __init__(self, cert, key, cacert):
self.etcd_key = key
self.etcd_cert = cert
self.etcd_cacert = cacert
def output(self, line):
self.output_file.write(line)
......@@ -111,7 +103,12 @@ class Generator(object):
subprocess.call("ipset restore", stdin=self.output_file, shell=True)
return index
def main(self):
def main(self, logfile=None):
if logfile:
handler = logging.handlers.RotatingFileHandler(logfile, maxBytes=10*1024**3,
backupCount=5)
logging.getLogger("").addHandler(handler)
self.etcd_client = etcd.Etcd(ssl_key=self.etcd_key, ssl_cert=self.etcd_cert, verify=self.etcd_cacert)
index = self.generate_all()
sys.exit(0)
while True:
......@@ -136,8 +133,8 @@ if __name__ == '__main__':
args = parse_args()
if args.daemonize:
logfile = '/var/log/nova_sg_configurator.log'
daemon_context = daemon.DaemonContext(pidfile=TimeoutPIDLockFile(args.pidfile))
with daemon_context:
Generator(args.cert, args.key, args.cacert, logfile=logfile).main()
generator = Generator(args.cert, args.key, args.cacert)
daemon = Daemonize(app="nova_sg_configurator", pid=args.pidfile, action=lambda: generator.main(logfile))
daemon.start()
else:
Generator(args.cert, args.key, args.cacert).main()
......@@ -7,7 +7,7 @@ here = os.path.abspath(os.path.dirname(__file__))
requires = [
'etcd-py>0.0.5',
'requests',
'python-daemon',
'daemonize',
'pytest',
'mock',
]
......
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