Skip to content

Commit

Permalink
Unitech#2980 PM2_SILENT=true pm2 startup
Browse files Browse the repository at this point in the history
  • Loading branch information
Unitech committed Jul 2, 2017
1 parent 8bcd841 commit df0ea4f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 26 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- #2951 pm2 reload command locker via timestamped lock file
- #2977 pm2 reloadLogs protected
- #2958 Allow to delete attribute via --attribute null
- #2980 PM2_SILENT=true pm2 startup
- expose cwd on CLI via --cwd
- multiple pm2-docker enhacements
- Alias pm2.link and pm2.unlink to pm2.interact and pm2._pre_interact
Expand Down
52 changes: 26 additions & 26 deletions lib/API/Startup.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ module.exports = function(CLI) {
*/
function isNotRoot(platform, opts, cb) {
if (opts.user) {
console.log(cst.PREFIX_MSG + 'You have to run this command as root. Execute the following command:');
Common.printOut(cst.PREFIX_MSG + 'You have to run this command as root. Execute the following command:');
console.log('sudo env PATH=$PATH:' + path.dirname(process.execPath) + ' pm2 ' + opts.args[1].name() + ' ' + platform + ' -u ' + opts.user + ' --hp ' + process.env.HOME);
return cb(new Error('You have to run this with elevated rights'));
}
return exec('whoami', function(err, stdout, stderr) {
console.log(cst.PREFIX_MSG + 'You have to run this command as root. Execute the following command:');
Common.printOut(cst.PREFIX_MSG + 'You have to run this command as root. Execute the following command:');
console.log('sudo env PATH=$PATH:' + path.dirname(process.execPath) + ' ' + require.main.filename + ' ' + opts.args[1].name() + ' ' + platform + ' -u ' + stdout.trim() + ' --hp ' + process.env.HOME);
return cb(new Error('You have to run this with elevated rights'));
});
Expand Down Expand Up @@ -71,11 +71,11 @@ module.exports = function(CLI) {
if (!platform)
platform = actual_platform;
else if (actual_platform && actual_platform !== platform) {
console.log('-----------------------------------------------------------')
console.log(' PM2 detected ' + actual_platform + ' but you precised ' + platform)
console.log(' Please verify that your choice is indeed your init system')
console.log(' If you arent sure, just run : pm2 startup')
console.log('-----------------------------------------------------------')
Common.printOut('-----------------------------------------------------------')
Common.printOut(' PM2 detected ' + actual_platform + ' but you precised ' + platform)
Common.printOut(' Please verify that your choice is indeed your init system')
Common.printOut(' If you arent sure, just run : pm2 startup')
Common.printOut('-----------------------------------------------------------')
}
if (platform === null)
throw new Error('Init system not found')
Expand Down Expand Up @@ -142,8 +142,8 @@ module.exports = function(CLI) {
};

shelljs.exec(commands.join('&& '), function(code, stdout, stderr) {
console.log(stdout);
console.log(stderr);
Common.printOut(stdout);
Common.printOut(stderr);
if (code == 0) {
Common.printOut(cst.PREFIX_MSG + chalk.bold('Init file disabled.'));
} else {
Expand Down Expand Up @@ -173,11 +173,11 @@ module.exports = function(CLI) {
if (!platform)
platform = actual_platform;
else if (actual_platform && actual_platform !== platform) {
console.log('-----------------------------------------------------------')
console.log(' PM2 detected ' + actual_platform + ' but you precised ' + platform)
console.log(' Please verify that your choice is indeed your init system')
console.log(' If you arent sure, just run : pm2 startup')
console.log('-----------------------------------------------------------')
Common.printOut('-----------------------------------------------------------')
Common.printOut(' PM2 detected ' + actual_platform + ' but you precised ' + platform)
Common.printOut(' Please verify that your choice is indeed your init system')
Common.printOut(' If you arent sure, just run : pm2 startup')
Common.printOut('-----------------------------------------------------------')
}
if (platform == null)
throw new Error('Init system not found');
Expand Down Expand Up @@ -283,13 +283,13 @@ module.exports = function(CLI) {
.replace(/%USER%/g, user)
.replace(/%HOME_PATH%/g, opts.hp ? path.resolve(opts.hp, '.pm2') : cst.PM2_ROOT_PATH);

console.log(chalk.bold('Platform'), platform);
console.log(chalk.bold('Template'));
console.log(template);
console.log(chalk.bold('Target path'));
console.log(destination);
console.log(chalk.bold('Command list'));
console.log(commands);
Common.printOut(chalk.bold('Platform'), platform);
Common.printOut(chalk.bold('Template'));
Common.printOut(template);
Common.printOut(chalk.bold('Target path'));
Common.printOut(destination);
Common.printOut(chalk.bold('Command list'));
Common.printOut(commands);

Common.printOut(cst.PREFIX_MSG + 'Writing init configuration in ' + destination);
try {
Expand All @@ -303,13 +303,13 @@ module.exports = function(CLI) {
Common.printOut(cst.PREFIX_MSG + 'Making script booting at startup...');

async.forEachLimit(commands, 1, function(command, next) {
console.log(chalk.bold('>>> Executing %s'), command);
Common.printOut(chalk.bold('>>> Executing %s'), command);
shelljs.exec(command, function(code, stdout, stderr) {
if (code === 0) {
console.log(chalk.bold('[DONE] '));
Common.printOut(chalk.bold('[DONE] '));
return next();
} else {
console.log(chalk.red('[ERROR] Exit code : ' + code))
Common.printOut(chalk.red('[ERROR] Exit code : ' + code))
return next(new Error(command + ' failed, see error above.'));
}
})
Expand All @@ -318,10 +318,10 @@ module.exports = function(CLI) {
console.error(cst.PREFIX_MSG_ERR + (err.message || err));
return cb(err);
}
console.log(chalk.bold.blue('+---------------------------------------+'));
Common.printOut(chalk.bold.blue('+---------------------------------------+'));
Common.printOut(chalk.bold.blue((cst.PREFIX_MSG + 'Freeze a process list on reboot via:' )));
Common.printOut(chalk.bold('$ pm2 save'));
console.log('');
Common.printOut('');
Common.printOut(chalk.bold.blue(cst.PREFIX_MSG + 'Remove init script via:'));
Common.printOut(chalk.bold('$ pm2 unstartup ' + platform));

Expand Down

0 comments on commit df0ea4f

Please sign in to comment.