]> gitweb.maison.local Git - rome.git/commitdiff
Initial commit
authorlionel <lionel@isis.maison.local>
Fri, 26 Aug 2016 12:56:21 +0000 (14:56 +0200)
committerlionel <lionel@isis.maison.local>
Fri, 26 Aug 2016 12:56:21 +0000 (14:56 +0200)
doc/README [new file with mode: 0644]
log/.gitignore [new file with mode: 0644]
pid/.gitignore [new file with mode: 0644]
test.py [new file with mode: 0644]

diff --git a/doc/README b/doc/README
new file mode 100644 (file)
index 0000000..fde8d0b
--- /dev/null
@@ -0,0 +1 @@
+For the moment ? nothing
diff --git a/log/.gitignore b/log/.gitignore
new file mode 100644 (file)
index 0000000..5e7d273
--- /dev/null
@@ -0,0 +1,4 @@
+# Ignore everything in this directory
+*
+# Except this file
+!.gitignore
diff --git a/pid/.gitignore b/pid/.gitignore
new file mode 100644 (file)
index 0000000..5e7d273
--- /dev/null
@@ -0,0 +1,4 @@
+# Ignore everything in this directory
+*
+# Except this file
+!.gitignore
diff --git a/test.py b/test.py
new file mode 100644 (file)
index 0000000..5f9c5f8
--- /dev/null
+++ b/test.py
@@ -0,0 +1,88 @@
+#!/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()