|
@@ -10,6 +10,7 @@ import time
|
|
import sys
|
|
import sys
|
|
import signal
|
|
import signal
|
|
import os
|
|
import os
|
|
|
|
+import logging
|
|
from optparse import OptionParser
|
|
from optparse import OptionParser
|
|
|
|
|
|
import stddlib.daemon
|
|
import stddlib.daemon
|
|
@@ -42,10 +43,8 @@ parser.add_option("-c", "--config", dest="config", help="define an\
|
|
|
|
|
|
run = True
|
|
run = True
|
|
|
|
|
|
-""" create the configuration object according to the given parameters and
|
|
|
|
-read the file itself
|
|
|
|
|
|
|
|
-"""
|
|
|
|
|
|
+""" define a sighandler to properly catch signals """
|
|
|
|
|
|
def sighandler(signum, frame):
|
|
def sighandler(signum, frame):
|
|
if signum == 2:
|
|
if signum == 2:
|
|
@@ -63,6 +62,11 @@ def sighandler(signum, frame):
|
|
#TODO: Log error message
|
|
#TODO: Log error message
|
|
sys,exit(1)
|
|
sys,exit(1)
|
|
|
|
|
|
|
|
+""" create the configuration object according to the given parameters and
|
|
|
|
+read the file itself
|
|
|
|
+
|
|
|
|
+"""
|
|
|
|
+
|
|
signal.signal(signal.SIGTERM, sighandler)
|
|
signal.signal(signal.SIGTERM, sighandler)
|
|
signal.signal(signal.SIGINT, sighandler)
|
|
signal.signal(signal.SIGINT, sighandler)
|
|
|
|
|
|
@@ -73,6 +77,31 @@ else:
|
|
config.Read()
|
|
config.Read()
|
|
config.Analyze()
|
|
config.Analyze()
|
|
|
|
|
|
|
|
+
|
|
|
|
+""" create a logger to log errors according to configuration """
|
|
|
|
+
|
|
|
|
+logger = logging.getLogger("stdd")
|
|
|
|
+
|
|
|
|
+if config.syslog_level == "debug":
|
|
|
|
+ logger.setLevel(logging.DEBUG)
|
|
|
|
+elif config.syslog_level == "error":
|
|
|
|
+ logger.setLevel(logging.ERROR)
|
|
|
|
+else:
|
|
|
|
+ logget.setLevel(logging.INFO)
|
|
|
|
+
|
|
|
|
+syslog_handler = logging.handlers.SysLogHandler("/dev/log")
|
|
|
|
+console_handler = logging.StreamHandler()
|
|
|
|
+
|
|
|
|
+formatter = logging.Formatter("%(asctime)s - %(name)s - %(message)s")
|
|
|
|
+
|
|
|
|
+syslog_handler.setFormatter(formatter)
|
|
|
|
+console_handler.setFormatter(formatter)
|
|
|
|
+
|
|
|
|
+if options.daemon is True:
|
|
|
|
+ logger.addHandler(syslog_handler)
|
|
|
|
+else:
|
|
|
|
+ logger.addHandler(console_handler)
|
|
|
|
+
|
|
if options.daemon is True:
|
|
if options.daemon is True:
|
|
if os.access("/run", os.F_OK & os.W_OK) is True:
|
|
if os.access("/run", os.F_OK & os.W_OK) is True:
|
|
daemon = stddlib.daemon.Daemon("/run", "stdd")
|
|
daemon = stddlib.daemon.Daemon("/run", "stdd")
|
|
@@ -80,6 +109,7 @@ if options.daemon is True:
|
|
daemon = stddlib.daemon.Daemon("/var/run", "stdd")
|
|
daemon = stddlib.daemon.Daemon("/var/run", "stdd")
|
|
daemon.Daemonize()
|
|
daemon.Daemonize()
|
|
daemon.Start()
|
|
daemon.Start()
|
|
|
|
+ logger.info("daemon started")
|
|
cmdline = ""
|
|
cmdline = ""
|
|
for element in sys.argv:
|
|
for element in sys.argv:
|
|
cmdline = cmdline + " " + element
|
|
cmdline = cmdline + " " + element
|