Hello, I recently purchased a droplet and have gotten everything up and running. I am using it for a Reddit bot I coded in Python. However, I noticed that in order to run the script I need to open Putty on my computer and keep it open. Is there anyway to run my Python script on my droplet without needing to use my computer.
Basically I am looking to run my python script 24/7 without use of my computer, which is what I thought the VPS was for, I just cannot figure it out. I am rather new to this so I apologize for my terminology or level of question.
Language: Python OS: Ubuntu
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Heya,
Setting up a Python script to run as a system service using systemd is a common way to ensure it’s always running. Here’s a step-by-step guide for setting up a Python script as a systemd service:
Write Your Python Script: For example, let’s say you have your_script.py in /path/to/your_script.py.
Ensure your script is executable: Make your Python script executable by adding a shebang line at the top and changing its permissions:
#!/usr/bin/env python3
chmod +x /path/to/your_script.py
/etc/systemd/system/, e.g., your_script.service.sudo nano /etc/systemd/system/your_script.service
Add the following content to the service file:
[Unit]
Description=My Python Script Service
After=multi-user.target
[Service]
Type=simple
ExecStart=/path/to/your_script.py
Restart=on-abort
[Install]
WantedBy=multi-user.target
Explanation:
multi-user system has been reached.systemd that it’s a simple, one-process service.systemd will restart it.systemd about the new service and start it:sudo systemctl daemon-reload
sudo systemctl start your_script.service
sudo systemctl enable your_script.service
Additional Commands:
sudo systemctl stop your_script.servicesudo systemctl restart your_script.servicejournalctl. For example: journalctl -u your_script.service.Remember that when you modify the service file or the script itself, you should usually reload or restart the service to apply the changes.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.