我试图创build一个新贵的脚本来启动时运行一个python脚本。 从理论上讲,这看起来很简单,但我似乎无法得到它的工作。 我正在使用我在这里find并改变的骨架脚本。
description "Used to start python script as a service" author "Me <[email protected]>" # Stanzas # # Stanzas control when and how a process is started and stopped # See a list of stanzas here: http://upstart.ubuntu.com/wiki/Stanzas#respawn # When to start the service start on runlevel [2345] # When to stop the service stop on runlevel [016] # Automatically restart process if crashed respawn # Essentially lets upstart know the process will detach itself to the background expect fork # Start the process script exec python /usr/local/scripts/script.py end script
我希望它运行的testing脚本是一个简单的python脚本,从terminal运行时没有任何问题。
#!/usr/bin/python2 import os, sys, time if __name__ == "__main__": for i in range (10000): message = "UpstartTest " , i , time.asctime() , " - Username: " , os.getenv("USERNAME") #print message time.sleep(60) out = open("/var/log/scripts/scriptlogfile", "a") print >> out, message out.close()
respawn 。 看到:
fork 。 你可以简化节开始你的工作简单地说:
exec python /usr/local/scripts/script.py
/var/log/upstart/yourjob.log显示什么?
新贵脚本进入/ etc / init而不是/etc/init.d ,那一周是漫长的一周。 🙁