0

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)
mac
  • 23
  • 8
  • 1
    What do you mean by `it doesn't work`? also why you are calling `execfile` on a *python* file from *python*? you could have just import and call it. – Shiplu Mokaddim Oct 25 '14 at 19:01
  • aaa I didn't know that I can only import script name and call it. Now my text script is execute but process after execute script is killed nad daemon-example.pid doesn't exist – mac Oct 25 '14 at 19:18
  • I want to execute my text script for every 60 second for example but now it executes once and stop it – mac Oct 25 '14 at 20:10
  • Why don't you just use Cron for that? – Max Noel Oct 25 '14 at 20:32
  • I'm trying right now. I've added to crontab line * * * * /usr/bin/ /usr/bin/script and I've set chmod execute for files but I'm getting '/usr/bin permisson denid' – mac Oct 25 '14 at 21:36
  • I can't use Cron because my script uses recived emails and I want to execute my script when new mail is received. So exactly I don't want to execute every 60 second because it uses the same mail couple of times. Do you have idea how I should execute my script when new mail is recived ? – mac Oct 26 '14 at 00:32
  • Then you should execute it as a callback or plugin. It depends on your mail server. – Shiplu Mokaddim Oct 26 '14 at 04:56
  • Could you tell me something more ? – mac Oct 26 '14 at 05:41

0 Answers0