systemd service file generator
Your service file
Save as /etc/systemd/system/mybot.service
Install and start it
Check it with systemctl status and read its output with journalctl -u plus the service name. After editing the file, run systemctl daemon-reload and restart the service.
Tips
- Use full paths in the command. For Python, point at the virtual environment's Python so the right packages are used.
- Don't run your app as root unless it needs to. Create a user with
useradd -r -m mybot. - Keep tokens and passwords in the environment file (
chmod 600), not in the command. Restart=alwayswithRestartSec=5restarts after a crash without hammering the CPU if it keeps failing.
Step-by-step guides: run an app as a service, Telegram bot 24/7, Discord bot. More free tools: cron expression generator, all tools.