Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Systemd: Start operation timed out. Terminating

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?

like image 420
Nix Avatar asked Jul 10 '17 12:07

Nix


2 Answers

Your type seems wrong, forking is for programs that detach immediately by themselves. Flask does not, it stays attached to your console.

Your service type should probably be simple

like image 139
Anthony Rossi Avatar answered Nov 08 '22 14:11

Anthony Rossi


Set a larger start timeout:

[Service]
TimeoutStartSec=300

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

like image 38
Voy Avatar answered Nov 08 '22 14:11

Voy