Skip to content

Python utility fully self-contained with defaults so you can run it in the same folder as main.py without passing any arguments. It will assume: Script name: main.py in current directory Working directory: current directory Python interpreter: system default /usr/bin/python3 Service user: current user Service name: derived from folder name

Notifications You must be signed in to change notification settings

thenik/service-systemd-create

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation


Python Systemd Service Creator

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.


Features

  • Automatically creates a systemd service for main.py or 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.

Installation

Clone this repository or download service_systemd_create.py:

git clone https://github.com/thenik/service_systemd_create.git
cd service_systemd_create

Ensure your Python script (main.py) is in the same directory.


Usage

Run the script as root or with sudo:

sudo python3 service_systemd_create.py

The utility will automatically:

  • Detect main.py in the current folder
  • Set the working directory to the current folder
  • Use /usr/bin/python3 as 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.


Check Service Status

To view the service status:

systemctl status <service-name>.service

To view real-time logs:

journalctl -u <service-name>.service -f

Advanced Configuration

  • Custom script or Python interpreter: Modify the ExecStart line 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= and RestartSec= as needed.

Benefits

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.


Keywords

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.


License

MIT License © 2025 \ Nikolai Kekish

About

Python utility fully self-contained with defaults so you can run it in the same folder as main.py without passing any arguments. It will assume: Script name: main.py in current directory Working directory: current directory Python interpreter: system default /usr/bin/python3 Service user: current user Service name: derived from folder name

Resources

Stars

Watchers

Forks

Languages