@@ -35,6 +35,8 @@ import {
3535 promiseWithResolvers ,
3636 resolveHostname ,
3737 resolveServerUrls ,
38+ setupSIGTERMListener ,
39+ teardownSIGTERMListener ,
3840} from '../utils'
3941import { getFsUtils } from '../fsUtils'
4042import { ssrLoadModule } from '../ssr/ssrModuleLoader'
@@ -502,8 +504,6 @@ export async function _createServer(
502504 const container = await createPluginContainer ( config , moduleGraph , watcher )
503505 const closeHttpServer = createServerCloseFn ( httpServer )
504506
505- let exitProcess : ( ) => void
506-
507507 const devHtmlTransformFn = createDevHtmlTransformFn ( config )
508508
509509 const onCrawlEndCallbacks : ( ( ) => void ) [ ] = [ ]
@@ -638,10 +638,7 @@ export async function _createServer(
638638 } ,
639639 async close ( ) {
640640 if ( ! middlewareMode ) {
641- process . off ( 'SIGTERM' , exitProcess )
642- if ( process . env . CI !== 'true' ) {
643- process . stdin . off ( 'end' , exitProcess )
644- }
641+ teardownSIGTERMListener ( closeServerAndExit )
645642 }
646643 await Promise . allSettled ( [
647644 watcher . close ( ) ,
@@ -736,20 +733,18 @@ export async function _createServer(
736733 } ,
737734 } )
738735
739- if ( ! middlewareMode ) {
740- exitProcess = async ( ) => {
741- try {
742- await server . close ( )
743- } finally {
744- process . exit ( )
745- }
746- }
747- process . once ( 'SIGTERM' , exitProcess )
748- if ( process . env . CI !== 'true' ) {
749- process . stdin . on ( 'end' , exitProcess )
736+ const closeServerAndExit = async ( ) => {
737+ try {
738+ await server . close ( )
739+ } finally {
740+ process . exit ( )
750741 }
751742 }
752743
744+ if ( ! middlewareMode ) {
745+ setupSIGTERMListener ( closeServerAndExit )
746+ }
747+
753748 const onHMRUpdate = async (
754749 type : 'create' | 'delete' | 'update' ,
755750 file : string ,
0 commit comments