Merge branch 'AlexeyKhristov-master' into development
--config option of `pm-gui start`
This commit is contained in:
commit
0cf77151ce
19
README.md
19
README.md
|
|
@ -76,15 +76,17 @@ $ npm install -g pm2-gui
|
|||
|
||||
-h, --help output usage information
|
||||
--no-debug hide stdout/stderr information
|
||||
--config path to custom .json config. Default value pm2-gui.json
|
||||
```
|
||||
|
||||
<a name="cli_confs" />
|
||||
## Configs
|
||||
```javascript
|
||||
{
|
||||
"refresh": 3000
|
||||
"manipulation": true
|
||||
"pm2": "~/.pm2"
|
||||
"refresh": 3000,
|
||||
"manipulation": true,
|
||||
"pm2": "~/.pm2",
|
||||
"port": 8088
|
||||
}
|
||||
```
|
||||
|
||||
|
|
@ -92,6 +94,17 @@ $ npm install -g pm2-gui
|
|||
- **manupulation** A value indicates whether the client has permission to restart/stop processes, `true` by default.
|
||||
- **pm2** Root directory of Unitech/PM2, `~/.pm2` by default.
|
||||
- **password** The encrypted authentication code, if this config is set, users need to be authorized before accessing the index page.
|
||||
- **port** Web GUI port, can be set only from config file
|
||||
|
||||
### Config file
|
||||
Config file can be set with option --config
|
||||
|
||||
Example
|
||||
```bash
|
||||
$ pm2-gui start --config pm2-gui.json
|
||||
```
|
||||
|
||||
If config name pm2-gui.json - option can be omitted
|
||||
|
||||
### Set Config
|
||||
Usage
|
||||
|
|
|
|||
54
bin/pm2-gui
54
bin/pm2-gui
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
var commander = require('commander'),
|
||||
path = p = require('path'),
|
||||
fs = require('fs'),
|
||||
chalk = require('chalk'),
|
||||
_ = require('lodash'),
|
||||
pkg = require('../package.json'),
|
||||
|
|
@ -25,17 +26,68 @@ commander.on('-c', function(){
|
|||
console.log(arguments);
|
||||
})
|
||||
|
||||
var defaultConfigFileName = 'pm2-gui.json';
|
||||
var acceptKeys = ['pm2', 'refresh', 'manipulation', 'password'];
|
||||
|
||||
// Web interface
|
||||
commander.command('start [port]')
|
||||
.option('--config <file>', 'pass json config file with options')
|
||||
.option('--no-debug', 'hide stdout/stderr information')
|
||||
.description('Launch the web server, port default by 8088')
|
||||
.action(function(port, cmd){
|
||||
|
||||
function setupOptions(jsonConfig) {
|
||||
var mon = Monitor();
|
||||
var passwordKeyName = acceptKeys[acceptKeys.length - 1];
|
||||
acceptKeys.forEach(function(keyName) {
|
||||
var value = jsonConfig[keyName];
|
||||
if (!value) {
|
||||
return;
|
||||
}
|
||||
if (keyName === passwordKeyName) {
|
||||
var md5 = crypto.createHash('md5');
|
||||
md5.update(value);
|
||||
value = md5.digest('hex');
|
||||
}
|
||||
mon.config(keyName, value);
|
||||
});
|
||||
}
|
||||
|
||||
var configData;
|
||||
if (cmd.config){ //if config file passed
|
||||
|
||||
try {
|
||||
configData = fs.readFileSync(cmd.config);
|
||||
} catch (e) {
|
||||
if (e.code === 'ENOENT') {
|
||||
console.log('Config file %s not found', cmd.config);
|
||||
process.exit(1);
|
||||
} else {
|
||||
console.log('Error read config file %s, error: %j', cmd.config, err);
|
||||
process.exit(2);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
configData = fs.readFileSync(defaultConfigFileName);
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
try {
|
||||
var jsonConfig = JSON.parse(configData);
|
||||
setupOptions(jsonConfig);
|
||||
} catch (e) {
|
||||
console.log('Cant convert file %s to JSON', cmd.config);
|
||||
process.exit(3);
|
||||
}
|
||||
|
||||
if (!port && jsonConfig.port) { // setup port from config file
|
||||
port = jsonConfig.port;
|
||||
}
|
||||
interface(port, cmd.debug);
|
||||
});
|
||||
|
||||
// Configuration
|
||||
var acceptKeys = ['pm2', 'refresh', 'manipulation', 'password'];
|
||||
function showConfigs(cmd, mon){
|
||||
if (!mon) {
|
||||
mon = Monitor();
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "pm2-gui",
|
||||
"version": "0.0.7",
|
||||
"version": "0.0.8",
|
||||
"description": "An elegant web interface for Unitech/PM2.",
|
||||
"scripts": {
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in New Issue