11const runCommand = require ( '../src/utility/run-command' ) ;
2- const { execSync } = require ( 'child_process' ) ;
3-
4- function getPidByPort ( port ) {
5- try {
6- const stdout = execSync ( `lsof -ti :${ port } ` , { encoding : 'utf8' } ) ;
7- const pid = stdout . trim ( ) ;
8- return pid ? parseInt ( pid , 10 ) : null ;
9- } catch ( error ) {
10- return null ;
11- }
12- }
13-
14- function killProcByPid ( pid ) {
15- try {
16- execSync ( `kill -15 ${ pid } ` , { stdio : 'ignore' } ) ;
17- } catch ( e ) { }
18- }
192
203module . exports = class NextJsServer {
214 constructor ( env , { port } = { port : 3000 } ) {
@@ -37,26 +20,8 @@ module.exports = class NextJsServer {
3720 async stop ( ) {
3821 console . log ( '-----NEXTJS SERVER-STOP---process.platform->' , ! ! this . proc , process . platform ) ;
3922 if ( this . proc ) {
40-
41- // this.proc.kill('SIGTERM');
42- // await new Promise((resolve) => setTimeout(resolve, 1000));
43- // this.proc.kill('SIGKILL');
44- console . log ( '-----NEXTJS SERVER-STOP---process.kill->' , ! ! this . proc , process . platform ) ;
4523 process . kill ( - this . proc . pid , 'SIGKILL' ) ;
46- await new Promise ( ( resolve ) => setTimeout ( resolve , 1000 ) ) ;
47- }
48-
49- if ( process . platform === 'win32' || 1 ) {
50- return ;
51- }
52-
53- let pid ;
54- while ( pid = getPidByPort ( this . port ) ) {
55- console . log ( `-----NEXTJS SERVER-stop() kill for port ${ this . port } ---->` , pid ) ;
56- killProcByPid ( pid ) ;
57- await new Promise ( ( resolve ) => setTimeout ( resolve , 5000 ) ) ;
5824 }
59- console . log ( `-----NEXTJS SERVER - KILLED for port ${ this . port } ---->` , pid ) ;
6025 }
6126} ;
6227
0 commit comments