Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Clear out junk files and repair common Windows errors3Scan for outdated or missing drivers - takes under a minuteiTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more
Antihost offers Linux VPS plans with full root access, unlimited traffic on a 1 Gbps port and a 14-day free trial.
The durable way to run a Python script in the background on Ubuntu is to create a native systemd service. Store a unit file in /etc/systemd/system/, call the virtual environment’s Python interpreter with absolute paths, run the process as a dedicated user, and let systemd start, monitor, log, and restart it.
This approach survives SSH disconnects, starts the script at boot, and can recover from unexpected exits. The procedure below uses a service named myscript.service and an application installed in /opt/myapp.
Why systemd is the right supervisor
Closing an SSH session does not stop a systemd service. Unlike a command launched with &, nohup, tmux, or screen, a service has a defined lifecycle that Ubuntu can manage at boot and during failures.
A unit can express startup ordering, the account that owns the process, its working directory, the exact executable to run, restart behavior, and where output should be collected. For a single always-on Python process on one Ubuntu host, systemd is integrated into the operating system and avoids adding another supervisor.
#1 Best Overall
- Powerful Turbo Fan:CAGIWIRU Electric Air Duster have reached speed up to 130000RPM,Can efficient remove dust and debris.With LED light and Three Adjustable Speed to meet with different cleaning tasks.
- With Attached USB C Fasting Charging cable.Charing 3 hours,Enjoy up to 240 minutes of use on the lowest setting, For third speed can use for 25mins.with four charging options to meet with your needs.
- Wide Application:Upgraded attached 5 different nozzles,making it suitable for a variety of scenes, such as car,pet, pc, keyboards, and other electronic devices. It also serves for office and home clean duster.
- Handy Design & Portable:Cordless air duster electric nozzle is Light weight and small size, design and comfortable to hold and space saving, convenient to carry around. You can put it in your room or inside the car without taking up space.
- Warranty & Support: Our Electric air duster comes with 5 years warranty and 24/7 customer service. During this period, if you have any questions,pls kindly feel free to contact us.
Use a different mechanism when the job is fundamentally different:
- Use cron for scheduled, finite tasks such as a script that runs every hour and exits.
- Use tmux or screen for an interactive session that you intend to reattach to manually, not for a production daemon.
- Use a container runtime when image packaging, isolation, or multi-service deployment is the main requirement.
- Use an external process manager when your platform already standardizes on one for several application processes.
Prepare the Python application
Choose a stable application directory
Keep the script and its virtual environment in a location that will not change between boots. This example uses:
/opt/myapp/app.py
/opt/myapp/.venv/bin/python
Do not rely on the directory from which you happen to start an SSH session. A service does not inherit your interactive shell’s current directory.
Create a least-privilege service account
Run the process as a dedicated account such as myapp, rather than as root, unless the application genuinely needs privileged operations. The account must be able to enter /opt/myapp, read the script and configuration, and write any directories used for data, sockets, uploads, or application logs.
Create the application directory and assign ownership before starting the unit:
sudo install -d -o myapp -g myapp /opt/myapp
sudo cp app.py /opt/myapp/
If the account does not yet exist, create it with your distribution’s normal system-user procedure, then grant it only the filesystem access the application needs. Test the permissions before blaming systemd for an application failure.
Free tools Windows power users keep installed
One-click scans. No signup required.
Rank #2
- Screen Cleaner is Your Screen’s New Bestfriend! - EVEO is proud to present a screen cleaner that’s perfectly suited for your TV. Meet your new screen cleaner, computer screen cleaner, laptop cleaner, iPad cleaner, Macbook,tv cleaner or any other electronic device. Our screen cleaner spray and wipe along with the included plush microfiber cloth, easily removes dust, fingerprints & other smudges on the screen’s surface. Clean effectively for a streak-free screen
- Gentle on your Screens - Our screen cleaner spray and wipes is compatible to be used even for the most sensitive LCD, LED, CRT, and OLED screens in proper use. Be at ease knowing that this product is compatible with all the major brands: LG, SONY, Samsung, Sharp, iPad, iPhone, Android screens, Kindle, PC monitors - we’ve got you covered! Can be used as LCD screen cleaner, tv cleaner, smart tv screen cleaner, and more
- Premium Super Soft Plush Microfiber Cloth - Included in this efficient screen cleaning kit. This screen cleaner spray and wipe has our signature plush microfiber cloth specially designed to comply with screens and monitors and leave them streak-free. Has been shown to effectively absorbs stubborn stains, zero streaks, and no fiber shedding. Always use this together with our screen cleaner for the best results
- Easy-to-Use Screen Cleaner Kit + microfiber cleaning cloth - The EVEO Screen Cleaning Kit will easily be your new favorite tool when it comes to taking care of the things you love most, quick and easy solution for a streak-free screen. Simply screw on the sprayer gun on the screen cleaner bottle. Spray the cleaning liquid onto the microfiber cloth, then wipe the screen until desired cleanliness & shine is achieved.
- Quality Screen Care Kit Worth Purchasing - Enjoy a convenient Screen Cleaner anytime, anywhere you need it. Your satisfaction is our top priority. We stand behind the quality of our products and that’s why, you shouldn’t be worrying at all. We manufacture the Best Screen Cleaner. and can be used for laptop cleaning kit, laptop screen cleaner, tv screen cleaner for smart tv. MacBook screen cleaner, monitor cleaner or screen cleaner spray for electronic devices with microfiber cleaning cloth
Test the exact command manually
From the application directory, run the same interpreter and script that the service will use:
sudo -u myapp /opt/myapp/.venv/bin/python /opt/myapp/app.py
Stop it after confirming that it starts. This catches missing packages, import errors, bad configuration, and permission problems before they are hidden behind a service status. If the script expects environment variables, provide them explicitly during this test.
Create the systemd unit
Create /etc/systemd/system/myscript.service with this content:
[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
Save the file as root, for example with an editor opened using sudo. The filename must end in .service; systemd will use the filename as the unit name.
The [Unit] section
Descriptionis the human-readable name shown by status tools.After=network-online.targetorders startup after that target. It does not prove that a remote database, API, or other application is ready.Wants=network-online.targetasks systemd to bring the target into the transaction. Your Python code should still implement connection retries and sensible timeouts.
The [Service] section
Type=simplekeeps the Python process in the foreground so systemd can supervise it. Do not daemonize the script itself.User=myappdrops privileges to the dedicated account.WorkingDirectory=/opt/myappmakes relative paths resolve from a known location. It does not make the script’s path relative; keepExecStartabsolute.ExecStartdirectly invokes the intended interpreter and script. Use the virtual environment’s absolute interpreter rather than trying to runsource .venv/bin/activate.Restart=on-failureasks systemd to restart the process after an unexpected failure, while allowing a deliberate clean exit to remain stopped.RestartSec=5waits five seconds between attempts instead of creating an immediate restart loop.Environment=PYTHONUNBUFFERED=1makes Python flush standard output promptly, which is useful when watching logs through journald.
The [Install] section
WantedBy=multi-user.target makes the service eligible for normal multi-user boot when you enable it. Enabling alone does not start a currently stopped unit; enable --now performs both actions.
Load, enable, and start the service
- Ask systemd to reread unit files:
sudo systemctl daemon-reload
- Enable the service for future boots and start it immediately:
sudo systemctl enable --now myscript.service
- Check whether it is active:
sudo systemctl status myscript.service
A healthy long-running process normally shows Active: active (running). The status output also shows the main process ID, the command systemd launched, and recent log lines.
Rank #3
- 【Large size】:Measuring 800 x 300 mm/ 31. 5×12 inches, which is wider and taller than others. Large mouse pad can perfectly fit your keyboard and mouse of any size, and there is also ample space for peripherals such as phones, tablets, etc.
- 【LED backlight mouse pad】:Blade Hawks RGB mouse pad provides 7 static modes and 7 dynamic modes will give you the options you are looking for. Power-off memory function remembers the last lighting mode you selected. The super glow fiber Chroma will give you a colorful gaming setup that you want.
- 【Anti-slip rubber base】:Made from Natural rubber, this gaming mousepad will firmly grip your desktop, allowing you to enjoy the ultimate precision in the games you are most passionate about. It also comes with a texture that enhances this ability even further.
- 【Smooth and waterproof surface】: Micro-textured cloth surface, for extremely precise mouse control and a smooth movement. When liquid splashes on the gaming mouse pad, it forms water droplets and slides down. Will not delay your work or gameplay.
- 【Plug and play】: This mouse and keyboard pad is powered by USB, plug and play, no driver required. One button control light modes. Press one time to change the lighting mode, press twice to change the brightness, press and hold about 3 seconds turn ON/OFF.
- Follow live output:
sudo journalctl -u myscript.service -f
Press Ctrl+C to leave the log view; that does not stop the service.
Operate the service day to day
Use explicit systemctl actions rather than killing the Python process manually:
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 minutePC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11| Task | Command | Effect |
|---|---|---|
| Start now | sudo systemctl start myscript.service |
Starts the unit without changing boot enablement. |
| Stop now | sudo systemctl stop myscript.service |
Stops the managed process. |
| Restart after a code change | sudo systemctl restart myscript.service |
Stops and starts the unit again. |
| Prevent boot start | sudo systemctl disable myscript.service |
Removes boot activation; it does not necessarily stop a currently running service. |
| See the unit exactly as loaded | systemctl cat myscript.service |
Displays the unit file and any drop-in configuration. |
| Show failures from this boot | journalctl -u myscript.service -b --no-pager |
Prints the service’s current-boot log without opening a pager. |
After changing the unit file itself, always run sudo systemctl daemon-reload before restarting. A Python source edit normally needs only sudo systemctl restart myscript.service.
Make paths, configuration, and output predictable
Use absolute paths everywhere important
System services do not receive the same PATH, aliases, shell startup files, display variables, or activated virtual environment as your SSH shell. Absolute paths in WorkingDirectory and ExecStart remove the most common source of “works over SSH, fails as a service” behavior.
If the application launches a helper executable, reference its absolute path too. If it reads a file, either use an absolute filename or confirm that the path is intentionally relative to WorkingDirectory.
Provide non-interactive configuration
A boot service cannot answer an interactive prompt. Supply required settings through the unit’s environment, a configuration file with appropriate permissions, or another non-interactive mechanism supported by the application. Never assume that variables exported in your personal shell are available to myapp.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Rank #4
- 【Softer and More Comfortable】Vaydeer wrist rest has unique diamond pattern, which is the combination of softness and aesthetics. The materials of wrist rest are improved into higher quality memory foam and covered with silky smooth lycra. The computer wrist rest makes you as comfortable and cushiony as like rest your wrists on clouds.
- 【Ergonomic Wrist Saver】The wrist rests for keyboard and mouse comes with a 17.32×3.15×0.83 inch keyboard wrist pad and a 5.94×3.15×0.83 inch mouse wrist support. Based on ergonomic design, the unique concave shape is the perfect fit for your wrist joints. The wrist rest pad fits most computer keyboards and laptops, improve hand and wrist posture, release your wrist and arm stress.
- 【Non-Slip Rubber Bottom】Featuring an anti-skid silicone base on the bottom, this wrist keyboard support stays firmly in place on your desk, preventing the padding from sliding around, ensuring stable and consistent wrist support during extended computer sessions.
- 【Better Experience & Pain Relief】Our keyboard arm rest is beneficial to alleviate the soreness caused by direct contact and friction between your arm and a hard desk surface, reducing the risk of wrist fatigue or carpal tunnel. The soft texture of memory foam can evenly distribute the pressure around your wrists and provide good support with just enough give.
- 【Helpful in Multiple Scenarios】Whether you're working, studying, writing, typing, gaming, this keyboard and mouse rest combo is an essential accessory to add comfort and support to your hands and wrists. It’s also a great gift for men, women, family, friend, coworker, gamer, teacher, etc.
Use journald for first-line diagnostics
Anything written to standard output or standard error is available through journalctl -u myscript.service. Keep Python output unbuffered when prompt visibility matters. If the application requires separate persistent log files, create the directory in advance and grant myapp write access; otherwise a permission error can make the service exit during startup.
Understand restart behavior and start limits
Restart=on-failure is intended for a long-running service that should recover from an unexpected exception or process crash. It is not a substitute for fixing a deterministic startup error. If the script immediately fails on every attempt, systemd eventually applies its start-rate limits, commonly described by StartLimitIntervalSec and StartLimitBurst.
After correcting the underlying problem, inspect the traceback, then clear the failed-start counter if necessary:
sudo systemctl reset-failed myscript.service
sudo systemctl restart myscript.service
Avoid switching blindly to Restart=always. That setting also restarts after a clean exit and can hide a program that is terminating intentionally. Choose restart behavior that matches whether a normal exit means success, completion, or a defect.
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Troubleshoot common failures
203/EXEC or “command not found”
Systemd could not execute the first item in ExecStart. Verify that the interpreter exists and is executable:
ls -l /opt/myapp/.venv/bin/python
Check every directory component and use an absolute path. Do not put shell syntax, pipes, redirection, or a trailing background operator in ExecStart; systemd command lines are not interpreted as an interactive shell command.
Best Value
- 【No Drill Mounted】Cable management tray can be assembled in as little as 3 minutes or less-simply. Side clips easily clampe the edge of desk, pass through the holes on the sides, and secure excess cables with baskets. Desk cable management supports inward or outward installation to meet your needs in different scenarios, and provides you with great convenience when collecting and organizing wires.
- 【Rubber Pad Protects Desk】Wire organizer under desk built-in soft rubber pads on the clamp protect your desk from scratches, so you will not damage your furniture or office.
- 【Sturdy and Beautiful】Cord management under desk is made of high-quality carbon steel and holds about 15 lbs. The wire basket has 2 holes on each side of the tray to enable your cables to pass freely. Cable baskets are suitable for desk thickness use from 0.4" to 2.4".
- 【Space Saving & Keep Organized】Desk cable management tray holds all your power cords, outlet strips, USB hubs and computer transformers hidden from your feet, and the data cables will not enter the vacuum cleaner to keep your desk clean and tidy. Desk wire organizer is also suitable for use in the kitchen and outdoors.
- 【Reduce Safety Risks】Cable tray under desk keeps all plugs away from your kids, no more worry about tripping. Using 2 holes wire tray saves extra space, helps you easily cabling and wire protection. The mesh design is not easy to accumulate dust, but avoids safety accidents caused by messy wires.
Permission denied
Confirm that myapp can traverse /opt and /opt/myapp, read app.py and its configuration, execute the virtual-environment interpreter, and write every required data or log directory. Test with the exact service account:
sudo -u myapp /opt/myapp/.venv/bin/python /opt/myapp/app.py
Do not solve a narrow permission problem by running the whole service as root.
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →The script works in SSH but fails as a service
Compare the service environment with your shell. Typical differences are the current directory, PATH, activated virtual environments, aliases, display variables, credentials, and interactive prompts. Replace implicit assumptions with explicit paths and configuration, then read the Python traceback:
sudo journalctl -u myscript.service -b --no-pager
The service starts and exits immediately
Run the exact ExecStart command as myapp outside systemd and inspect the current-boot journal. A clean exit may be correct for a finite task, but a daemon that should stay alive usually indicates an exception, missing configuration, or code that does not contain a persistent main loop.
The service constantly restarts
Read the first traceback rather than treating the restart as the problem. Fix the exception, missing file, connection failure, or permission issue. If systemd has stopped trying because of its start-rate limit, run systemctl reset-failed after the fix and start the unit again. A five-second delay limits the speed of the loop but cannot repair the cause.
Network-dependent startup fails
After=network-online.target controls ordering only. It does not guarantee that a remote database, DNS-dependent endpoint, or other application is accepting connections. Add retry and backoff logic to the Python program, and make failed connections produce useful log messages.
Compare systemd with other ways to keep Python running
| Method | Boot integration | Crash restart | Dependency ordering | Privilege isolation | Logs | Best fit |
|---|---|---|---|---|---|---|
| systemd | Native enablement | Built in with restart policies | Unit relationships and targets | Runs as a specified user | journald by default | Always-on service on one Ubuntu host |
| cron | Scheduled invocation | Not a service supervisor | Limited | Runs as a selected account | Mail or redirected output | Finite jobs on a schedule |
| tmux or screen | Manual session management | Not automatic application recovery | None | Uses the session account | Terminal output | Interactive administration and debugging |
| Container runtime | Depends on the runtime and host setup | Usually available through runtime policies | Strong in multi-service deployments | Container and host controls | Runtime-managed logs | Reproducible packaging or orchestration |
| External process manager | Depends on its integration | Usually available | Depends on the manager | Depends on configuration | Manager-specific | Hosts already standardized on that manager |
For this title’s use case—one Python process that should start at Ubuntu boot, stay detached from SSH, and restart after a crash—systemd has the strongest native integration and the fewest moving parts.
Security and maintenance checklist
- Run under a dedicated unprivileged account such as
myapp. - Keep the virtual environment and application in a stable directory with controlled ownership.
- Use absolute interpreter and script paths.
- Grant write permission only to directories the application must modify.
- Do not place secrets directly in a world-readable unit file; restrict configuration-file permissions and avoid exposing credentials in process arguments.
- Review the unit with
systemctl cat myscript.serviceafter edits. - After unit changes, reload systemd before restarting.
- Check logs after deployment and after every unexpected restart.
- Make network clients retry safely instead of assuming that boot ordering means service readiness.
- Keep the Python application itself non-daemonized so systemd can observe its real exit status.
A repeatable deployment sequence
For a new host, this sequence keeps installation and diagnosis deterministic:
- Create the
myappaccount and/opt/myappdirectory. - Copy the script, virtual environment, and configuration into that directory.
- Run the exact interpreter command as
myappuntil it succeeds without an SSH-only dependency. - Write
/etc/systemd/system/myscript.serviceusing the unit shown above. - Run
sudo systemctl daemon-reload. - Run
sudo systemctl enable --now myscript.service. - Check
sudo systemctl status myscript.service. - Follow
sudo journalctl -u myscript.service -fand confirm that startup output and application behavior are correct. - Simulate a controlled restart with
sudo systemctl restart myscript.service, then verify that the process returns to an active state.
Bottom line
Use a systemd unit with Type=simple, an absolute virtual-environment interpreter, a dedicated service user, and Restart=on-failure. Enable it with systemctl enable --now, use systemctl status for state, and use journalctl -u for Python tracebacks. That gives Ubuntu a supervised background process that starts at boot, survives SSH disconnects, and can recover from unexpected crashes.
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.
Recommended Free Tools

