--- /dev/null
+#!/usr/bin/python2.7
+# -*- coding:Utf-8 -*-
+
+import logging # Logs
+import time # sleep
+import string # split strings
+#import python-daemon
+
+from daemon import runner # daemonization
+
+#from multiprocessing import Process
+#import subprocess
+#import shlex
+
+# logger.debug("Debug message")
+# logger.info("Info message")
+# logger.warn("Warning message")
+# logger.error("Error message")
+
+class App():
+
+ def __init__(self):
+ self.stdin_path = "/dev/null"
+ self.stdout_path = "/home/lionel/work/python/horusd/stdout.log"
+ self.stderr_path = "/home/lionel/work/python/horusd/stderr.log"
+ self.pidfile_path = "/home/lionel/work/python/horusd/horusd.pid"
+ self.pidfile_timeout = 5
+
+ def run(self):
+ if __name__ == '__main__':
+# All functions definitions took place above
+
+ logger.info("horusd started")
+
+## Begin the infinit loop by polling signals values
+ loop_counter = 0
+ while True:
+ time.sleep(2)
+ loop_counter=loop_counter+1
+# Every 300 loops (around 600s/10min on normal conditions),
+# we write informations to the log file and verify power unit keep alive.
+ if (loop_counter) == 3:
+ logger.info("Still Alive.")
+ loop_counter = 0
+
+
+# Invocation of the daemon part
+# Means : if it's working : DON'T TOUCH ANYTHING
+if __name__ == "__main__":
+
+ app = App()
+ logger = logging.getLogger("horusd")
+ loglevel = "info"
+ if (loglevel=="DEBUG") or (loglevel=="debug"):
+ logger.setLevel(logging.DEBUG)
+ elif (loglevel=="INFO") or (loglevel=="info"):
+ logger.setLevel(logging.INFO)
+ elif (loglevel=="WARN") or (loglevel=="warn"):
+ logger.setLevel(logging.WARN)
+ elif (loglevel=="ERROR") or (loglevel=="error"):
+ logger.setLevel(logging.ERROR)
+ else:
+ logger.setLevel(logging.DEBUG)
+ formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
+ handler = logging.FileHandler("horusd.log")
+ handler.setFormatter(formatter)
+ logger.addHandler(handler)
+
+ daemon_runner = runner.DaemonRunner(app)
+ #This ensures that the logger file handle does not get closed during daemonization
+ daemon_runner.daemon_context.files_preserve=[handler.stream]
+ daemon_runner.do_action()