How to see the systemd service logs in Ubuntu
10,185
To view the logged stdout
and stderr
you can use journalctl command:
sudo journalctl -u [service_name]
Author by
S Andrew
I am electronics fresher. I am learning things so soon I'll start answering questions on SE and help everyone.
Updated on June 04, 2022Comments
-
S Andrew almost 2 years
I have a below service file:
[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
This
demo.service
simply calls a python codedemo.py
. When I am starting the service usingsudo systemctl start demo.service
, it always remains inauto-restart(failure)
mode.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)
I have checked
syslog
but there is no useful information in them. It just shows demo service started and demo service stopped logs.From where can I get its logs to understand why the service is not starting. Please help. Thanks
Below are the logs from
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.
-
alex_noname over 3 yearsCan you post the code of demo.py?
-
S Andrew over 3 yearsFor some reason I cannot post the code but is there anything I need to include in the code which will show some logs in journactl
-
alex_noname over 3 yearsyou can try systemd package to logging
-
-
S Andrew over 3 yearsI have updated the question with journactl logs. It doesn't seems to help. How can I check what caused service to go into inactive state.
-
alex_noname over 3 yearsYes, you can get full list by
sudo systemctl list-units --type=service