Skip to content

Commit

Permalink
Merge pull request #16 from Tjatse/next
Browse files Browse the repository at this point in the history
Next
  • Loading branch information
Tjatse committed Mar 9, 2015
2 parents 488f195 + 78843eb commit 85b2646
Show file tree
Hide file tree
Showing 32 changed files with 584 additions and 262 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
0.0.9
**Breaking Changes**
- Using `.ini` config file instead of `.json`.

**Bugs**
- Warning messages of initialization.
- Running behind proxy / sub-domain.

**Enhancements**
- Restart / Delete / Stop / Save all processes.
102 changes: 84 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ An elegant web interface for Unitech/PM2.
- [Configs](#cli_confs)
- [Authorization](#auth)
- [UI/UX](#ui)
- [Serving apps locally with nginx and custom domain](#serv)

<a name="feats" />
# Features
Expand Down Expand Up @@ -65,6 +66,12 @@ $ npm install -g pm2-gui
Start the web server, by specific port (8090):
$ pm2-gui start 8090
Start the web server, by specific configuration file (pm2-gui.ini):
$ pm2-gui start --config
Start the web server, by specific configuration file:
$ pm2-gui start --config my-config.ini
```

<a name="cli_web" />
Expand All @@ -75,41 +82,47 @@ $ npm install -g pm2-gui
Options:

-h, --help output usage information
--config [file] pass JSON config file with options
--no-debug hide stdout/stderr information
--config path to custom .json config. Default value pm2-gui.json
--config [file] pass ".ini" configuration file (with options)
--no-debug hide stdout / stderr information
```

**Daemonic:**
```bash
# start
$ nohup pm2-gui start > /dev/null 2>&1 & echo $! > /path/to/pm2-gui.pid
# stop
$ kill -9 `cat /path/to/pm2-gui.pid`
```

<a name="cli_confs" />
## Configs
```javascript
{
"refresh": 3000,
"manipulation": true,
"pm2": "~/.pm2",
"port": 8088
}
```ini
pm2 = ~/.pm2
refresh = 5000
debug = false
port = 8088
```

- **refresh** The heartbeat duration of monitor (backend), `5000` by default.
- **manipulation** A value indicates whether the client has permission to restart/stop processes, `true` by default.
- **pm2** Root directory of Unitech/PM2, `~/.pm2` by default.
- **port** Port of web interface.
- **debug** A value indicates whether show the debug information, `true` by default.
- **password** The encrypted authentication code, if this config is set, users need to be authorized before accessing the index page, `password` could only be set by `pm2-gui set password [password]` ([authorization](#authorization)).

### Config file
You can quit set configurations by `pm2-gui start --config [file]`, the `[file]` must be an valid JSON, and can including all the above keys.
### File
You can quick set configurations by `pm2-gui start --config [file]`, the `[file]` must be a valid **ini** file, and can include all the above keys.

Example
```bash
# Load the JSON configured file which is named as `pm2-gui.json` in current directory.
# Load the configuration file which is named as `pm2-gui.ini` in current directory.
$ pm2-gui start --config

# Load the specific JSON configured file in current directory.
$ pm2-gui start --config conf.json
# Load the specific configuration file under current directory, `.ini` postfix is optional.
$ pm2-gui start --config conf
$ pm2-gui start --config conf.ini
```

### Set Config
### Set
Usage
```bash
$ pm2-gui set <key> <value>
Expand All @@ -122,7 +135,7 @@ $ pm2-gui set refresh 2000

Above command will set `refresh` to 2 seconds.

### Remove Config
### Remove
Usage
```bash
$ pm2-gui rm <key>
Expand All @@ -135,6 +148,18 @@ $ pm2-gui rm refresh

Above command will remove `refresh` config and it will be set to `5000` (milliseconds) by default.

### Update via `vi`
```bash
$ vi $PM2_ROOT/.pm2/pm2-gui.ini
```

### Cleanup
```bash
$ rm $PM2_ROOT/.pm2/pm2-gui.ini
```

> The value of `$PM2_ROOT` is `~/` by default.
<a name="auth" />
# Authorization
Run the following commands:
Expand Down Expand Up @@ -188,6 +213,47 @@ Tail Logs

![image](screenshots/logs.jpg)

<a name="serv" />
# Serving apps locally with nginx and custom domain

```ini
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}

upstream pm2-gui {
server 127.0.0.1:8000;
}

server {
listen 80;
server_name pm2-gui.dev;

#useless but can not get rid of.
root /path/to/pm2-gui/web/public;

try_files $uri/index.html $uri.html $uri @app;

# paths
location @app {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;

proxy_pass http://pm2-gui;
}

# socket.io
location /socket.io {
proxy_pass http://pm2-gui;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
}
```

## Test
```bash
$ npm test
Expand Down
26 changes: 18 additions & 8 deletions bin/pm2-gui
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var commander = require('commander'),
pkg = require('../package.json'),
Monitor = require('../lib/mon'),
crypto = require('crypto'),
conf = require('../lib/util/conf'),
interface = require('../web/index');

commander.version(pkg.version, '-v, --version')
Expand All @@ -19,35 +20,44 @@ commander.on('--help', function(){
chalk.grey(' $ pm2-gui start\n') +
'\n' +
' Start the web server, by specific port (8090):\n' +
chalk.grey(' $ pm2-gui start 8090\n')
chalk.grey(' $ pm2-gui start 8090\n') +
'\n' +
' Start the web server, by specific configuration file (pm2-gui.ini):\n' +
chalk.grey(' $ pm2-gui start --config\n') +
'\n' +
' Start the web server, by specific configuration file:\n' +
chalk.grey(' $ pm2-gui start --config my-config.ini\n')
);
});

/**
* Run web interface.
*/
commander.command('start [port]')
.option('--config [file]', 'pass JSON config file with options')
.option('--config [file]', 'pass ".ini" configuration file (with options)')
.option('--no-debug', 'hide stdout / stderr information')
.description('Launch the web server, port default by 8088')
.action(function(port, cmd){
if (cmd.config) {
var jsonFile;
if (typeof cmd.config != 'string') {
jsonFile = 'pm2-gui.json';
jsonFile = 'pm2-gui.ini';
} else {
jsonFile = cmd.config;
if (jsonFile.indexOf('.') < 0) {
jsonFile += '.ini';
}
}
if (!fs.existsSync(jsonFile)) {
console.log(chalk.red('✘ JSON configured file does not exist!\n'));
console.log(chalk.red('✘ .ini configuration file does not exist!\n'));
process.exit();
}

try {
var config = JSON.parse(fs.readFileSync(jsonFile, {encoding: 'utf-8'}));
var config = conf.File(path.resolve(process.cwd(), jsonFile)).loadSync().valueOf();
setConfig(config);
} catch (err) {
console.log(chalk.red('✘ JSON configured file is invalid!\n'));
console.log(chalk.red('✘ .ini configuration file is invalid!\n'));
process.exit();
}
}
Expand Down Expand Up @@ -90,7 +100,7 @@ if (process.argv.length == 2) {
function setConfig(key, value){
var mon = Monitor(),
acceptKeys = Object.keys(mon.options).filter(function(key){
return !~['socketio', 'pm2Conf', 'debug'].indexOf(key);
return !~['socketio', 'pm2Conf'].indexOf(key);
});

acceptKeys.push('password');
Expand Down Expand Up @@ -124,7 +134,7 @@ function showConfigs(cmd, mon){
if (!mon) {
mon = Monitor();
}
var storage = mon._config.store, prints = '';
var storage = mon._config.valueOf(), prints = '';
var maxLen = 0;
for (var k in storage) {
maxLen = Math.max(k.length, maxLen);
Expand Down
Loading

0 comments on commit 85b2646

Please sign in to comment.