--- /dev/null
+#!/usr/bin/python3
+# -*- coding:Utf-8 -*-
+
+import logging # Logs
+import time # sleep
+import string # split strings
+import os,select
+
+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/rome/log/stdout.log"
+ self.stderr_path = "/home/lionel/work/python/rome/log/stderr.log"
+ self.pidfile_path = "/home/lionel/work/python/rome/pid/horusd.pid"
+ self.pidfile_timeout = 5
+
+ def run(self):
+# We must put all functions before the 'if __name__ blabla'
+
+ def heartbeat(min):
+ seconds = int(min) * 60
+ while True:
+ logger.info("HB : alive")
+ time.sleep(seconds)
+ return False
+
+
+# All functions definitions took place above
+ if __name__ == '__main__':
+ logger.info("Rome test started")
+
+ '''
+ Launching the heartbeat function
+ '''
+ p = Process(target=heartbeat, args=(2,))
+ p.daemon = True
+ p.start()
+ heartbeat_pid = p.pid
+ logger.info("heartbeat loop launched (pid " + str(heartbeat_pid) + ")")
+
+ '''
+ Entering infinite loop
+ '''
+
+ try:
+ while True:
+ time.sleep(30)
+ except:
+ logger.error("While loop interrupted : aborting")
+ # Faut arrêter les Process ...
+
+# Invocation of the daemon part
+# Means : if it's working : DON'T TOUCH ANYTHING
+if __name__ == "__main__":
+ app = App()
+ logger = logging.getLogger("horusd")
+ loglevel = "debug"
+ 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("log/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()