mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2024-11-22 08:46:54 -06:00
add robustness when we run the electron process and move the exit
controller inside the main js file
This commit is contained in:
parent
3a443402a6
commit
0ae2e7f73c
12
server.js
12
server.js
@ -150,6 +150,18 @@
|
||||
if (err) throw err
|
||||
// Create/activate the webtorrent module
|
||||
webtorrent.create(function () {
|
||||
function cleanForExit () {
|
||||
utils.cleanForExit(webtorrent.app)
|
||||
}
|
||||
|
||||
function exitGracefullyOnSignal () {
|
||||
process.exit()
|
||||
}
|
||||
|
||||
process.on('exit', cleanForExit)
|
||||
process.on('SIGINT', exitGracefullyOnSignal)
|
||||
process.on('SIGTERM', exitGracefullyOnSignal)
|
||||
|
||||
// ----------- Make the server listening -----------
|
||||
server.listen(port, function () {
|
||||
videos.seedAll(function () {
|
||||
|
@ -186,5 +186,10 @@
|
||||
return dec
|
||||
}
|
||||
|
||||
utils.cleanForExit = function (webtorrent_process) {
|
||||
logger.info('Gracefully exiting')
|
||||
process.kill(-webtorrent_process.pid)
|
||||
}
|
||||
|
||||
module.exports = utils
|
||||
})()
|
||||
|
@ -43,11 +43,23 @@
|
||||
ipc.serve(function () {
|
||||
if (!webtorrentnode.silent) logger.info('IPC server ready.')
|
||||
|
||||
// Run a timeout of 30s after which we exit the process
|
||||
var timeout_webtorrent_process = setTimeout(function () {
|
||||
logger.error('Timeout : cannot run the webtorrent process. Please ensure you have electron-prebuilt npm package installed with xvfb-run.')
|
||||
process.exit()
|
||||
}, 30000)
|
||||
|
||||
ipc.server.on(processKey + '.ready', function () {
|
||||
if (!webtorrentnode.silent) logger.info('Webtorrent process ready.')
|
||||
clearTimeout(timeout_webtorrent_process)
|
||||
callback()
|
||||
})
|
||||
|
||||
ipc.server.on(processKey + '.exception', function (data) {
|
||||
logger.error('Received exception error from webtorrent process.', { exception: data.exception })
|
||||
process.exit()
|
||||
})
|
||||
|
||||
var webtorrent_process = spawn(__dirname + '/webtorrent.js', host, port, { detached: true })
|
||||
webtorrent_process.stderr.on('data', function (data) {
|
||||
// logger.debug('Webtorrent process stderr: ', data.toString())
|
||||
@ -57,15 +69,6 @@
|
||||
// logger.debug('Webtorrent process:', data.toString())
|
||||
})
|
||||
|
||||
function exitChildProcess () {
|
||||
if (!webtorrentnode.silent) logger.info('Gracefully exit child')
|
||||
process.kill(-webtorrent_process.pid)
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
process.on('SIGINT', exitChildProcess)
|
||||
process.on('SIGTERM', exitChildProcess)
|
||||
|
||||
webtorrentnode.app = webtorrent_process
|
||||
})
|
||||
|
||||
|
@ -83,5 +83,9 @@
|
||||
ipc.of[nodeKey].emit(processKey + '.ready')
|
||||
console.log('Ready.')
|
||||
})
|
||||
|
||||
process.on('uncaughtException', function (e) {
|
||||
ipc.of[nodeKey].emit(processKey + '.exception', { exception: e })
|
||||
})
|
||||
}
|
||||
})()
|
||||
|
Loading…
Reference in New Issue
Block a user