Systemd: Start operation timed out. Terminating
Asked Answered
D

4

19

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?

Dabbs answered 10/7, 2017 at 12:43 Comment(4)
But I saw a lot of similar questions that were not down voted... Why is that? I humbly ask for explanation. I'd like to delete this question to fix the problem, as it can not be rephrased. But I can't do this.Dabbs
Stack Overflow does a poor job of policing itself. Many off-topic questions pass without incident. Its a big disservice because its like a trap for folks who come later. If the question does not pass the high level sniff test of, is it a programming or development question, then it probably does not belong here. How to run a program as a service or how to configure systemd does not pass the sniff test. I eat my own dog food. Here's my latest systemd question on U&L.SE: Fedora 26 and fully qualified domain names?. It was asked today.Tankoos
As for Deletion and Migration... You can flag the question and ask the moderators move it so you don't have to delete it on one site and create it on another site. For whatever reasons, the Stack Exchange network does not allow you to migrate it yourself. Also see Author initiated migration to other SE sites?Tankoos
this -1 killed my reputation and I am not sure what I can do to get out of this ban.Dabbs
S
31

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

Scintillometer answered 10/7, 2017 at 12:47 Comment(1)
Well that's weird, I'm sure I tried simple and it did not work. But it does now. Well, I guess I tried it in my sleep :D Thank you.Dabbs
J
13

Set a larger start timeout:

[Service]
TimeoutStartSec=300

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

Jamilajamill answered 8/4, 2021 at 6:12 Comment(0)
B
0

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'
Bonnie answered 5/6, 2022 at 1:41 Comment(0)
D
-4

It really took me one hour to figure this out :o

Druce answered 18/11, 2022 at 18:3 Comment(2)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Vaisya
Please don't add "thank you" as an answer. Once you have sufficient reputation, you will be able to vote up questions and answers that you found helpful. - From ReviewEditorialize

© 2022 - 2025 — McMap. All rights reserved.