mirror of
https://github.com/Unitech/pm2.git
synced 2026-02-01 16:57:09 +00:00
harmony options passed on runtime to NodeJS - init script modified to not execute NODE to enable option passing on startup - pm2 PID file written on .pm2 - gracefull pm2 exit
This commit is contained in:
parent
512dd0e179
commit
8dd460ba38
35
README.md
35
README.md
@ -47,7 +47,10 @@ Thanks in advance and we hope that you like pm2 !
|
||||
|
||||
# News
|
||||
|
||||
- 0.7.2 harmony, can pass options to pm2 script via PM2_NODE_OPTIONS
|
||||
- 0.7.2
|
||||
- harmony
|
||||
- can pass any options to node via PM2_NODE_OPTIONS, configurable via ~/.pm2/custom_options.sh
|
||||
- pid file is written in ~/.pm2/pm2.pid
|
||||
- 0.7.1 integrates hardened reload, graceful reload and strengthened process management
|
||||
|
||||
# Readme Contents
|
||||
@ -168,9 +171,11 @@ By default every logs (error and out), pids files, dump, pm2 logs are located in
|
||||
```
|
||||
.pm2/
|
||||
├── dump.pm2
|
||||
├── custom_options.sh
|
||||
├── pm2.log
|
||||
├── pm2.pid
|
||||
├── logs
|
||||
├── pids
|
||||
└── pm2.log
|
||||
└── pids
|
||||
```
|
||||
|
||||
<a name="a16"/>
|
||||
@ -332,9 +337,11 @@ pm2 web
|
||||
```
|
||||
|
||||
<a name="a24"/>
|
||||
## Customization
|
||||
## Configuration / Customization
|
||||
|
||||
Multiple variables can be customized via the environment :
|
||||
You can edit these options by editing the file `~/.pm2/custom_options.sh`
|
||||
|
||||
These variables can be customized :
|
||||
|
||||
```
|
||||
DAEMON_BIND_HOST : process.env.PM2_BIND_ADDR || 'localhost',
|
||||
@ -343,9 +350,12 @@ Multiple variables can be customized via the environment :
|
||||
DEBUG : process.env.PM2_DEBUG || false,
|
||||
WEB_INTERFACE : process.env.PM2_API_PORT || 9615,
|
||||
GRACEFUL_TIMEOUT : parseInt(process.env.PM2_GRACEFUL_TIMEOUT) || 4000,
|
||||
|
||||
PM2_NODE_OPTIONS : ''
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
<a name="a13"/>
|
||||
# Multi process JSON declaration
|
||||
|
||||
@ -388,7 +398,7 @@ $ pm2 start processes.json
|
||||
|
||||
Fork PM2 and to hack it it's pretty simple :
|
||||
|
||||
```
|
||||
```bash
|
||||
$ pm2 kill # kill the current pm2
|
||||
$ git clone my_pm2_fork.git
|
||||
$ cd pm2/
|
||||
@ -399,6 +409,17 @@ Everytime you do a modification on the code you have to restart pm2, so just do
|
||||
starting an app or something else.
|
||||
You have to restart it because the code is daemonized on the memory.
|
||||
|
||||
## Install pm2 development
|
||||
|
||||
```bash
|
||||
$ npm install git://github.com/Unitech/pm2#development -g
|
||||
```
|
||||
|
||||
# MISC Notes
|
||||
|
||||
- Remove init script : `sudo update-rc.d -f pm2-init.sh remove`
|
||||
|
||||
|
||||
<a name="a21"/>
|
||||
# Known bugs and workarounds
|
||||
|
||||
|
||||
41
bin/pm2
41
bin/pm2
@ -1,18 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
':' //; exec "`command -v nodejs || command -v node`" $PM2_NODE_OPTIONS "$0" "$@"
|
||||
|
||||
//
|
||||
// Harmony test
|
||||
//
|
||||
try {
|
||||
var assert = require('assert')
|
||||
, s = new Set();
|
||||
s.add('a');
|
||||
assert.ok(s.has('a'));
|
||||
console.log('ES6 Harmony succesfully enabled');
|
||||
} catch(e) {
|
||||
}
|
||||
':' // Hack to pass parameters to Node before running this file
|
||||
':' //; [ -f ~/.pm2/custom_options.sh ] && . ~/.pm2/custom_options.sh || : ; exec "`command -v nodejs || command -v node`" $PM2_NODE_OPTIONS "$0" "$@"
|
||||
|
||||
var commander = require('commander');
|
||||
var fs = require('fs');
|
||||
@ -326,9 +315,35 @@ process.on('satan:client:ready', function() {
|
||||
(function init() {
|
||||
fs.exists(cst.DEFAULT_FILE_PATH, function(exist) {
|
||||
if (!exist) {
|
||||
console.log('Initializing folder for pm2 on %s', cst.DEFAULT_FILE_PATH);
|
||||
fs.mkdirSync(cst.DEFAULT_FILE_PATH);
|
||||
fs.mkdirSync(cst.DEFAULT_LOG_PATH);
|
||||
fs.mkdirSync(cst.DEFAULT_PID_PATH);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Create configuration file if not present
|
||||
*/
|
||||
fs.exists(cst.PM2_CONF_FILE, function(exist) {
|
||||
if (!exist) {
|
||||
console.log('Creating PM2 configuration file in %s', cst.PM2_CONF_FILE);
|
||||
fs
|
||||
.createReadStream(path.join(__dirname, cst.SAMPLE_CONF_FILE))
|
||||
.pipe(fs.createWriteStream(cst.PM2_CONF_FILE));
|
||||
}
|
||||
});
|
||||
})();
|
||||
|
||||
(function testHarmony() {
|
||||
//
|
||||
// Harmony test
|
||||
//
|
||||
try {
|
||||
var assert = require('assert')
|
||||
, s = new Set();
|
||||
s.add('a');
|
||||
assert.ok(s.has('a'));
|
||||
console.log('● ES6 mode'.green);
|
||||
} catch(e) {}
|
||||
})();
|
||||
|
||||
@ -7,15 +7,20 @@ var p = require('path');
|
||||
var fs = require('fs');
|
||||
var util = require('util');
|
||||
|
||||
// Dont change this or the pm2 could not load custom_options.sh because of
|
||||
// header in bin/pm2
|
||||
DEFAULT_FILE_PATH = p.resolve(process.env.HOME, '.pm2');
|
||||
|
||||
var default_conf = {
|
||||
DEFAULT_FILE_PATH : DEFAULT_FILE_PATH,
|
||||
PM2_LOG_FILE_PATH : p.join(p.resolve(process.env.HOME, '.pm2'), 'pm2.log'),
|
||||
PM2_PID_FILE_PATH : p.join(p.resolve(process.env.HOME, '.pm2'), 'pm2.pid'),
|
||||
DEFAULT_PID_PATH : p.join(DEFAULT_FILE_PATH, 'pids'),
|
||||
DEFAULT_LOG_PATH : p.join(DEFAULT_FILE_PATH, 'logs'),
|
||||
DUMP_FILE_PATH : p.join(DEFAULT_FILE_PATH, 'dump.pm2'),
|
||||
PM2_CONF_FILE : p.join(DEFAULT_FILE_PATH, 'conf.json'),
|
||||
|
||||
SAMPLE_CONF_FILE : '../lib/custom_options.sh',
|
||||
PM2_CONF_FILE : p.join(DEFAULT_FILE_PATH, 'custom_options.sh'),
|
||||
|
||||
DAEMON_BIND_HOST : process.env.PM2_BIND_ADDR || 'localhost',
|
||||
DAEMON_RPC_PORT : parseInt(process.env.PM2_RPC_PORT) || 6666, // RPC commands
|
||||
|
||||
@ -163,7 +163,7 @@ CLI.startup = function(platform) {
|
||||
|
||||
script = script.toString().replace(/%PM2_PATH%/g, process.mainModule.filename);
|
||||
script = script.toString().replace(/%HOME_PATH%/g, process.env.HOME);
|
||||
script = script.toString().replace(/%NODE_PATH%/g, process.execPath);
|
||||
script = script.toString().replace(/%NODE_PATH%/g, p.dirname(process.execPath));
|
||||
script = script.toString().replace(/%USER%/g, commander.user || 'root');
|
||||
|
||||
console.log(cst.PREFIX_MSG + 'Generating system V init script in ' + INIT_SCRIPT);
|
||||
|
||||
17
lib/Satan.js
17
lib/Satan.js
@ -67,8 +67,25 @@ Satan.onReady = function() {
|
||||
* Daemon part
|
||||
*
|
||||
*/
|
||||
Satan.processStateHandler = function() {
|
||||
function gracefullExit() {
|
||||
console.log('pm2 has been killed by signal');
|
||||
try {
|
||||
fs.unlinkSync(cst.PM2_PID_FILE_PATH);
|
||||
} catch(e){}
|
||||
process.exit(0);
|
||||
}
|
||||
try {
|
||||
fs.writeFileSync(cst.PM2_PID_FILE_PATH, process.pid);
|
||||
} catch(e){}
|
||||
|
||||
process.on('SIGTERM', gracefullExit);
|
||||
process.on('SIGINT', gracefullExit);
|
||||
process.on('SIGQUIT', gracefullExit);
|
||||
};
|
||||
|
||||
Satan.remoteWrapper = function() {
|
||||
Satan.processStateHandler();
|
||||
|
||||
if (process.env.SILENT == 'true') {
|
||||
// Redirect output to files
|
||||
|
||||
23
lib/custom_options.sh
Normal file
23
lib/custom_options.sh
Normal file
@ -0,0 +1,23 @@
|
||||
#!/bin/bash
|
||||
|
||||
#
|
||||
# This permits to pass options to node
|
||||
# Usefull if you want to activate the --harmony options for example
|
||||
#
|
||||
# export PM2_NODE_OPTIONS='--harmony'
|
||||
|
||||
|
||||
# export DAEMON_RPC_PORT=6666
|
||||
# export DAEMON_PUB_PORT=6667
|
||||
# export DAEMON_BIND_HOST='localhost'
|
||||
|
||||
#
|
||||
# This it's the timeout used for the process to graceful exit everything
|
||||
# if it doesnt kill itself
|
||||
#
|
||||
# export GRACEFUL_TIMEOUT=4000
|
||||
|
||||
#
|
||||
# If you want to run pm2 in debug mode
|
||||
#
|
||||
# export DEBUG=false
|
||||
@ -19,10 +19,11 @@ PM2=%PM2_PATH%
|
||||
NODE=%NODE_PATH%
|
||||
USER=%USER%
|
||||
|
||||
export PATH=$PATH:%NODE_PATH%
|
||||
export HOME="%HOME_PATH%"
|
||||
|
||||
super() {
|
||||
sudo -i -u $USER $*
|
||||
sudo -Ei -u $USER PATH=$PATH $*
|
||||
}
|
||||
|
||||
start() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user