improved example script 0.4
authorkaliko <efrim@azylum.org>
Sun, 23 Oct 2011 12:24:53 +0000 (14:24 +0200)
committerkaliko <efrim@azylum.org>
Sun, 23 Oct 2011 12:24:53 +0000 (14:24 +0200)
doc/examples/daemon-example.py

index 2baca82..87a80bc 100755 (executable)
@@ -4,12 +4,24 @@ import sys, time
 from daemon import Daemon
 
 class MyDaemon(Daemon):
+
+    def __init__(self, pid, log):
+      Daemon.__init__(self, pid, stdout=log, stderr=log)
+
     def run(self):
+        """Overrides Daemon().run() with actions you want to daemonize.
+        MyDaemon.run() is then called within MyDaemon().start()"""
+        print "Starting Deamon!"
         while True:
             time.sleep(1)
 
+    def shutdown(self):
+        """Overrides Daemon().shutdown() with some clean up"""
+        print "Stopping Daemon!"
+
 if __name__ == "__main__":
-    daemon = MyDaemon('/tmp/daemon-example.pid')
+    daemon = MyDaemon('/tmp/daemon-example.pid',
+            '/tmp/daemon.log')
     if len(sys.argv) == 2:
         if 'start' == sys.argv[1]:
             daemon.start()