I am running my Python script using upstart feature of Ubuntu so that if for whatever reason my Python script dies or gets killed, it can be restarted automatically.
So I decided to use UPSTART feature of Ubuntu to restart the Python script automatically.
After creating the testing.conf file like this in /etc/init/testing.conf
–
chdir /tekooz
exec python testing.py
respawn
I ran below sudo command to start it and I can see that process running using ps ax
and my python script is also running fine.
root@bx13:/tekooz# sudo start testing
testing start/running, process 27794
This is my below python script –
#!/usr/bin/python
import time
while True:
print "Hello World"
time.sleep(5)
But how do I test it to see if my Python script gets killed, then it is getting restarted automatically? I cannot kill the PID
as the PID keeps on changing if I do ps ax
on my testing.py
.
Can anyone tell me how to test this scenario? I am just trying to make sure my script can be restarted automatically if it gets killed or dies.
Best Answer
Just run:
that gives you the status of the running upstart service.
And with
tail -f /var/log/syslog
you can see if it is respawning.The "Hello World" goes is I think going nowhere.
I recommend testing with:
and run
tail -f /var/tmp/testing.log
in an other window.