I've found 'daemon.py' script by Sander Marechal and I want to use it to execute my simply test script which prints text. When I execute script without 'execfile()' it creates daemon-example.pid and daemon works but when I add 'execfile()' it doesn't work.
here is code:
#!/usr/bin/env python
import sys
from daemon import Daemon
class MyDaemon(Daemon):
def run(self):
while True:
execfile("text.py")
time.sleep(1)
if __name__ == "__main__":
daemon = MyDaemon('/tmp/daemon-example.pid')
if len(sys.argv) == 2:
if 'start' == sys.argv[1]:
daemon.start()
elif 'stop' == sys.argv[1]:
daemon.stop()
elif 'restart' == sys.argv[1]:
daemon.restart()
else:
print "Unknown command"
sys.exit(2)
sys.exit(0)
else:
print "usage: %s start|stop|restart" % sys.argv[0]
sys.exit(2)