4

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 code demo.py. When I am starting the service using sudo systemctl start demo.service, it always remains in auto-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.
S Andrew
  • 5,592
  • 27
  • 115
  • 237

2 Answers2

12

To view the logged stdout and stderr you can use journalctl command:

sudo journalctl -u [service_name]
alex_noname
  • 26,459
  • 5
  • 69
  • 86
8
sudo journalctl -u [service_name] -e 

the -e option at end jumps to end of the logfile to see most recent logs.

CodingMatters
  • 1,275
  • 16
  • 26