【发布时间】:2017-10-17 23:05:07
【问题描述】:
我有一个这样的 python 脚本:
while True:
print("ok")
我创建了一个守护进程 test.service:
[Unit]
Description=Un service de test.
[Service]
Type=idle
ExecStart=/usr/bin/python3 /home/andy/Desktop/test.py > /home/andy/Desktop/test.log 2>&1
[Install]
WantedBy=multi-user.target
我使用 sudo systemctl start test.service 激活它。 没有创建日志文件:输出重定向不起作用。
当我写 systemctl status test.service 时,我有:
● test.service - Un service de test.
Loaded: loaded (/etc/systemd/system/test.service; disabled; vendor preset: enabled)
Active: active (running) since Wed 2017-10-18 00:50:29 CEST; 20s ago
Main PID: 3651 (python3)
Tasks: 1 (limit: 4915)
CGroup: /system.slice/test.service
└─3651 /usr/bin/python3 /home/andy/Desktop/test.py > /home/andy/Desktop/test.log 2>&1
oct. 18 00:50:29 andy-G551JW systemd[1]: Started Un service de test..
oct. 18 00:50:29 andy-G551JW python3[3651]: ok
oct. 18 00:50:29 andy-G551JW python3[3651]: ok
如何在守护程序脚本中重定向输出?
【问题讨论】:
标签: python linux output daemon