【发布时间】:2018-02-21 19:19:51
【问题描述】:
我有以下简单的python脚本test.py(玩具示例)
#!/usr/bin/python
import time
from time import gmtime, strftime
from daemon import runner
import config
import subprocess
class App():
def __init__(self):
self.stdin_path = '/dev/null'
self.stdout_path = '/dev/tty'
self.stderr_path = '/dev/tty'
self.pidfile_path = '/tmp/foo.pid'
self.pidfile_timeout = 5
def run(self):
while True:
file = open('/var/www/myfile.dat'+strftime("%Y-%m-%d %H:%M:%S", gmtime()), 'w+')
file.write("Hello World")
file.close()
time.sleep(20)
app = App()
daemon_runner = runner.DaemonRunner(app)
daemon_runner.do_action()
我想在 Linux Centos 7 启动时运行该脚本。
出于这个原因,我在rc.local 文件中添加了这一行
touch python /root/scripts/test.py start
但不幸的是脚本没有运行。
附:当我从命令行python test.py start 运行该脚本时,它可以完美运行。
【问题讨论】:
-
我知道如何在 python 中创建守护进程(上面的脚本)问题是我无法在启动时运行它
标签: python centos7 daemon boot