Running a Python script on your laptop means it dies when you close the lid. Running it in a screen session is better but still fragile. The right way is systemd โ the Linux init system that was built for exactly this: keeping processes alive.
What we're setting up
We'll take any Python script โ a price tracker, a data scraper, a notification bot, a scheduled task โ and turn it into a proper Linux service that starts on boot, restarts on failure, and logs to the system journal.
Step 1 โ Get your script onto the server
ssh root@147.135.215.238 -p YOUR_PORT
Create a directory and upload your script:
mkdir -p /opt/myscript
# From your local machine:
scp -P YOUR_PORT myscript.py root@147.135.215.238:/opt/myscript/
Step 2 โ Set up a virtual environment
apt update && apt install -y python3 python3-venv
cd /opt/myscript
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt # or install packages manually
Step 3 โ Create the systemd service
nano /etc/systemd/system/myscript.service
[Unit]
Description=My Python Script
After=network.target
[Service]
Type=simple
WorkingDirectory=/opt/myscript
ExecStart=/opt/myscript/venv/bin/python3 /opt/myscript/myscript.py
Restart=always
RestartSec=10s
StandardOutput=journal
StandardError=journal
[Install]
WantedBy=multi-user.target
Step 4 โ Enable and start it
systemctl daemon-reload
systemctl enable myscript
systemctl start myscript
systemctl status myscript
You should see active (running). Your script is now a system service.
Step 5 โ Watch the logs
journalctl -u myscript -f
The -f flag follows the log in real time. Everything your script prints to stdout or stderr lands here.
Running on a schedule instead of continuously
If your script runs once and exits (like a daily price check), use a systemd timer instead of Restart=always:
nano /etc/systemd/system/myscript.timer
[Unit]
Description=Run myscript daily
[Timer]
OnCalendar=daily
Persistent=true
[Install]
WantedBy=timers.target
systemctl enable --now myscript.timer
This is cleaner than cron for Python scripts โ you get the same journalctl logging, the same restart behaviour, and no crontab syntax to remember.
How much does this cost to run?
Most lightweight Python scripts โ scrapers, bots, monitors โ use 20โ60MB of RAM at idle. A NATBox Nano VPS at $0.99/mo gives you 256MB, which comfortably hosts two or three scripts alongside the OS. If you're running heavier workloads, the Micro plan at $1.99/mo (512MB) gives you room to grow.