Can upstart expect/respawn be used on processes that fork more than twice?
I came up with an ugly hack to make this work. It works for my application on my system. YMMV.
- start the application in the pre-start section
- 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.
- 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.
delayed_job with multiple workers and upstart
Out of the box, it appears that upstart expect does not support the behavior outlined in https://github.com/collectiveidea/delayed_job#running-jobs , as there are multiple workers that each fork twice to daemonize.
As outlined in this question about upstart: Can upstart expect/respawn be used on processes that fork more than twice? , you can use a bit of scripting to shepherd the processes yourself in the different hooks.
Another option would be to use upstart job instances (http://upstart.ubuntu.com/cookbook/#instance) to start multiple jobs that do not fork.
Ubuntu upstart gets incorrect PID from Play 1.3
This is because getJavaVersion()
spawns a subprocess, which bumps the PID count, which breaks Upstart, the latter which expects Play to fork exactly none, once or twice, depending on which expect stanza you use.
I've fixed this in a pull request.
Upstart script for bitcoind, respawn feature
oom never
is your first problem. You need this:
oom score never
Additionally, do not use oom score never except for critical system services. Try -500 or -700 instead. That should be a higher priority than most processes, but not the ones that are essential for any running system. So you should use:
oom score -500
The second issue is that you are using start-stop-daemon. You should just ditch that, as Upstart can handle everything. So the resulting script would look like this:
description "bitcoind"
start on filesystem
stop on runlevel [!2345]
oom score -500
chdir /root/.bitcoin
respawn
respawn limit 10 60 # 10 times in 60 seconds
exec /usr/bin/bitcoind
The last issue could be that you have not defined normal exit
properly. You need to specify which return codes and signals constitute a normal exit, so that Upstart knows to respawn if the signals and return codes do not match. See the Upstart cookbook on how to do this: http://upstart.ubuntu.com/cookbook/#normal-exit.
Upstart stop if running
A colleague came up with a great solution
if ( initctl status node-App | grep start ); then
initctl stop node-App
fi
Very simple and works properly when run from Jenkins
Related Topics
Different CPU Cache Size Reported by /Sys/Device/ and Dmidecode
Graphics Card Memory and Virtual Address Space of a Process
How to Find Files Except Given Name
How to Open Another File in Background Vim from Bash Command-Line
How to Set Control Register 0 (Cr0) Bits in X86-64 Using Gcc Assembly on Linux
How to Translate X11 Keycode Back to Scancode or Hid Usage Id Reliably
Linux Transfer Parameter for Function in Declare_Work
How to Tell Binary from Text Files in Linux
How to Determine Thread Local Storage Model Used by a Library on Linux
Receiving Multicast on a Server with Multiple Interfaces (Linux)
Can Upstart Expect/Respawn Be Used on Processes That Fork More Than Twice
What Is Eof!! in The Bash Script
Implementing Basic File System
Calculate Total Disk I/O by a Single Process