The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →The reliable way to run a Python program continuously on Ubuntu is to create a systemd service. A unit in /etc/systemd/system/ starts the program at boot, keeps it independent of your SSH session, restarts it after unexpected failures, and sends its output to the system journal.
Antihost offers Linux VPS plans with full root access, unlimited traffic on a 1 Gbps port and a 14-day free trial.
The essential pattern is simple: run the virtual environment’s Python interpreter with an absolute path, keep the script in the foreground, run it as a restricted service account, then use systemctl and journalctl to operate and diagnose it.
As an Amazon Associate I earn from qualifying purchases.
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallWhat you will build
This guide creates a service named myscript.service for an application stored in /opt/myapp. The service account is myapp, and the Python entry point is /opt/myapp/app.py. Substitute your own names, but keep paths absolute in the unit file.
The finished service will:
- start automatically when Ubuntu reaches its normal multi-user boot target;
- start immediately when you install it;
- run without an open terminal or SSH connection;
- restart when the process exits unsuccessfully, with a five-second delay; and
- send startup messages, tracebacks, and other output to the journal.
This is intended for a long-running worker, bot, web listener, queue consumer, or similar process. A finite task that should run at a particular time is usually a better fit for a timer or cron job, not a permanently supervised service.
#1 Best Overall
- BLUE LIGHT BLOCKING GLASSES: Our blue light glasses for women boast UV400 protection, blocking harmful blue rays from computer screens. With these bluelight glasses women, you can enjoy gaming, reading, or watching TV with no worries of eye strain.
- EYE RELIEF: Our blue light glasses are engineered to reduce blurry vision or strain caused by prolonged screen time. These womens blue light glasses aid in better sleep by preventing blue light from disrupting your natural sleep cycle, helping you fall asleep faster and enjoy a more restful night's sleep, making them the perfect christmas present.
- COMFORTABLE: Crafted from durable material, our trendy blue light glasses for woman or blue light glasses men ensure long-lasting comfort. The high-transmittance lenses accessories, gamer gifts for men, help keep your eyes relaxed. Perfect stocking stuffers, gifts for gamers men, christmas gifts for men, halloween costumes.
- LIGHTWEIGHT: These clear blue light glasses feature a lightweight frame, meaning they’ll stay comfy for long-term wear. Perfect as blue blockers glasses for women or mens blue light glasses, these non-prescription fake glasses for men can be worn throughout the day. The blue light blocking glasses women feature polycarbonate HD lenses, which are anti-reflective and restore true color.
- WORRY-FREE PURCHASE: If you experience any issues, our support team is ready to assist you quickly. These are the perfect costume glasses for cosplay dressing up.
Why systemd is the right supervisor on Ubuntu
Starting a script with python app.py &, nohup, screen, or tmux can keep it alive temporarily, but those approaches do not provide the same boot integration, dependency ordering, privilege separation, restart policy, and centralized logs. Closing an SSH session, losing a terminal multiplexer, or rebooting the machine can still stop or strand the process.
Ubuntu’s service manager treats a unit file as the definition of a background task and its interaction with the operating system. It knows the process ID, records exit status, applies restart limits, and can start the unit as part of boot.
Free tools Windows power users keep installed
One-click scans. No signup required.
| Approach | Boot integration | Crash restart | Privilege isolation | Logs | Best use |
|---|---|---|---|---|---|
| systemd service | Native; enabled with systemctl |
Built in with Restart= |
Runs as a named Unix user | Integrated with journalctl |
A continuously running program on one Ubuntu host |
| cron | Scheduled invocation | Not a service supervisor | Runs as the selected cron user | Varies by cron/mail configuration | Finite jobs at fixed times or intervals |
| tmux or screen | No normal boot registration | Limited; depends on the session | Usually your interactive account | Terminal output unless redirected | Interactive work you need to reattach to |
| Docker or another container runtime | Depends on the runtime and its policy | Available, but adds another layer | Container isolation model | Runtime-dependent | When packaging and multi-process orchestration are the main concern |
| External process manager | Requires its own installation and integration | Usually available | Depends on its configuration | Manager-dependent | Applications already standardized on that manager |
For one Python process on an Ubuntu server, systemd normally has the strongest native integration and the fewest moving parts.
Prepare the application and service account
Create a dedicated account
Do not run an unattended application as root unless it genuinely needs root privileges. A dedicated account limits what a compromised or buggy process can read and change.
sudo adduser --system --group --home /opt/myapp myapp
The command creates the myapp user and group. The home path is also the application directory in this example. If the account already exists, skip this command and verify it with id myapp.
Create the directory and install files
sudo install -d -o myapp -g myapp /opt/myapp
sudo cp app.py /opt/myapp/
sudo chown -R myapp:myapp /opt/myapp
Copy your requirements file and configuration into the same tree, or grant the account access to their actual locations. The service user must be able to traverse every parent directory, read the script and its modules, read configuration and certificates, and write any directory used for state, uploads, caches, or application logs.
Create and populate a virtual environment
Use the interpreter that belongs to the application’s virtual environment. This avoids depending on whichever Python happens to be first in a non-interactive service’s PATH.
Rank #2
- WINDEX GAMING WIPES: effortlessly clean all your gaming gear and gaming electronics in one easy step with our new Windex Gaming Wipes
- AMMONIA FREE: our ammonia-free formula is safe to use on all of your favorite gaming equipment like consoles, headsets, controllers, screens, keyboards, and more
- PRE-MOISTENED WIPES: each wipe instantly removes dust, dirt, and stubborn smudges and fingerprints leaving a streak-free shine
- ANTI-STATIC: great for cleaning and wiping down your gaming gear and electronics leaving behind no visible residue
- COMPACT RESEALABLE PACKAGE: store your pack of Windex Gaming Wipes anywhere in your home for whenever a quick and easy wipedown is needed
sudo -u myapp python3 -m venv /opt/myapp/.venv
sudo -u myapp /opt/myapp/.venv/bin/pip install -r /opt/myapp/requirements.txt
If the host does not have the Python virtual-environment package installed, install the Ubuntu package appropriate to your Python version before creating the environment. Confirm the executable exists:
ls -l /opt/myapp/.venv/bin/python
That exact path is what the unit will execute. Do not rely on source .venv/bin/activate; activation changes an interactive shell and is not required when the absolute interpreter path is used.
Write the systemd unit
Create /etc/systemd/system/myscript.service as root:
[Unit]
Description=My Python background service
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
User=myapp
WorkingDirectory=/opt/myapp
ExecStart=/opt/myapp/.venv/bin/python /opt/myapp/app.py
Restart=on-failure
RestartSec=5
Environment=PYTHONUNBUFFERED=1
[Install]
WantedBy=multi-user.target
For example, open the file with sudo nano /etc/systemd/system/myscript.service, paste the contents, save it, and exit. Unit filenames are case-sensitive; the filename determines the name used in every systemctl command.
How the unit directives work
[Unit]: identifies the service and expresses ordering relationships.After=network-online.targetstarts this unit after that target has been reached, whileWants=network-online.targetasks systemd to bring the target in as part of the transaction.Type=simple: tells systemd that the process launched byExecStartis the service. Keep the Python program in the foreground so systemd can supervise its lifetime. Do not append&or daemonize it yourself.User=myapp: drops the service to the dedicated account. File ownership and directory permissions must match this choice.WorkingDirectory=/opt/myapp: gives the process a predictable current directory. Relative paths in application code are still less robust than absolute paths, but this setting prevents a common difference between an SSH shell and a service.ExecStart=: invokes the intended Python executable directly and passes the script as an argument. Use absolute paths for the interpreter, script, and any executable you call.Restart=on-failure: asks systemd to restart the process after an unsuccessful exit or signal. This is the recommended policy for a long-running service; a clean exit is not treated as a crash that must be hidden.RestartSec=5: waits five seconds before a restart, which avoids an immediate, resource-consuming restart loop while still recovering quickly.Environment=PYTHONUNBUFFERED=1: makes Python flush standard output and error promptly, so messages appear in the journal without the delays that buffered output can cause.[Install]andWantedBy=multi-user.target: define the boot target used when you enable the service.
Systemd command lines are not shell command lines. Shell redirection, pipelines, command substitution, and background operators are not interpreted in ExecStart. If your application needs a pipeline, implement it in Python or explicitly invoke a shell with a carefully quoted command; direct execution is safer and easier to diagnose.
Load, enable, and start the service
- Ask systemd to reread unit files:
sudo systemctl daemon-reload - Enable the unit for future boots and start it now:
sudo systemctl enable --now myscript.serviceThe
--nowoption combines boot activation with an immediate start. - Check its current state and the most recent status details:
sudo systemctl status myscript.service - Follow live output from the service:
sudo journalctl -u myscript.service -f
A healthy long-running service normally shows active (running). Press Ctrl+C to leave a live journal view; doing so does not stop the service.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Scan for outdated or missing drivers - takes under a minute3Repair Windows errors before they cause bigger problemsRank #3
- Ergonomic & Adjustable Design: Fight "text neck" and improve your posture. Designed for comfort, it offers an adjustable height (7.1in-8.5in) (1.4in adjustable range) and angle (5°-85°) Please note: cell phone stand is only 9 inches tall—the length of a standard pencil
- Without blocking subtitles Perfect for office desk Tiktok Face Time Zoom video—this is the ultimate kitchen desk essential for phones! Perfect viewing experience while reducing neck back strain, A must-have for gamers streamers desk, and anyone who values both style and support!
- Sleek & Stable Design fits Otterbox Case: Say goodbye to bent cables, tangles, and tip-overs! LISEN’s stylish adjustable desk phone holder features a built-in charging hole and smart cable management, keeping your phone secure and your workspace clutter-free cool gadgets for men
- ANTI-SLIP DESIGN free hands: The under 10.00 items easy gadgets back and the bottom of this kitchen essentials for women are fully covered by anti-skid silicone, which LISEN stand up desk decor can provide maximum protection device from any scratches and slides
- Your Perfect Viewing Companion:If your product arrives damaged or breaks within 365 days, reach out to LISEN for a quick and hassle-free solution. Struggling with assembly, like tightening the screw? We’ve got your back! Your experience matters to us. (Product including: phone Holder stand*1, screw*1, hexagon screwdriver*1, specification*1)
Inspect the effective unit
When a unit behaves differently from the file you remember editing, display the definition systemd is using:
systemctl cat myscript.service
This is particularly useful when a similarly named unit exists in another location or when an edit was made without a subsequent daemon reload.
Operate the service day to day
| Task | Command | What it does |
|---|---|---|
| Start now | sudo systemctl start myscript.service |
Launches the unit without changing boot enablement |
| Stop now | sudo systemctl stop myscript.service |
Requests a clean stop |
| Restart after code or configuration changes | sudo systemctl restart myscript.service |
Stops and starts the process again |
| Enable at boot | sudo systemctl enable myscript.service |
Creates the boot-time dependency |
| Disable at boot | sudo systemctl disable myscript.service |
Removes boot activation; it does not necessarily stop a running process |
| See recent boot’s failures | sudo journalctl -u myscript.service -b --no-pager |
Shows this boot’s journal entries and exits without a pager |
| Follow new log entries | sudo journalctl -u myscript.service -f |
Streams new output until you leave the view |
After changing the unit file itself, always run sudo systemctl daemon-reload before sudo systemctl restart myscript.service. A Python-only code change usually needs the restart but not a daemon reload.
Make the application service-friendly
Remove interactive assumptions
A program launched from SSH may inherit your shell’s PATH, aliases, current directory, activated virtual environment, display variables, credentials, and terminal input. A system service has none of those assumptions unless you define them. Use explicit paths, read configuration from a known location, and ensure startup never waits for a question typed at a terminal.
Recommended Free Tools
Handle signals and shutdown
Let the main Python process remain the process started by ExecStart. Avoid forking into the background. A foreground process receives systemd’s stop request directly, allowing normal cleanup of sockets, files, and worker threads.
Write useful logs
Send diagnostic messages and tracebacks to standard output or standard error so they are visible through the journal. PYTHONUNBUFFERED=1 helps short-lived messages appear promptly. Do not assume that a file opened by your SSH account is writable by myapp; create application-owned directories and check their permissions explicitly.
Network-dependent startup
The network ordering directives delay startup until the network-online.target transaction completes, but they do not prove that a remote database, API, or game server is accepting connections. Your Python code should implement connection retries and backoff for remote dependencies. Ordering is not a readiness check for another application.
Rank #4
- Easy Installation: Our gaming lights have been designed to enhance your entertainment experience. Simply position the led light bar next to your TV or game console to create a game room environment with ease. They come with USB power and a 60 inch cord for direct mounting and mobility
- Audio Syncing & Extensive Mode: The built-in high-sensitivity music sensor allows you to sync the TV led lights to your favorite music. Lights react and move to the beat of music, film and game audio, creating an incredible immersive sound and light experience – and all without the need for an additional hub. You can choose from 64+ patterns, including strobe, illusion, jump, energy, gradient, running, chasing, fluttering mode etc. Each mode can be applied to different scenes
- 64+ Chasing IC+RGB & W Effect: The independent control design of IC+RGB and white all-in-one multifunctional rgbw led bar lights monitor backlight allows you to easily switch the led lights for desk between IC+RGB and white to enjoy a variety of lighting effects, you can choose white lighting mode with high brightness for better illumination when working, etc. Choose IC+RGB lighting mode when you need to create an entertaining atmosphere for the light show, 16 million colours of Color changing rgb light bar let you dance to the beat and create a dynamic party atmosphere
- Dynamic and Dimmable Lights: 1%-full brightness free brightness adjustment gives you the flexibility to adjust dimmable led light bar for room decorations or a variety of occasions
- USB Powered: USB light bars for room can be powered by powernank, usb charger, TV, Monitor, laptop PC mainframe, making behind TV led lighting bar easy to install in any location.TV led lights are powered by the TV usb interface / PC mainframe, can be turned on/off synchronously with TV / PC
Keep the script running after SSH disconnects
Once the unit is enabled and started, the SSH session is no longer part of the process’s lifetime. You can log out, close the terminal, or lose the connection; systemd continues to own the service. This is the important difference from launching the script directly in a shell or leaving it inside an interactive multiplexer session.
If you only need a one-time interactive run and do not want a persistent boot service, a multiplexer or nohup may be adequate. They are not substitutes for the unit above when you need automatic boot startup, crash recovery, structured status, and journal logs.
Automatic recovery and start-rate limits
Restart=on-failure handles ordinary unexpected exits, but it cannot repair the exception that caused the exit. If the program fails immediately every time, systemd eventually applies its start-rate limit using StartLimitIntervalSec and StartLimitBurst. The unit then appears failed instead of being restarted indefinitely.
First fix the application or environment problem. Afterward, clear the recorded failed-start counter if necessary:
sudo systemctl reset-failed myscript.service
sudo systemctl start myscript.service
Do not replace on-failure with Restart=always merely to hide a persistent bug. A clean exit may represent a deliberate shutdown, and an unconditional policy can turn a configuration error into a noisy restart loop.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →Troubleshoot by symptom
203/EXEC or “command not found”
- Check that the interpreter exists:
ls -l /opt/myapp/.venv/bin/python. - Verify every component of
ExecStartis an absolute path. - Confirm the target filesystem is mounted and accessible at boot.
- Display the loaded unit with
systemctl cat myscript.service, then reload systemd after corrections.
Permission denied
- Confirm the service account can read
app.pyand imported modules. - Check that it can enter
/opt/myappand every parent directory. - Check read access to configuration, certificates, sockets, and data files.
- Check write access to every directory where the program stores state or logs.
Run namei -l /opt/myapp/app.py when you need to inspect permissions on each directory component.
It works in SSH but fails as a service
Compare the two environments rather than adding random delays. Look for a missing virtual-environment activation, a shell-only alias, a relative path, an unset variable, a display requirement, a credential available only in your login shell, or a prompt waiting for input. Put required values in a deliberate configuration mechanism and use the same absolute command in both tests.
Best Value
- Compatible with Wide Screens - To ensure compatibility with the dual monitor mount, your each monitor must meet three conditions at the same time: First, computer screens size range: 13 to 32 inches. Second, screen weight range: 4.4 to 19.8 lbs. Third, the back of the monitor screen must have VESA mounting holes with a pitch of 75x75mm or 100x100mm.
- Regarding the compatibility with desks - Your desk must meet three conditions at the same time: First, desk material: Only wooden desks are recommended, plastic or glass desks cannot be used. Second, desk thickness range: 0.59" - 3.54". Third, the bottom of the desk should not have any cross beams or panels, as this will interfere with installation. We recommend carefully checking that your desk and monitors meets all above conditions before purchasing.
- Dual C-Clamp Hold - Worried your dual monitors might wobble or slip? Our upgraded base uses a larger platform plus a dual C-clamp structure to lock the dual monitor arm firmly to your desk. Each arm safely keeps your screens steady while you type, click and game—no shaking, no sliding, just a clean and secure setup you can trust every day. It also provides Grommet Mounting installation choice, both options ensure stable and secure fixation for your 0.59" - 3.54" desk.
- Full-Motion Adjustment For Comfortable View - Pull the screen closer when you’re deep in a spreadsheet, push it back to watch videos, or rotate to portrait for coding — moving everything smoothly with just one hand. The monitor stand offers +85°/-50° tilt, ±90° swivel and 360° rotation. Raise your monitor up to 15.75″ to support a healthy sitting posture. Whether you’re working from home, gaming through the night, or switching between video calls and documents, getting the screens to your natural line of sight helps relieve neck, shoulder and back strain so you can stay focused longer with less fatigue.
- Keep Your Desk Organized: By lifting both screens off the desktop, this dual monitor stand opens up valuable space for your keyboard, notebook, docking station or a simple, clutter-free work area. Built-in cable management guides wires along the arms, keeping cords out of sight and out of the way. Enjoy a tidy, modern workstation that looks as good as it feels to use.
The process starts and immediately exits
Read the Python traceback:
sudo journalctl -u myscript.service -b --no-pager
Then run the exact command as the service user with the intended working directory:
sudo -u myapp sh -c 'cd /opt/myapp && exec /opt/myapp/.venv/bin/python /opt/myapp/app.py'
This reproduces the account and directory context without involving systemd’s restart policy. Fix the exception, missing file, or configuration error shown by the traceback.
Constant restart loop
Inspect the journal for the first failure, not only the later “scheduled restart” messages. Correct the underlying exception, verify the command manually as myapp, then reset the start-limit counter if it has been exceeded. A restart directive is recovery logic, not a replacement for application error handling.
The service starts before its remote dependency is usable
Keep the network ordering directives, but add retry logic in Python. If the remote service becomes available after boot, the application must be able to reconnect without requiring a manual restart.
Updating code, dependencies, and the unit safely
- Copy or deploy the new files with ownership that allows
myappto read them. - Install changed dependencies into the same virtual environment, for example with
sudo -u myapp /opt/myapp/.venv/bin/pip install -r /opt/myapp/requirements.txt. - Run a foreground test as the service account if the change is substantial.
- If the unit file changed, run
sudo systemctl daemon-reload. - Restart the service:
sudo systemctl restart myscript.service. - Immediately inspect
sudo systemctl status myscript.serviceand followsudo journalctl -u myscript.service -f.
Keeping deployment and runtime ownership consistent prevents a common failure where an administrator can edit a file but the service account cannot read it. If you replace the virtual environment, verify the interpreter path before restarting.
Useful checks before calling the setup complete
- Boot test: confirm
systemctl is-enabled myscript.servicereports that it is enabled, then verify the service after a controlled reboot. - Crash test: stop or terminate the test process in a maintenance window and watch whether systemd starts it again after the configured delay.
- Log test: produce a known startup message and locate it with
journalctl -u myscript.service. - Privilege test: verify the service cannot write outside the directories it actually needs.
- Configuration test: start the program without your login shell and confirm all required settings are supplied explicitly.
- Dependency test: temporarily make the remote dependency unavailable and confirm the Python code retries rather than exits permanently.
When a different tool is a better fit
Use cron for scheduled finite work
A report, cleanup script, or one-off import that should run every hour or every night is a scheduled job, not a daemon. Cron expresses “run at this time”; systemd services express “keep this process supervised.”
Use a container when packaging is the central problem
If you need an immutable image, multiple cooperating processes, or deployment across many hosts, a container platform may be appropriate. That choice adds image, volume, networking, and runtime operations that are unnecessary for one Python process on one Ubuntu machine.
Use an external process manager when your platform already standardizes on it
Some organizations operate every application through a separate supervisor. In that case, follow the platform’s conventions, but avoid running two independent supervisors for the same process; competing restart policies make ownership and diagnosis confusing.
Final checklist
- The script and virtual environment are in a stable absolute location.
- A dedicated account owns or can read the application files.
ExecStartcalls the intended interpreter directly.- The process stays in the foreground with
Type=simple. - The service has a predictable working directory and explicit configuration.
Restart=on-failureand a delay are configured for unexpected exits.- You ran
daemon-reloadafter editing the unit. enable --nowsucceeded and status reports the expected state.- You know how to read the unit’s journal and reset a start-rate failure.
- The Python program retries remote connections and does not depend on an SSH shell.
With those conditions met, systemd provides the durable background execution, boot startup, supervision, and diagnostics that an Ubuntu Python service needs.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.




