statful-relay
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -60,2 +60,3 @@ var Config = require('../lib/config/config.js'); | ||
pm2.start({ | ||
name: 'statful-relay', | ||
script: 'statful-relay', | ||
@@ -79,6 +80,50 @@ args: 'start ' + configPath | ||
var stopManaged = function() { | ||
return new Promise(function(resolve, reject) { | ||
pm2.connect(function(err) { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
pm2.stop('statful-relay', | ||
function(err) { | ||
pm2.disconnect(); | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(); | ||
} | ||
}); | ||
} | ||
}); | ||
}); | ||
}; | ||
var restartManaged = function() { | ||
return new Promise(function(resolve, reject) { | ||
pm2.connect(function(err) { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
pm2.restart('statful-relay', | ||
function(err) { | ||
pm2.disconnect(); | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(); | ||
} | ||
}); | ||
} | ||
}); | ||
}); | ||
}; | ||
module.exports = { | ||
generateConfig: generateConfig, | ||
start: start, | ||
startManaged: startManaged | ||
startManaged: startManaged, | ||
stopManaged: stopManaged, | ||
restartManaged: restartManaged | ||
}; |
@@ -10,8 +10,12 @@ var yargs = require('yargs'); | ||
.command('start-managed <path>', 'Start the Statful Relay, managed by pm2, with a config on the given path.') | ||
.command('stop-managed', 'Stop the Statful Relay, managed by pm2.') | ||
.command('restart-managed', 'Restart the Statful Relay, managed by pm2.') | ||
.demand(1) | ||
.strict() | ||
.example('$0 generate-config /etc/statful-relay/conf', 'Generates a default Statful Relay ' + | ||
'config file on /etc/statful-relay/conf/ with name statful-relay-conf.json') | ||
'config file on /etc/statful-relay/conf/ with name statful-relay-conf.json') | ||
.example('$0 start /etc/statful-relay/conf/statful-relay-conf.json', 'Starts the Statful Relay with the given config.') | ||
.example('$0 start-managed /etc/statful-relay/conf/statful-relay-conf.json', 'Starts the Statful Relay, managed by pm2, with the given config.') | ||
.example('$0 stop-managed', 'Stops the Statful Relay, managed by pm2.') | ||
.example('$0 restart-managed', 'Restarts the Statful Relay, managed by pm2.') | ||
.help('help') | ||
@@ -44,2 +48,20 @@ .alias('h', 'help') | ||
); | ||
} else if (argv._[0] === 'stop-managed') { | ||
Commands.stopManaged().then( | ||
function() { | ||
return console.log('Pm2 successfully stopped for Statful Relay process.'); | ||
}, | ||
function(error) { | ||
return console.error(error); | ||
} | ||
); | ||
} else if (argv._[0] === 'restart-managed') { | ||
Commands.restartManaged().then( | ||
function() { | ||
return console.log('Pm2 successfully restarted for Statful Relay process.'); | ||
}, | ||
function(error) { | ||
return console.error(error); | ||
} | ||
); | ||
} else if (argv._[0] === 'generate-config') { | ||
@@ -46,0 +68,0 @@ Commands.generateConfig(path).then( |
@@ -16,3 +16,3 @@ { | ||
}, | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"dependencies": { | ||
@@ -19,0 +19,0 @@ "bluebird": "3.4.6", |
28372
627
165