Automatically create and manage a systemd service for any Python script on Ubuntu / Linux. This utility simplifies running your Python scripts as background services with automatic restart and logging.
- Automatically creates a systemd service for
main.pyor any Python script. - Sets up working directory, service name, and user automatically.
- Supports automatic restart on failure.
- Uses journal logging for easy debugging.
- Simple, one-command setup with no manual systemd configuration.
- Compatible with Ubuntu and modern Linux distributions.
Clone this repository or download service_systemd_create.py:
git clone https://github.com/thenik/service_systemd_create.git
cd service_systemd_createEnsure your Python script (main.py) is in the same directory.
Run the script as root or with sudo:
sudo python3 service_systemd_create.pyThe utility will automatically:
- Detect
main.pyin the current folder - Set the working directory to the current folder
- Use
/usr/bin/python3as the Python interpreter - Name the service after the current folder
- Set the current user as the service user
Once completed, your script will run as a systemd service and start automatically at boot.
To view the service status:
systemctl status <service-name>.serviceTo view real-time logs:
journalctl -u <service-name>.service -f- Custom script or Python interpreter: Modify the
ExecStartline in/etc/systemd/system/<service-name>.service. - Environment variables: Add them via
Environment=lines in the[Service]section or use an environment file. - Restart policies: Adjust
Restart=andRestartSec=as needed.
Running your Python scripts as systemd services ensures:
- Reliable background execution
- Automatic recovery from crashes
- Centralized logging via systemd journal
- Easy management with standard Linux tools
Perfect for automation scripts, web crawlers, background tasks, or any long-running Python application on Ubuntu.
Python systemd service, Ubuntu Python service, auto-start Python script, run Python script in background, systemd Python tutorial, Python background service Linux, Python service setup Ubuntu.
MIT License © 2025 \ Nikolai Kekish