]> kaliko git repositories - python-daemon.git/blobdiff - doc/examples/daemon-example.py
Add setup.py and moved to seth namespace :)
[python-daemon.git] / doc / examples / daemon-example.py
index 2baca825b214a2baf5e059a8fdf4d97ca0905843..47dff70241296913c9961d024a93bbac45743fa9 100755 (executable)
@@ -1,15 +1,27 @@
 #!/usr/bin/env python
 
 import sys, time
-from daemon import Daemon
+from seth 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()