| 556 | public async start(options?: { skipBuild?: boolean }): Promise<void> {} |
| 557 | |
| 558 | public async stop( |
| 559 | signal: 'SIGINT' | 'SIGTERM' | 'SIGKILL' = 'SIGKILL' |
| 560 | ): Promise<void> { |
| 561 | if (this.childProcess) { |
| 562 | if (this.isStopping !== null) { |
| 563 | // warn for debugging, but don't prevent sending two signals in succession |
| 564 | // (e.g. SIGINT and then SIGKILL) |
| 565 | require('console').error( |
| 566 | `Next server is already being stopped (received signal: ${signal}): `, |
| 567 | this.isStopping |
| 568 | ) |
| 569 | } |
| 570 | this.isStopping = Error() |
| 571 | Error.captureStackTrace(this.isStopping, this.stop) |
| 572 | const closePromise = once(this.childProcess, 'close') |
| 573 | await new Promise<void>((resolve) => { |
| 574 | treeKill(this.childProcess!.pid!, signal, (err) => { |
| 575 | if (err) { |
| 576 | require('console').error('tree-kill', err) |
| 577 | } |
| 578 | resolve() |
| 579 | }) |
| 580 | }) |
| 581 | this.childProcess.kill(signal) |
| 582 | await closePromise |
| 583 | this.childProcess = undefined |
| 584 | this.isStopping = null |
| 585 | require('console').log(`Stopped next server`) |
| 586 | } |
| 587 | } |
| 588 | |
| 589 | public async destroy(): Promise<void> { |
| 590 | try { |