Systemd: Start operation timed out. Terminating

Viewed 19235

I'm trying to create an autostart service for my python-flask-socketio server.

I need to start a python script through systemd. Here's my service code:

[Unit]
Description=AppName


[Service]
Type=forking
ExecStart=/usr/bin/python3 /opt/myapp/app.py

[Install]
WantedBy=multi-user.target

If I try to start it manually using sudo service myservice start - it works just fine. It halts my terminal\ssh window but I can close it and it works like expected.

But when I reboot my PC it does not start. When checking it's status with systemctl status myservice I get the following:

systemd[1]: Starting My Service...
systemd[1]: myserivce.service: Start operation timed out. Terminating.
systemd[1]: Failed to start My Service.
systemd[1]: myserivce.service: Unit entered failed state.
systemd[1]: myserivce.service: Failed with result 'timeout'.

What am I doing wrong here?

3 Answers

Set a larger start timeout:

[Service]
TimeoutStartSec=300

In case your service would actually need more time to complete the startup.

You have to check /var/log/message.

After you start service, If your script works normally at first and then failed, try this.

ExecStart=/usr/bin/bash -c '/usr/bin/python3 /opt/myapp/app.py'
Related