1

I was looking for how to create a pid file for monitoring of upstart processes in ubuntu. I looked at the accepted answer in Ubuntu, upstart, and creating a pid for monitoring and ended up with following code:

env PROGRAM_NAME=myscript
env BASE_PATH=/bar/

respawn limit 5 30

script
${BASE_PATH}/bin/python ${BASE_PATH}/scripts/${PROGRAM_NAME}.py -e ${BASE_PATH}/foo.ini
end script

post-start script
echo PID=`status myscript | egrep -oi '([0-9]+)$' | head -n1` 
echo $PID > /var/run/${PROGRAM_NAME}.pid
end script

post-stop script
rm -f /var/run/${PROGRAM_NAME}.pid
end script

There are 3 problems I encounter:

  1. Somehow this code creates two processes. The parent process (checked through ps -ef | grep python) is just a shell such as:

    /bin/sh -e -c ${BASE_PATH}/bin/python ${BASE_PATH}/scripts/${PROGRAM_NAME}.py -e ${BASE_PATH}/foo.ini /bin/sh
    

    While the child process has the correct substitutes:

    /bar/bin/python /bar/scripts/myscript.py -e /bar/foo.ini        
    
  2. The pid file contains the pid of the parent of the actual process. Not the child one which is the actual process.

  3. The respawn doesn't work. I kill the child process with kill pid (which kills the parent too, but not vice versa).

Community
  • 1
  • 1
Karan
  • 334
  • 1
  • 3
  • 15

0 Answers0