Upstart can't determine my process' pid

Posted by sirlark on Server Fault See other posts from Server Fault or by sirlark
Published on 2012-11-01T15:46:53Z Indexed on 2012/11/08 23:05 UTC
Read the original article Hit count: 286

Filed under:
|
|

I'm writing an upstart script for a small service I've written for my colleagues. My upstart job can start the service, but when it does it only outputs queryqueue start/running; note the lack of a pid as given for other services.

#/etc/init/queryqueue.conf

description     "Query Queue Daemon"
author          "---"

start on started mysql
stop on stopping mysql

expect fork

env DEFAULTFILE=/etc/default/queryqueue
umask 007

kill timeout 30

pre-start script
    #if [ -f "$DEFAULTFILE" ]; then
    #    . "$DEFAULTFILE"
    #fi
    [ ! -f /var/run/queryqueue.sock ] || rm -rf /var/run/queryqueue.sock
    #exec /usr/local/sbin/queryqueue -s /var/run/queryqueue.sock -d -l /tmp/upstart.log -p $PIDFILE -n $NUM_WORKERS $CLEANCACHE $FLUSHCACHE $CACHECONN
end script

script
    #Originally this stanza didn't exist at all
    if [ -f "$DEFAULTFILE" ]; then
        . "$DEFAULTFILE"
    fi
    exec /usr/local/sbin/queryqueue -s /var/run/queryqueue.sock -d -l /tmp/upstart.log -p $PIDFILE -n $NUM_WORKERS $CLEANCACHE $FLUSHCACHE $CACHECONN
end script


post-start script
    for i in `seq 1 5` ; do
        [ -S /var/run/queryqueue.sock ] && exit 0
        sleep 1
    done
    exit 1
end script

The service in question is a python script, which when run without error, forks using the code below right after checking command line options and basic environmental sanity, so I tell upstart to expect fork.

pid = os.fork()
if pid != 0:
    sys.exit(0)

The script is executable, and has a python shebang. I can send the TERM signal to the process manually, and it quits gracefully. But running stop queryqueue claims queryqueue stop/waiting but the process is still alive and well. Also, it's logs indicate it never received the kill signal. I'm guessing this is because upstart doesn't know which pid it has. I've also tried expect daemon and leaving the expect clause out entirely, but there's no change in behaviour.

How can I get upstart to determine the pid of the exec'd process

© Server Fault or respective owner

Related posts about ubuntu

Related posts about python