Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question
    
I've also just tried removing the forking behaviour from the service, and removing expect entirely, but then start queryqueue runs indefinitely, presumably waiting for the service to exit. –  sirlark Nov 1 '12 at 16:07

1 Answer 1

up vote 1 down vote accepted

The expect stanza only works for the "main" process ("exec" or "script" stanza). This is documented in init(5).

share|improve this answer
    
Thanks for the answer, but if I place the script command in it's own stanza, then the environment variables defined in the config file (sourced in pre-start script) aren't available to exec/script. I've edited the original post to reflect the changes I've made. –  sirlark Nov 8 '12 at 21:09
    
Okay, I figured it out. You need to source the config file in the main script stanza. Again, edited the original code to reflect what eventually worked. –  sirlark Nov 8 '12 at 21:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.