Host a simple python script with systemd on ubuntu
Work In Progress
sudo useradd -m simple-script
sudo -u simple-script bash
ssh-keygen -t ed25519 -C “simple-script”
tail ~/.ssh/id_ed25519.pub# after adding the key to the deploykey section of github
git clone [email protected]:user/simple_script.git
Difference between folders
the user folder is simple-script with a ”-” and the project forlder has a ”_” instead
cd /home/simple-script/simple_script/
# test you script
python3 -m venv venv
source venv/bin/activate
pip3 install -r requirement.txt
python3 main.py
# execute this with the host admin user
sudo nano /etc/systemd/system/simple-script.service# systemd service file
[Unit]
Description=simple-script daemon
After=network.target
[Service]
User=simple-script
Group=simple-script
WorkingDirectory=/home/simple-script/simple_script/
ExecStart=/home/simple-script/simple_script/venv/bin/python3 main.py
[Install]
WantedBy=multi-user.target# execute this with the host admin user
sudo systemctl start simple-script.service
# check if everything is running correctly
sudo systemctl status simple-script.service
# make it start when you restart the server
sudo systemctl enable simple-script.service