Reputation: 13
I have a Python file that needs to be constantly running (a Telegram bot), but if I run in the background
python bot.py &
and then gracefully end the SSH connection, after a while the bot stops responding and I have to connect and launch it again.
How can I stop this from happening? If i cannot, how can I check when it is dead and relaunch it?
Upvotes: 1
Views: 1234
Reputation: 1284
chmod +x bot.py
Do this to your python file to make it executable
nohup /path/to/script/bot.py &
The nohup will run the script in the background while the & will keep it running after you close the terminal
To check if your script is still running ps -e | grep bot.py
To see any errors run cat nohup.out
Upvotes: 3