Commit cd0faf8f authored by Sigmund Augdal's avatar Sigmund Augdal

Cleanup how daemonize gets used, and port one more script from python-daemon

parent 45878483
......@@ -2,4 +2,4 @@
*.pyc
*.egg-info
.coverage
build
\ No newline at end of file
build
......@@ -7,14 +7,12 @@ import logging
import logging.handlers
import time
import argparse
import daemon
from daemonize import Daemonize
import socket
try:
from daemon.pidfile import TimeoutPIDLockFile
except ImportError:
from daemon.pidlockfile import TimeoutPIDLockFile
CONF_FILE = "/etc/haproxy/haproxy.cfg"
APP = "nova_dhcp_configurator"
DESCRIPTION = "Generate dhcp server config based on neighbor list in etcd"
def etcd_get_dict(etcd_client, prefix):
......@@ -37,7 +35,9 @@ 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:
logging.getLogger("").addHandler(logging.handlers.RotatingFileHandler(logfile, maxBytes=10*1024**3, backupCount=5))
handler = logging.handlers.RotatingFileHandler(logfile,
maxBytes=10*1024**3, backupCount=5)
logging.getLogger("").addHandler(handler)
self.range = [150, 200]
self.prefix = "158.38.213."
......@@ -110,13 +110,24 @@ class Generator(object):
index = self.generate_all()
def daemon_main(args):
generator = Generator(args.cert, args.key, args.cacert, args.logfeil)
generator.main()
def parse_args():
parser = argparse.ArgumentParser(description="Configure haproxy based on data from etcd")
parser.add_argument('-d', '--daemonize', default=False, action='store_true', help="Run as daemon")
parser.add_argument('--pidfile', type=str, default="/var/run/nova_lb_configuration.pid", help="pidfile when run as daemon")
parser = argparse.ArgumentParser(description=DESCRIPTION)
parser.add_argument('-d', '--daemonize', default=False, action='store_true',
help="Run as daemon")
parser.add_argument('--pidfile', type=str, default="/var/run/{}.pid".format(APP),
help="pidfile when run as daemon")
parser.add_argument('--cert', default="client.crt", help="client certificate to use")
parser.add_argument('--key', default="client.key", help="private key to use for client certificate")
parser.add_argument('--key', default="client.key",
help="private key to use for client certificate")
parser.add_argument('--cacert', default="etcd_ca.crt", help="ca certificate to use")
parser.add_argument('--logfile', default='/var/log/{}.log'.format(APP),
help="logfile to use")
return parser.parse_args()
if __name__ == '__main__':
......@@ -124,9 +135,7 @@ if __name__ == '__main__':
logging.getLogger("requests").setLevel(logging.WARNING)
args = parse_args()
if args.daemonize:
logfile='/var/log/nova_loadbalancer_configurator.log'
daemon_context = daemon.DaemonContext(pidfile=TimeoutPIDLockFile(args.pidfile))
with daemon_context:
Generator(args.cert, args.key, args.cacert, logfile=logfile).main()
daemon = Daemonize(app=APP, pid=args.pidfile, action=lambda: daemon_main(args))
daemon.start()
else:
Generator(args.cert, args.key, args.cacert).main()
......@@ -11,6 +11,10 @@ import tempfile
from nova_router import security_groups
APP = "nova_sg_configurator"
DESCRIPTION = "Configure ipset based on data from etcd"
class Generator(object):
def __init__(self, cert, key, cacert, logfile=None):
self.etcd_client = etcd.Etcd(ssl_key=key, ssl_cert=cert, verify=cacert)
......@@ -119,13 +123,17 @@ def daemon_main(args):
def parse_args():
parser = argparse.ArgumentParser(description="Configure ipset based on data from etcd")
parser.add_argument('-d', '--daemonize', default=False, action='store_true', help="Run as daemon")
parser.add_argument('--pidfile', type=str, default="/var/run/nova_sg_configurator.pid", help="pidfile when run as daemon")
parser = argparse.ArgumentParser(description=DESCRIPTION)
parser.add_argument('-d', '--daemonize', default=False, action='store_true',
help="Run as daemon")
parser.add_argument('--pidfile', type=str, default="/var/run/{}.pid".format(APP),
help="pidfile when run as daemon")
parser.add_argument('--cert', default="client.crt", help="client certificate to use")
parser.add_argument('--key', default="client.key", help="private key to use for client certificate")
parser.add_argument('--key', default="client.key",
help="private key to use for client certificate")
parser.add_argument('--cacert', default="etcd_ca.crt", help="ca certificate to use")
parser.add_argument('--logfile', default='/var/log/nova_sg_configurator.log', help="logfile to use")
parser.add_argument('--logfile', default='/var/log/{}.log'.format(APP),
help="logfile to use")
return parser.parse_args()
......@@ -134,7 +142,7 @@ if __name__ == '__main__':
logging.getLogger("requests").setLevel(logging.WARNING)
args = parse_args()
if args.daemonize:
daemon = Daemonize(app="nova_sg_configurator", pid=args.pidfile, action=lambda: daemon_main(args))
daemon = Daemonize(app=APP, pid=args.pidfile, action=lambda: daemon_main(args))
daemon.start()
else:
Generator(args.cert, args.key, args.cacert).main()
#!/usr/bin/env python
import logging
import argparse
from daemonize import Daemonize
log = logging.getLogger("neighbors")
# arp
......@@ -10,11 +12,14 @@ log = logging.getLogger("neighbors")
# RTM_NEWNEIGH, RTM_DELNEIGH
#
from pyroute2.netlink.iproute import IPRoute
import sys
import etcd
from nova_router import neighbors
APP = "nova_neighbor_monitor"
DESCRIPTION = "Monitor neighbors and keep updated set of mac/ip bindings in etcd"
def byteswap(a):
return ((a & 0xff000000) >> 24) | ((a & 0xff0000) >> 8) | \
((a & 0xff00) << 8) | ((a & 0xff) << 24)
......@@ -94,15 +99,44 @@ class NeighborCache(object):
self.ir.release()
def main():
def main(args):
logging.basicConfig(level=logging.DEBUG)
logging.getLogger("requests").setLevel(logging.INFO)
ssl_cert = "/etc/etcd/server.crt"
ssl_key = "/etc/etcd/server.key"
cacert = "/etc/etcd/myca.crt"
if args.daemonize:
handler = logging.handlers.RotatingFileHandler(args.logfile, maxBytes=10*1024**3,
backupCount=5)
logging.getLogger("").addHandler(handler)
cache = NeighborCache(ssl_cert, ssl_key, cacert, sys.argv[1], sys.argv[2:])
cache = NeighborCache(args.cert, args.key, args.cacert, args.interface, args.routers)
cache.run()
def parse_args():
parser = argparse.ArgumentParser(description=DESCRIPTION)
parser.add_argument('-d', '--daemonize', default=False, action='store_true',
help="Run as daemon")
parser.add_argument('--pidfile', type=str, default="/var/run/{}.pid".format(APP),
help="pidfile when run as daemon")
parser.add_argument('--cert', default="client.crt", help="client certificate to use")
parser.add_argument('--key', default="client.key",
help="private key to use for client certificate")
parser.add_argument('--cacert', default="etcd_ca.crt", help="ca certificate to use")
parser.add_argument('--logfile', default='/var/log/{}.log'.format(APP),
help="logfile to use")
parser.add_argument('--interface', help="Interface to monitor", required=True)
parser.add_argument('--routers',
help="Comma-separated list of routers to ignore when monitoring",
nargs="*", required=True)
return parser.parse_args()
if __name__ == '__main__':
main()
logging.basicConfig(level=logging.DEBUG)
logging.getLogger("requests").setLevel(logging.WARNING)
args = parse_args()
if args.daemonize:
daemon = Daemonize(app=APP, pid=args.pidfile,
action=lambda: main(args))
daemon.start()
else:
main(args)
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