aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils/server/server.ts
diff options
context:
space:
mode:
Diffstat (limited to 'shared/extra-utils/server/server.ts')
-rw-r--r--shared/extra-utils/server/server.ts21
1 files changed, 11 insertions, 10 deletions
diff --git a/shared/extra-utils/server/server.ts b/shared/extra-utils/server/server.ts
index bc5e1cd5f..f7048ba43 100644
--- a/shared/extra-utils/server/server.ts
+++ b/shared/extra-utils/server/server.ts
@@ -221,11 +221,17 @@ export class PeerTubeServer {
221 221
222 this.app = fork(join(root(), 'dist', 'server.js'), options.peertubeArgs || [], forkOptions) 222 this.app = fork(join(root(), 'dist', 'server.js'), options.peertubeArgs || [], forkOptions)
223 223
224 const onExit = function () { 224 const onPeerTubeExit = () => rej(new Error('Process exited'))
225 return rej(new Error('Process exited')) 225 const onParentExit = () => {
226 if (!this.app || !this.app.pid) return
227
228 try {
229 process.kill(self.app.pid)
230 } catch { /* empty */ }
226 } 231 }
227 232
228 this.app.on('exit', onExit) 233 this.app.on('exit', onPeerTubeExit)
234 process.on('exit', onParentExit)
229 235
230 this.app.stdout.on('data', function onStdout (data) { 236 this.app.stdout.on('data', function onStdout (data) {
231 let dontContinue = false 237 let dontContinue = false
@@ -254,16 +260,11 @@ export class PeerTubeServer {
254 if (options.hideLogs === false) { 260 if (options.hideLogs === false) {
255 console.log(data.toString()) 261 console.log(data.toString())
256 } else { 262 } else {
263 process.removeListener('exit', onParentExit)
257 self.app.stdout.removeListener('data', onStdout) 264 self.app.stdout.removeListener('data', onStdout)
258 self.app.removeListener('exit', onExit) 265 self.app.removeListener('exit', onPeerTubeExit)
259 } 266 }
260 267
261 process.on('exit', () => {
262 try {
263 process.kill(self.app.pid)
264 } catch { /* empty */ }
265 })
266
267 res() 268 res()
268 }) 269 })
269 }) 270 })