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
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-applicati on
pre-start script
su -s /bin/sh -c "$DAEMON" joeuseraccount
end script
script ppIsUp( ){
sleepWhileA
while pidof $1 >/dev/null; do
sleep 1
done
}
sleepWhileA ppIsUp $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.