Ubuntu 14.04
I have simple upstart job test.conf:
root@ubuntutest:~# cat /etc/init/test.conf
expect fork
script
/root/test.py
end script
and simple python script /root/test.py:
root@ubuntutest:~# cat /root/test.py
#!/usr/bin/python
import time
print("Hello, World")
time.sleep(30)
print("Goodbye")
I start test job, ensure that upstart tracks proper PID, wait script's termination, but than upstart doesn't stop tracking non-existing PID. So upstart always shows that the job is running (while actually it is not)
root@ubuntutest:~# initctl status test
test stop/waiting
root@ubuntutest:~# initctl start test
test start/running, process 1859
root@ubuntutest:~# ps aux | grep 1859
root 1859 0.2 0.7 29832 7188 ? S 14:43 0:00 /usr/bin/python /root/test.py
root 1862 0.0 0.2 11760 2156 pts/0 S+ 14:43 0:00 grep --color=auto 1859
root@ubuntutest:~# ps aux | grep 1859
root 1864 0.0 0.2 11760 2224 pts/0 S+ 14:43 0:00 grep --color=auto 1859
root@ubuntutest:~# initctl status test
test start/running, process 1859
If i delete expect fork from test job then everything works good (except upstart tracks sh instead of python) - i want to understand what's wrong with my code?
The same happens if i use bash script instead of python:
#!/bin/bash
sleep 30
Why not simply use the
execstanza rather thanscript [...] end script?Alternatively you can exec the python program from within the script section:
As a short answer on why upstart thinks the process is still alive even though it has exited: the shell process is intercepting the signals that upstart would normally receive when your python program exits, and Upstart cannot know that the process has exited without these signals.