feat: forward signals to process manager (#6357)
### Description
Add a Rust version of the Signal handler that alerts any subscribers
that a signal has been received. Since async callbacks are tricky in
Rust we instead go with the approach of registering subscribers that
then can listen and get a guard to indicate when they are done
responding to the closure.
Future work might include switching to use
[`SignalStream`](https://docs.rs/tokio-stream/latest/tokio_stream/wrappers/struct.SignalStream.html)
so we could handle "graceful" vs "forceful" shutdowns depending on the
number of signals received.
### Testing Instructions
New unit tests for signal handler, verify that long running processes
receive the signal in a test repo:
```
[0 olszewski@chriss-mbp] /tmp $ npx create-turbo ctrl-c -m pnpm && cd ctrl-c && pnpm rm turbo
[0 olszewski@chriss-mbp] /tmp/ctrl-c $ EXPERIMENTAL_RUST_CODEPATH=true turbo_dev dev --no-daemon -vv
...
docs:dev: - ready started server on [::]:3001, url: http://localhost:3001
web:dev: - ready started server on [::]:3000, url: http://localhost:3000
docs:dev: - event compiled client and server successfully in 154 ms (20 modules)
web:dev: - event compiled client and server successfully in 176 ms (20 modules)
docs:dev: - wait compiling...
web:dev: - wait compiling...
docs:dev: - event compiled client and server successfully in 95 ms (20 modules)
web:dev: - event compiled client and server successfully in 86 ms (20 modules)
^C2023-11-03T10:46:06.619-0700 [DEBUG] turborepo_lib::process::child: stopping child process
starting shutdown
2023-11-03T10:46:06.620-0700 [DEBUG] turborepo_lib::process::child: sending SIGINT to child 54213
2023-11-03T10:46:06.619-0700 [DEBUG] turborepo_lib::process: waiting for 2 processes to exit
2023-11-03T10:46:06.620-0700 [DEBUG] turborepo_lib::process::child: stopping child process
starting shutdown
2023-11-03T10:46:06.620-0700 [DEBUG] turborepo_lib::process::child: sending SIGINT to child 54214
2023-11-03T10:46:06.620-0700 [DEBUG] turborepo_lib::process::child: waiting for child 54213
2023-11-03T10:46:06.620-0700 [DEBUG] turborepo_lib::process::child: waiting for child 54214
web:dev:
docs:dev:
2023-11-03T10:46:06.670-0700 [DEBUG] turborepo_lib::process::child: child process stopped
2023-11-03T10:46:06.670-0700 [DEBUG] turborepo_lib::process::child: child process stopped
```
Closes TURBO-1583
---------
Co-authored-by: Chris Olszewski <Chris Olszewski>