always running python script
# in python, you should make a while(True) over the script
flag = True
while(flag):
# Your awesome script goes here
print("I'm running forever")
# flag is there to have an exit option if needed
flag = flase if statement == True else True
""" Now we need to make changes in system level """
# In Windows #
# Use built-in program "Task-Scheduler"
- Create Task
- In 'Triggers' tab add new trigger and selecet 'At startup'
- In 'Actions' tab add new action and write the command as you would write it in cmd (use absoulute path)
press OK and you DONE!
# In Ubuntu #
Create file 'foo.service' inside '/etc/systemmd/system'
and write inside
"""
[Unit]
After=network.target
Description=bot
[Service]
Type=simple
ExecStart=/bin/bash -c 'python3 /home/ubuntu/Path/To/Directory/main.py'
Restart=always
RestartSec=5s
[Install]
WantedBy=multi-user.target
"""
then in terminal run
sudo systemctl enable foo.service
sudo systemctl start foo.service
Done!