aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/webTorrentNode.js
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2015-11-02 22:19:39 +0100
committerChocobozzz <florian.bigard@gmail.com>2015-11-03 08:10:30 +0100
commit0ae2e7f73c24779f8c99453fb02491382cc0520e (patch)
treef7bd68672746107c5bcc91686fef48c0f5c11bf2 /src/webTorrentNode.js
parent3a443402a6f22e4ac1fd80af62abfef7efd6d7a4 (diff)
downloadPeerTube-0ae2e7f73c24779f8c99453fb02491382cc0520e.tar.gz
PeerTube-0ae2e7f73c24779f8c99453fb02491382cc0520e.tar.zst
PeerTube-0ae2e7f73c24779f8c99453fb02491382cc0520e.zip
add robustness when we run the electron process and move the exit
controller inside the main js file
Diffstat (limited to 'src/webTorrentNode.js')
-rw-r--r--src/webTorrentNode.js21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/webTorrentNode.js b/src/webTorrentNode.js
index ebe8d5d81..507cf31fc 100644
--- a/src/webTorrentNode.js
+++ b/src/webTorrentNode.js
@@ -43,11 +43,23 @@
43 ipc.serve(function () { 43 ipc.serve(function () {
44 if (!webtorrentnode.silent) logger.info('IPC server ready.') 44 if (!webtorrentnode.silent) logger.info('IPC server ready.')
45 45
46 // Run a timeout of 30s after which we exit the process
47 var timeout_webtorrent_process = setTimeout(function () {
48 logger.error('Timeout : cannot run the webtorrent process. Please ensure you have electron-prebuilt npm package installed with xvfb-run.')
49 process.exit()
50 }, 30000)
51
46 ipc.server.on(processKey + '.ready', function () { 52 ipc.server.on(processKey + '.ready', function () {
47 if (!webtorrentnode.silent) logger.info('Webtorrent process ready.') 53 if (!webtorrentnode.silent) logger.info('Webtorrent process ready.')
54 clearTimeout(timeout_webtorrent_process)
48 callback() 55 callback()
49 }) 56 })
50 57
58 ipc.server.on(processKey + '.exception', function (data) {
59 logger.error('Received exception error from webtorrent process.', { exception: data.exception })
60 process.exit()
61 })
62
51 var webtorrent_process = spawn(__dirname + '/webtorrent.js', host, port, { detached: true }) 63 var webtorrent_process = spawn(__dirname + '/webtorrent.js', host, port, { detached: true })
52 webtorrent_process.stderr.on('data', function (data) { 64 webtorrent_process.stderr.on('data', function (data) {
53 // logger.debug('Webtorrent process stderr: ', data.toString()) 65 // logger.debug('Webtorrent process stderr: ', data.toString())
@@ -57,15 +69,6 @@
57 // logger.debug('Webtorrent process:', data.toString()) 69 // logger.debug('Webtorrent process:', data.toString())
58 }) 70 })
59 71
60 function exitChildProcess () {
61 if (!webtorrentnode.silent) logger.info('Gracefully exit child')
62 process.kill(-webtorrent_process.pid)
63 process.exit(0)
64 }
65
66 process.on('SIGINT', exitChildProcess)
67 process.on('SIGTERM', exitChildProcess)
68
69 webtorrentnode.app = webtorrent_process 72 webtorrentnode.app = webtorrent_process
70 }) 73 })
71 74