Skip to content

Commit

Permalink
Merge pull request #1 from Unitech/development
Browse files Browse the repository at this point in the history
Merge development branch from Unitech/PM2
  • Loading branch information
Tjatse committed Jan 28, 2015
2 parents 202cea8 + cb4e461 commit 1eabd10
Show file tree
Hide file tree
Showing 19 changed files with 210 additions and 97 deletions.
7 changes: 3 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ branches:
- travis
node_js:
- "0.11"
- "0.11.14"
- "0.11.13"
- "0.10"
- "0.10.32"
- "0.10.31"
- "0.10.30"
- "0.10.29"
- "0.10.34"
- "0.10.33"
os:
- linux
- osx
Expand Down
32 changes: 20 additions & 12 deletions ADVANCED_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,9 @@ Yap, if the `alias` exists, you can using it as a CLI option, but do not forget
- maximum

`"instances": 0` means starting maximum processes depending on available CPUs (cluster mode)
- array

`args`, `node_args` and `ignore_watch` could be type of `Array` (e.g.: `"args": ["--toto=heya coco", "-d", "1"]`) or `string` (e.g.: `"args": "--to='heya coco' -d 1"`)

<a name="update-pm2"/>
## How to update PM2
Expand Down Expand Up @@ -715,7 +718,7 @@ Then use the command:
$ pm2 gracefulReload [all|name]
```
When PM2 starts a new process to replace an old one, it will wait for the new process to begin listening to a connection or a timeout before sending the shutdown message to the old one. You can define the timeout value with the `PM2_GRACEFUL_LISTEN_TIMEOUT` environamente variable. I f a script does not need to listen to a connection, it can manually tell PM2 that the process has started up by calling `process.send('online')`.
When PM2 starts a new process to replace an old one, it will wait for the new process to begin listening to a connection or a timeout before sending the shutdown message to the old one. You can define the timeout value with the `PM2_GRACEFUL_LISTEN_TIMEOUT` environamente variable. If a script does not need to listen to a connection, it can manually tell PM2 that the process has started up by calling `process.send('online')`.
<a name="a8"/>
## Startup script
Expand All @@ -724,7 +727,11 @@ PM2 has the amazing ability to **generate startup scripts and configure them**.
PM2 is also smart enough to **save all your process list** and to **bring back all your processes on restart**.
```bash
$ pm2 startup [ubuntu|centos|gentoo|systemd]
$ pm2 startup
# auto-detect platform
$ pm2 startup [platform]
# render startup-script for a specific platform, the [platform] could be one of:
# ubuntu|centos|redhat|gentoo|systemd|darwin
```
Once you have started the apps and want to keep them on server reboot do:
Expand All @@ -746,9 +753,10 @@ Three types of startup scripts are available:
The startup options are using:
- **ubuntu** will use `updaterc.d` and the script `lib/scripts/pm2-init.sh`
- **centos** will use `chkconfig` and the script `lib/scripts/pm2-init-centos.sh`
- **centos**/**redhat** will use `chkconfig` and the script `lib/scripts/pm2-init-centos.sh`
- **gentoo** will use `rc-update` and the script `lib/scripts/pm2`
- **systemd** will use `systemctl` and the script `lib/scripts/pm2.service`
- **darwin** will use `launchd` to load a specific `plist` to resurrect processes after reboot.
### User permissions
Expand Down Expand Up @@ -793,7 +801,7 @@ To watch specific paths, please use a JSON app declaration, `watch` can take a s
```json
{
"watch": ["server", "client"],
"ignoreWatch" : ["node_modules", "client/img"]
"ignore_watch" : ["node_modules", "client/img"]
}
```
Expand All @@ -807,9 +815,9 @@ You can define parameters for your apps in `processes.json`:
"apps" : [{
"name" : "echo",
"script" : "examples/args.js",
"args" : "['--toto=heya coco', '-d', '1']",
"args" : ["--toto=heya coco", "-d", "1"],
"log_date_format" : "YYYY-MM-DD HH:mm Z",
"ignoreWatch" : ["[\\/\\\\]\\./", "node_modules"],
"ignore_watch" : ["[\\/\\\\]\\./", "node_modules"],
"watch" : true,
"node_args" : "--harmony",
"cwd" : "/this/is/a/path/to/start/script",
Expand All @@ -820,7 +828,7 @@ You can define parameters for your apps in `processes.json`:
},{
"name" : "api",
"script" : "./examples/child.js",
"instances" : "4",
"instances" : 4,
"log_date_format" : "YYYY-MM-DD",
"log_file" : "./examples/child.log",
"error_file" : "./examples/child-err.log",
Expand All @@ -831,7 +839,7 @@ You can define parameters for your apps in `processes.json`:
},{
"name" : "auto-kill",
"script" : "./examples/killfast.js",
"min_uptime" : "100",
"min_uptime" : "100s",
"exec_mode" : "fork_mode"
}]
}
Expand Down Expand Up @@ -870,11 +878,11 @@ Note that if you execute `pm2 start node-app-2` again, it will spawn an addition
- **cwd:** your JSON declaration does not need to reside with your script. If you wish to maintain the JSON(s) in a location other than your script (say, `/etc/pm2/conf.d/node-app.json`) you will need to use the cwd feature. (Note, this is especially helpful for capistrano style directory structures that use symlinks.) Files can be either relative to the cwd directory, or absolute (example below.)
- The following are valid options for JSON app declarations:
```
```json
[{
"name" : "node-app",
"cwd" : "/srv/node-app/current",
"args" : "['--toto=heya coco', '-d', '1']",
"args" : ["--toto=heya coco", "-d", "1"]",
"script" : "bin/app.js",
"node_args" : ["--harmony", " --max-stack-size=102400000"],
"log_date_format" : "YYYY-MM-DD HH:mm Z",
Expand All @@ -887,7 +895,7 @@ Note that if you execute `pm2 start node-app-2` again, it will spawn an addition
"max_memory_restart": "1M", // 1 megabytes, e.g.: "2G", "10M", "100K", 1024... the default unit is byte.
"cron_restart" : "1 0 * * *",
"watch" : false,
"ignoreWatch" : ["[\\/\\\\]\\./", "node_modules"],
"ignore_watch" : ["[\\/\\\\]\\./", "node_modules"],
"merge_logs" : true,
"exec_interpreter" : "node",
"exec_mode" : "fork",
Expand Down Expand Up @@ -1213,7 +1221,7 @@ $ pm2 start my_app.js --node-args="--harmony"
And with JSON declaration:
```bash
```json
[{
"name" : "ES6",
"script" : "es6.js",
Expand Down
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ Node.js 0.11.14 is recommended for cluster mode and reload feature.

```bash
$ pm2 start app.js
$ pm2 start app.js -i max # Enable load-balancer and cluster features
```

## Main features
Expand Down Expand Up @@ -83,6 +82,8 @@ $ pm2 flush # Clear all the logs

When an app is started with the -i <worker number> option, the **cluster** mode is enabled.

Please take in account that this feature is still in beta.

With the cluster mode, PM2 enables load balancing between each worker.
Each HTTP/TCP/UDP request will be forwarded to one specific process at a time.

Expand All @@ -97,7 +98,11 @@ $ pm2 reload all # Reload all apps in 0s manner
PM2 can generate and configure a startup script to keep PM2 and your processes alive at every server restart.

```bash
$ pm2 startup <ubuntu|centos|gentoo|systemd>
$ pm2 startup
# auto-detect platform
$ pm2 startup [platform]
# render startup-script for a specific platform, the [platform] could be one of:
# ubuntu|centos|redhat|gentoo|systemd|darwin
```

To save a process list just do:
Expand All @@ -112,7 +117,9 @@ $ pm2 save

We're going to release a very nice product, a dashboard to monitor every part of your Node.js applications. Here are some links:

- [Pitch + Survey](https://docs.google.com/forms/d/1FuCjIhrGg-ItxInq2nLreoe9GS-gZWJNkNWE0JJajw8/viewform) People who fill the survey will be eligible for free license
- [Register](https://app.keymetrics.io/#/register)

<!-- - [Pitch + Survey](https://docs.google.com/forms/d/1FuCjIhrGg-ItxInq2nLreoe9GS-gZWJNkNWE0JJajw8/viewform) People who fill the survey will be eligible for free license -->

Thanks in advance and we hope that you like PM2!

Expand All @@ -122,7 +129,7 @@ Thanks in advance and we hope that you like PM2!
- [JSON application declaration](https://github.com/Unitech/PM2/blob/development/ADVANCED_README.md#a10)
- [Using PM2 in your code](https://github.com/Unitech/PM2/blob/development/ADVANCED_README.md#programmatic-example)
- [Deployment workflow](https://github.com/Unitech/PM2/blob/development/ADVANCED_README.md#deployment)
- [Startup script generation (SystemV/Ubuntu/Gentoo/AWS)](https://github.com/Unitech/PM2/blob/development/ADVANCED_README.md#a8)
- [Startup script generation (SystemV/Ubuntu/Gentoo/AWS)](https://github.com/Unitech/PM2/blob/master/ADVANCED_README.md#startup-script)
- [Advanced log management (flush, reload, ilogs)](https://github.com/Unitech/PM2/blob/development/ADVANCED_README.md#9)
- [GracefullReload](https://github.com/Unitech/PM2/blob/development/ADVANCED_README.md#a690)

Expand Down
7 changes: 4 additions & 3 deletions bin/pm2
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var Satan = require('../lib/Satan');
var CLI = require('../lib/CLI');
var cst = require('../constants.js');
var pkg = require('../package.json');
var platform = require('os').platform();

CLI.pm2Init();

Expand Down Expand Up @@ -364,10 +365,10 @@ commander.command('resurrect')
//
// Set pm2 to startup
//
commander.command('startup <platform>')
commander.command('startup [platform]')
.description('auto resurrect process at startup. [platform] = ubuntu, centos, gentoo or systemd')
.action(function(platform) {
CLI.startup(platform, commander);
.action(function(_platform, cmd) {
CLI.startup(_platform || platform, commander);
});


Expand Down
1 change: 1 addition & 0 deletions constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ var csts = {
SYSTEMD_STARTUP_SCRIPT : '../lib/scripts/pm2.service',
AMAZON_STARTUP_SCRIPT : '../lib/scripts/pm2-init-amazon.sh',
GENTOO_STARTUP_SCRIPT : '../lib/scripts/pm2',
DARWIN_STARTUP_SCRIPT : '../lib/scripts/io.keymetrics.PM2.plist',

SUCCESS_EXIT : 0,
ERROR_EXIT : 1,
Expand Down
11 changes: 11 additions & 0 deletions doc/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# 0.12.4

- Never start a process that already has a PID [#938]
- 1. Make platform auto detecting. 2. Support darwin startup script. [#936]
- Fix #857 #935, add scriptArgs back [d61d710]
- Fix broken link upstart [f8ff296]
- Fixed: multiple calls to vizion.parse() for the same process [0e798b1]
- fix 2015 test easter egg - Happy New Year! [85d11d5]
- fixes #906 [#911]
- add back automatic coffee interpreter #488 #901 [e9a69fe]

# 0.12.3

- fixed critical bug: `process.env` flattens all env-vars [#898]
Expand Down
3 changes: 2 additions & 1 deletion examples/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ process.argv.forEach(function (val, index, array) {
console.log(index + ': ' + val);
});

console.log('Argv2 = ', process.argv[2]);

setInterval(function() {
console.log('HERE ARE MY ARGS !!! = ', process.argv);
}, 800);

7 changes: 7 additions & 0 deletions examples/axm/probes.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,14 @@ setInterval(function() {
}, 1500);


axm.catchAll();

axm.action('throw error', function(reply) {
setTimeout(function() {
console.log('log message from echo auto kill');
throw new Error('Exitasdsadasdsda unacepted 222222 !!');
}, 2000);
});


axm.action('dec', function(reply) {
Expand Down
11 changes: 11 additions & 0 deletions examples/start-args.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@


var pm2 = require('..');

pm2.connect(function() {
pm2.start(__dirname + '/args.js', {
scriptArgs : ['-i', 'sisi', '-x', 'toto']
}, function(err, res) {
console.log(arguments);
});
});
Loading

0 comments on commit 1eabd10

Please sign in to comment.