More improvements to shutdown process #24
2 changed files with 16 additions and 13 deletions
27
app/main.js
27
app/main.js
|
@ -40,7 +40,7 @@ function openItem(fullPath) {
|
||||||
} else if (process.platform == 'linux') {
|
} else if (process.platform == 'linux') {
|
||||||
child = child_process.spawn('xdg-open', [fullPath], subprocOptions);
|
child = child_process.spawn('xdg-open', [fullPath], subprocOptions);
|
||||||
} else if (process.platform == 'win32') {
|
} else if (process.platform == 'win32') {
|
||||||
child = child_process.execSync('start', [fullPath], subprocOptions);
|
child = child_process.spawn(fullPath, [], subprocOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Causes child process reference to be garbage collected, allowing main process to exit
|
// Causes child process reference to be garbage collected, allowing main process to exit
|
||||||
|
@ -48,12 +48,13 @@ function openItem(fullPath) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPidsForProcessName(name) {
|
function getPidsForProcessName(name) {
|
||||||
if (process.platform == 'windows') {
|
if (process.platform == 'win32') {
|
||||||
const tasklistOut = child_process.execSync('tasklist',
|
const tasklistOut = child_process.execSync(`tasklist /fi "Imagename eq ${name}.exe" /nh`, {encoding: 'utf8'});
|
||||||
['/fi', `Imagename eq ${name}.exe`, '/nh'],
|
if (tasklistOut.startsWith('INFO')) {
|
||||||
{encoding: 'utf8'}
|
return [];
|
||||||
).stdout;
|
} else {
|
||||||
return tasklistOut.match(/[^\n]+/g).map((line) => line.split(/\s+/)[1]); // Second column of every non-empty line
|
return tasklistOut.match(/[^\r\n]+/g).map((line) => line.split(/\s+/)[1]); // Second column of every non-empty line
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
const pgrepOut = child_process.spawnSync('pgrep', ['-x', name], {encoding: 'utf8'}).stdout;
|
const pgrepOut = child_process.spawnSync('pgrep', ['-x', name], {encoding: 'utf8'}).stdout;
|
||||||
return pgrepOut.match(/\d+/g);
|
return pgrepOut.match(/\d+/g);
|
||||||
|
@ -158,13 +159,15 @@ function forceKillAllDaemonsAndQuit() {
|
||||||
console.log(`Found ${daemonPids.length} running daemon instances. Attempting to force kill...`);
|
console.log(`Found ${daemonPids.length} running daemon instances. Attempting to force kill...`);
|
||||||
|
|
||||||
for (const pid of daemonPids) {
|
for (const pid of daemonPids) {
|
||||||
const daemonKillAttemptsComplete = 0;
|
let daemonKillAttemptsComplete = 0;
|
||||||
kill(pid, 'SIGKILL', (err) => {
|
kill(pid, 'SIGKILL', (err) => {
|
||||||
daemonKillAttemptsComplete++;
|
daemonKillAttemptsComplete++;
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log(`Failed to force kill running daemon with pid ${pid}. Error message: ${err.message}`);
|
console.log(`Failed to force kill daemon task with pid ${pid}. Error message: ${err.message}`);
|
||||||
|
} else {
|
||||||
|
console.log(`Force killed daemon task with pid ${pid}.`);
|
||||||
}
|
}
|
||||||
if (daemonKillAttemptsComplete >= daemonPids.length) {
|
if (daemonKillAttemptsComplete >= daemonPids.length - 1) {
|
||||||
quitNow();
|
quitNow();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -208,9 +211,9 @@ app.on('activate', () => {
|
||||||
function shutdownDaemonAndQuit(evenIfNotStartedByApp = false) {
|
function shutdownDaemonAndQuit(evenIfNotStartedByApp = false) {
|
||||||
if (daemonSubprocess) {
|
if (daemonSubprocess) {
|
||||||
console.log('Killing lbrynet-daemon process');
|
console.log('Killing lbrynet-daemon process');
|
||||||
|
daemonSubprocessKillRequested = true;
|
||||||
kill(daemonSubprocess.pid, undefined, (err) => {
|
kill(daemonSubprocess.pid, undefined, (err) => {
|
||||||
console.log('Killed lbrynet-daemon process');
|
console.log('Killed lbrynet-daemon process');
|
||||||
requestedDaemonSubprocessKilled = true;
|
|
||||||
quitNow();
|
quitNow();
|
||||||
});
|
});
|
||||||
} else if (evenIfNotStartedByApp) {
|
} else if (evenIfNotStartedByApp) {
|
||||||
|
@ -249,7 +252,7 @@ function upgrade(event, installerPath) {
|
||||||
win.loadURL(`file://${__dirname}/dist/upgrade.html`);
|
win.loadURL(`file://${__dirname}/dist/upgrade.html`);
|
||||||
}
|
}
|
||||||
|
|
||||||
app.quit();
|
shutdownDaemonAndQuit(true);
|
||||||
// wait for daemon to shut down before upgrading
|
// wait for daemon to shut down before upgrading
|
||||||
// what to do if no shutdown in a long time?
|
// what to do if no shutdown in a long time?
|
||||||
console.log('Update downloaded to', installerPath);
|
console.log('Update downloaded to', installerPath);
|
||||||
|
|
|
@ -14,7 +14,7 @@ Web UI version numbers should always match the corresponding version of LBRY App
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
* Update process now easier and more reliable
|
* Update process now easier and more reliable
|
||||||
*
|
* Cleaned up shutdown logic
|
||||||
*
|
*
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
Loading…
Reference in a new issue