Skip to content

Commit

Permalink
add message feedback when script hasn't been created
Browse files Browse the repository at this point in the history
  • Loading branch information
Unitech committed Oct 16, 2013
1 parent 21e02e3 commit b8bab09
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion bin/pm2
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ commander.command('restartAll')
commander.command('startup [platform]')
.description('auto resurect process at startup. [platform] can be CentOS, default use update-rc.d')
.action(function(platform) {
CLI.upstart(platform);
CLI.startup(platform);
});


Expand Down
13 changes: 10 additions & 3 deletions lib/CLI.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ CLI.resurrect = function() {
})(JSON.parse(apps));
};

CLI.upstart = function(platform) {
CLI.startup = function(platform) {
if (process.getuid() != 0) {
console.error(cst.PREFIX_MSG + 'You have to run this command as root');
console.error(cst.PREFIX_MSG + 'Execute the following command :');
Expand All @@ -136,14 +136,21 @@ CLI.upstart = function(platform) {
process.exit(cst.ERROR_EXIT);
}

var INIT_SCRIPT = "/etc/init.d/pm2-init.sh";
var script = fs.readFileSync(path.join(__dirname, cst.STARTUP_SCRIPT));

script = script.toString().replace(/%PM2_PATH%/g, process.mainModule.filename);
script = script.toString().replace(/%HOME_PATH%/g, process.env.HOME);
script = script.toString().replace(/%NODE_PATH%/g, process.execPath);


var INIT_SCRIPT = "/etc/init.d/pm2-init.sh";
fs.writeFileSync(INIT_SCRIPT, script);

if (fs.existsSync(INIT_SCRIPT) == false) {
console.log(script);
console.log(cst.PREFIX_MSG_ERR + ' There is a problem when trying to write file : ' + INIT_SCRIPT);
process.exit(cst.ERROR_EXIT);
}

var exec = require('child_process').exec;

var cmd;
Expand Down

0 comments on commit b8bab09

Please sign in to comment.