DarthSim / overmind

Process manager for Procfile-based applications and tmux
MIT License
2.86k stars 81 forks source link

Gracefully handle backgrounded processes #143

Closed mculp closed 1 year ago

mculp commented 1 year ago

Kinda similar to some of the other issues on here. rubocop --start-server always runs daemonized, which kills the other processes. In this case, there's no signal to trap, since it's just spawning another process.

Hopefully the issue will be remedied soon on their side soon, as they have a pull request open: https://github.com/rubocop/rubocop/pull/11319

But I think a lot of folks would benefit from some type of solution for this -- whether it's before/after hooks, process order, process dependencies, or something else.

My workaround:

OVERMIND_CAN_DIE=rubocop rubocop --start-server

This isn't a great workaround, because the server continues running even after Overmind has shutdown.

image

But you can see the rubocop server running:

image

Here, you can see all processes running: (I guess it's a separate issue, but there are two of each of them)

image

After overmind stop:

image
DarthSim commented 1 year ago

Unfortunately, I don't see any way to fix this on the Overmind's level. When daemonizing, the process launches another process within another process group. Thus Overmind can't get the new process's PID and can't monitor its status.

As a dirty bypass:

rubocop: trap 'rubocop --stop-server' EXIT > /dev/null; rubocop --start-server && ping localhost > /dev/null

trap 'rubocop --stop-server' EXIT > /dev/null sets the trap on exit so rubocop --stop-server will be executed when the script exits. ping localhost > /dev/null makes script keeping running after rubocop --stop-server exits.

mculp commented 1 year ago

agh! That ping trick worked! But that is definitely a dirty, dirty bypass :)

Thank you.