Open jaytaylor opened 10 years ago
start-stop-daemon is still needed, but it does not get in the way because it just executes the --exec process (instead of fork + exec). I have a PR (#19) that does not use the app_in_context script, so now all that is left to do is to implement that signal handler stuff you detailed.
So, the main problem you're going to run into with this setup is that Upstart has syscall hook based PID-tracking which it uses to keep track of the processes it is supposed to manage during the launch process. Since you are using start-stop-daemon to run /app/run-in-context, then using that to run /app/runs, then running multiple PIDs from /app/run, this is three layers of PID indirection which will confuse upstart greatly and cause it to get mixed up when it sends signals to downstream processes and potentially create a number of unresponsive, unreliable, and/or orphan PIDs.
This setup could be made more reliable by making the /app/run be called from Upstart directly without start-stop-daemon, then place a signal handler into /app/run which passes any signals it receives down to every child process it owns. An easy way of doing that can be, if your pid happened to be 12345, you can pass the signal to -12345 to send it to your entire POSIX Process Group. Or you can keep appending the $$ value to some list in bash, then loop across the list in the handler to signal all subprocesses using the signal received from above. Another option is to make a pre-stop hook which sends the signals where they are needed before the stop hook stops the master process.
Another option: make a separate upstart config for each daemon in the Procfile, so Upstart can watch each of them. Then use some of Upstart's dependencies, to make a task which depends on all the others to perform the starts and stops, while Upstart will be able to see each PID. Then, in the bash launcher of each task, use the exec function to launch the tasks, which causes them to inherit bash's PID. Then the PID it runs with and the PID Upstart expects are the same, and you get reliable operation.