Comment 44 for bug 406397

Revision history for this message
john miller (johnmille1) wrote :

I came up with a hack to use upstart with applications that fork more than twice to use until the rewrite makes it downstream. It works for my application on my system. YMMV.

1. start the application in the pre-start section
2. in the script section run a script that runs as long as the application runs. The pid of this script is what upstart will track.
3. in the post-stop section kill the application

example

env DAEMON=/usr/bin/forky-application

pre-start script
    su -s /bin/sh -c "$DAEMON" joeuseraccount
end script

script
    sleepWhileAppIsUp(){
        while pidof $1 >/dev/null; do
            sleep 1
        done
    }

    sleepWhileAppIsUp $DAEMON
end script

post-stop script
    if pidof $DAEMON;
    then
        kill `pidof $DAEMON`
        #pkill $DAEMON # post-stop process (19300) terminated with status 1
    fi
end script

a similar approach could be taken with pid files.