shutdown method
Graceful shutdown: SIGTERM, wait, then SIGKILL.
Implementation
Future<int> shutdown({Duration grace = const Duration(seconds: 5)}) async {
_process.kill(ProcessSignal.sigterm);
final code = await _process.exitCode.timeout(
grace,
onTimeout: () {
_process.kill(ProcessSignal.sigkill);
return -1;
},
);
await _stdoutSub.cancel();
await _stderrSub.cancel();
await _stdoutController.close();
await _stderrController.close();
return code;
}