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?
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
Set a larger start timeout:
[Service]
TimeoutStartSec=300
In case your service would actually need more time to complete the startup.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With