Skip to content
Snippets Groups Projects
Commit 11dca3cc authored by Cédric Moreau's avatar Cédric Moreau
Browse files

Fix #618 When making a `reset` or `sync`, automatically stop the node if it is currently running

parent 665bfa99
Branches
Tags
No related merge requests found
......@@ -452,17 +452,10 @@ program
.command('check-config')
.description('Checks the node\'s configuration')
.action(subCommand(service(function (server) {
server.checkConfig()
return server.checkConfig()
.then(function () {
logger.warn('Configuration seems correct.');
server.disconnect();
throw Error("Exiting");
})
.catch(function (err) {
logger.warn(err.message || err);
server.disconnect();
throw Error("Exiting");
});
})));
program
......@@ -522,7 +515,6 @@ program
} catch (e) {
logger.error(e);
}
return server.disconnect();
});
}, type != 'peers')(type);
}));
......@@ -830,17 +822,6 @@ function service(callback, nologs) {
};
}
function logIfErrorAndExit(server, prefix) {
return function (err) {
if (err && err.uerr) {
err = err.uerr.message;
}
err && logger.error((prefix ? prefix : "") + (err.message || err));
server.disconnect();
onResolve && onResolve();
};
}
function parsePercent(s) {
var f = parseFloat(s);
return isNaN(f) ? 0 : f;
......
......@@ -17,6 +17,19 @@ switch (process.argv[2]) {
daemon.stop();
break;
case "sync":
case "reset":
const command = process.argv[2];
if (daemon.status()) {
console.log('Stopping daemon...');
daemon.stop(function() {
launchCmd(command);
});
} else {
launchCmd(command);
}
break;
case "restart":
daemon = getDaemon('start');
daemon.stop(function(err) {
......@@ -78,6 +91,14 @@ function getFullCommand(overrideCommand) {
return [duniter].concat(getCommand(overrideCommand));
}
function launchCmd(cmd) {
let checkConf = spawn(process.argv[0], getFullCommand(cmd));
// Error messages
checkConf.stdout.on('data', (data) => console.log(data.toString('utf8')));
checkConf.stderr.on('data', (data) => console.error(data.toString('utf8')));
}
function start(daemonToStart) {
let checkConf = spawn(process.argv[0], getFullCommand('check-config'));
let echos = [];
......
......@@ -45,7 +45,7 @@ duniter() {
# DUNITER DAEMON MANAGEMENT
#---------------------------------
webwait|webstart|webstop|webrestart|start|stop|restart)
reset|webwait|webstart|webstop|webrestart|start|stop|restart)
$NODE "$DUNITER_DIR/bin/daemon" $*
;;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment