2017-10-17 5 views
0

動作しません。私はこのようなPythonスクリプトがあります。Linuxの出力リダイレクトデーモンが

while True: 
    print("ok") 

を私はデーモンtest.service作成します。sudoと

[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 

そして私アクティブそれをテストを開始systemctl。サービス。 ログファイルが作成されていません:出力リダイレクトが機能していません。

私はsystemctlステータス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 

+0

[python-daemonとstdout]の可能な複製(https://stackoverflow.com/questions/11146128/python-daemon-and-stdout) – jww

答えて

1

出力をリダイレクトしないでください。スクリプトを標準出力にします。 Systemdはその出力をsystemdジャーナルに保存します。このジャーナルはjournalctl -u testまたはsystemctl status testで表示できます。

+0

しばらくして2分だけ "ok" OK")。それは普通ですか? – Andy

関連する問題