- Implemented a new param for launching client processes to wait for the process to close - Waiting for the bash script to finish before restarting the application
This commit is contained in:
@@ -34,7 +34,7 @@ export const checkForUpdates = async () => {
|
|||||||
|
|
||||||
// Run the post-update script
|
// Run the post-update script
|
||||||
console.log('Running post-update script...');
|
console.log('Running post-update script...');
|
||||||
await launchProcess("bash", ['./post-update.sh']);
|
await launchProcess("bash", ['./post-update.sh'], true);
|
||||||
|
|
||||||
// Restart the application to apply the updates
|
// Restart the application to apply the updates
|
||||||
console.log('Update completed successfully. Restarting the application...');
|
console.log('Update completed successfully. Restarting the application...');
|
||||||
|
|||||||
@@ -10,20 +10,28 @@ const runningProcesses = {};
|
|||||||
* Launches a new process if it's not already running.
|
* Launches a new process if it's not already running.
|
||||||
* @param {string} processName - The name of the process to launch.
|
* @param {string} processName - The name of the process to launch.
|
||||||
* @param {string[]} args - The arguments to pass to the process.
|
* @param {string[]} args - The arguments to pass to the process.
|
||||||
|
* @param {boolean} waitForClose - Set this to wait to return until the process exits
|
||||||
*/
|
*/
|
||||||
export const launchProcess = (processName, args) => {
|
export const launchProcess = (processName, args, waitForClose=false) => {
|
||||||
if (!runningProcesses[processName]) {
|
if (!runningProcesses[processName]) {
|
||||||
const childProcess = spawn(processName, args);
|
const childProcess = spawn(processName, args);
|
||||||
|
|
||||||
// Store reference to the spawned process
|
// Store reference to the spawned process
|
||||||
runningProcesses[processName] = childProcess;
|
runningProcesses[processName] = childProcess;
|
||||||
|
|
||||||
childProcess.on('exit', (code, signal) => {
|
code = new Promise(res => {
|
||||||
// Remove reference to the process when it exits
|
childProcess.on('exit', (code, signal) => {
|
||||||
delete runningProcesses[processName];
|
// Remove reference to the process when it exits
|
||||||
console.log(`${processName} process exited with code ${code} and signal ${signal}`);
|
delete runningProcesses[processName];
|
||||||
|
console.log(`${processName} process exited with code ${code} and signal ${signal}`);
|
||||||
|
res(code);
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (waitForClose === true) {
|
||||||
|
return code
|
||||||
|
}
|
||||||
|
|
||||||
console.log(`${processName} process started.`);
|
console.log(`${processName} process started.`);
|
||||||
} else {
|
} else {
|
||||||
console.log(`${processName} process is already running.`);
|
console.log(`${processName} process is already running.`);
|
||||||
|
|||||||
Reference in New Issue
Block a user