* If command is launched without root right * Display helper
(startup_mode, platform, opts, cb)
| 20 | * Display helper |
| 21 | */ |
| 22 | function isNotRoot(startup_mode, platform, opts, cb) { |
| 23 | Common.printOut(`${cst.PREFIX_MSG}To ${startup_mode} the Startup Script, copy/paste the following command:`); |
| 24 | |
| 25 | let pm2_bin_path = require.main.filename |
| 26 | |
| 27 | if (pm2_bin_path.includes('/lib/binaries/CLI.js') === true) { |
| 28 | pm2_bin_path = pm2_bin_path.replace('/lib/binaries/CLI.js', '/bin/pm2') |
| 29 | } |
| 30 | |
| 31 | if (opts.user) { |
| 32 | console.log('sudo env PATH=$PATH:' + path.dirname(process.execPath) + ' pm2 ' + opts.args[1].name() + ' ' + platform + ' -u ' + opts.user + ' --hp ' + process.env.HOME); |
| 33 | return cb(new Error('You have to run this with elevated rights')); |
| 34 | } |
| 35 | return sexec('whoami', {silent: true}, function(err, stdout, stderr) { |
| 36 | console.log('sudo env PATH=$PATH:' + path.dirname(process.execPath) + ' ' + pm2_bin_path + ' ' + opts.args[1].name() + ' ' + platform + ' -u ' + stdout.trim() + ' --hp ' + process.env.HOME); |
| 37 | return cb(new Error('You have to run this with elevated rights')); |
| 38 | }); |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Detect running init system |
no test coverage detected
searching dependent graphs…