如何在Ubuntu中查看systemd服务日志

时间:2020-08-17 11:17:10

标签: python ubuntu service systemd

我有一个下面的服务文件:

[Unit]
Description=demo service
Requisite=mosquitto.service
BindsTo=mosquitto.service

[Service]
Type=simple
ExecStart=/usr/bin/python3 /home/john/Documents/source/demo.py
Restart=on-failure
RestartSec=30s
StandardOutput=null

[Install]
WantedBy=multi-user.target

demo.service仅调用python代码demo.py。当我使用sudo systemctl start demo.service启动服务时,它始终处于auto-restart(failure)模式。

demo.service - demo service
   Loaded: loaded (/etc/systemd/system/demo.service; enabled; vendor preset: enabled)
   Active: activating (auto-restart) (Result: exit-code) since Mon 2020-08-17 12:13:37 BST; 23s ago
  Process: 4744 ExecStart=/usr/bin/python3 /home/john/Documents/source/demo.py
 Main PID: 4744 (code=exited, status=1/FAILURE)

我已经检查过syslog,但是其中没有有用的信息。它仅显示演示服务已启动,演示服务已停止日志。

我可以从哪里获取其日志,以了解为什么服务未启动。请帮忙。谢谢

下面是journactl的日志:

Aug 13 13:51:40 john systemd[1]: Started demo service.
Aug 13 13:51:40 john systemd[1]: demo.service: Main process exited, code=exited, status=1/FAILURE
Aug 13 13:51:40 john systemd[1]: demo.service: Failed with result 'exit-code'.
Aug 13 13:52:10 john systemd[1]: demo.service: Service hold-off time over, scheduling restart.
Aug 13 13:52:10 john systemd[1]: demo.service: Scheduled restart job, restart counter is at 2.
Aug 13 13:52:10 john systemd[1]: Stopped demo service.

1 个答案:

答案 0 :(得分:0)

要查看已记录的stdoutstderr,可以使用journalctl命令:

sudo journalctl -u [service_name]