Skip to content

Commit

Permalink
small update
Browse files Browse the repository at this point in the history
  • Loading branch information
asaccool committed Jul 18, 2019
1 parent b97686d commit 2f5a9d2
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ When a new version of PrivateSky code will be released the clones of the pskrunt
The following scripts are available to run:

``` npm run start ``` will run a PrivateSky node
``` npm run build ``` will build the code for the domain and deply in the current domain
``` npm run build ``` will build the code for the domain and deploy in the current domain
``` npm run watch ``` will automatically build the code for the domain and deploy
``` npm run console ``` will launch a bash or cmd with paths to run pskadmin tools
Empty file removed psknode/bin/pskbuild.js
Empty file.
Empty file removed psknode/bin/psknode.js
Empty file.
16 changes: 14 additions & 2 deletions psknode/bin/scripts/psknode.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/

const {spawnSync, fork, spawn} = require('child_process');
const max_timeout = 10*60*1000; // 10 minutes
const restartDelays = {};

let shouldRestart = true;
const forkedProcesses = {};
Expand All @@ -16,11 +18,21 @@ function startProcess(filePath) {

console.log('SPAWNED ', forkedProcesses[filePath].pid);

function restartWithDelay(filePath){
let timeout = restartDelays[filePath] || 100;
console.log(`Process will restart in ${timeout} ms ...`);
setTimeout(()=>{
restartDelays[filePath] = (timeout * 2) % max_timeout;
startProcess(filePath);
}, timeout);
}

function errorHandler(filePath) {
let timeout = 100;
return function (error) {
console.log(`\x1b[31mException caught on spawning file ${filePath} `, error ? error : "", "\x1b[0m"); //last string is to reset terminal colours
if (shouldRestart) {
startProcess(filePath);
restartWithDelay(filePath);
}
}
}
Expand All @@ -29,7 +41,7 @@ function startProcess(filePath) {
return function () {
console.log(`\x1b[33mExit caught on spawned file ${filePath}`, "\x1b[0m"); //last string is to reset terminal colours
if (shouldRestart) {
startProcess(filePath);
restartWithDelay(filePath);
}
}
}
Expand Down
24 changes: 20 additions & 4 deletions psknode/bundles/pskruntime.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion psknode/bundles/readme.txt

This file was deleted.

11 changes: 7 additions & 4 deletions psknode/core/launcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,15 @@ function launchDomainSandbox(name, configuration) {
child_env.config = JSON.stringify(env.config);
child_env.PRIVATESKY_TMP = process.env.PRIVATESKY_TMP;
child_env.PRIVATESKY_ROOT_FOLDER = process.env.PRIVATESKY_ROOT_FOLDER;

const child = childProcess.fork('sandboxes/domainSandbox.js', [name], {cwd: __dirname, env: child_env});
child.on('exit', (code, signal) => {
console.log(`DomainSandbox [${name}] got an error code ${code}. Restarting...`);
delete domainSandboxes[name];
launchDomainSandbox(name, configuration);
});
setTimeout(()=>{
console.log(`DomainSandbox [${name}] got an error code ${code}. Restarting...`);
delete domainSandboxes[name];
launchDomainSandbox(name, configuration);
}, 100);
});

domainSandboxes[name] = child;
} else {
Expand Down
22 changes: 19 additions & 3 deletions psknode/core/utils/exitHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,29 @@ const events = ["exit", "SIGINT", "SIGUSR1", "SIGUSR2", "uncaughtException", "SI

module.exports = function manageShutdownProcess(childrenList){

let shutting = false;
function handler(){
console.log("Handling exit event on", process.pid, "arguments:", arguments);
//console.log("Handling exit event on", process.pid, "arguments:", arguments);
var childrenNames = Object.keys(childrenList);
for(let j=0; j<childrenNames.length; j++){
var child = childrenList[childrenNames[j]];
console.log(`[${process.pid}]`, "Sending kill signal to PID:", child.pid);
process.kill(child.pid);
//console.log(`[${process.pid}]`, "Sending kill signal to PID:", child.pid);
try{
process.kill(child.pid);
}catch(err){
//...
}
}

if(!shutting){
try{
process.stdout.cursorTo(0);
process.stdout.write(`[PID: ${process.pid}] [Timestamp: ${new Date().getTime()}] [Process argv: ${process.argv}]- Shutting down...\n`);
}catch(err)
{
//...
}
shutting = true;
}

setTimeout(()=>{
Expand Down

0 comments on commit 2f5a9d2

Please sign in to comment.