feat: 초기 프로젝트 설정 및 룰.md 파일 추가
This commit is contained in:
1033
api.hyungi.net/node_modules/pm2/lib/binaries/CLI.js
generated
vendored
Normal file
1033
api.hyungi.net/node_modules/pm2/lib/binaries/CLI.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
183
api.hyungi.net/node_modules/pm2/lib/binaries/DevCLI.js
generated
vendored
Normal file
183
api.hyungi.net/node_modules/pm2/lib/binaries/DevCLI.js
generated
vendored
Normal file
@@ -0,0 +1,183 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
process.env.PM2_NO_INTERACTION = 'true';
|
||||
// Do not print banner
|
||||
process.env.PM2_DISCRETE_MODE = true;
|
||||
|
||||
var commander = require('commander');
|
||||
|
||||
var PM2 = require('../..');
|
||||
var Log = require('../API/Log');
|
||||
var cst = require('../../constants.js');
|
||||
var pkg = require('../../package.json');
|
||||
var chalk = require('chalk');
|
||||
var path = require('path');
|
||||
var fmt = require('../tools/fmt.js');
|
||||
var exec = require('child_process').exec;
|
||||
var os = require('os');
|
||||
|
||||
commander.version(pkg.version)
|
||||
.description('pm2-dev monitor for any file changes and automatically restart it')
|
||||
.option('--raw', 'raw log output')
|
||||
.option('--timestamp', 'print timestamp')
|
||||
.option('--node-args <node_args>', 'space delimited arguments to pass to node in cluster mode - e.g. --node-args="--debug=7001 --trace-deprecation"')
|
||||
.option('--ignore [files]', 'files to ignore while watching')
|
||||
.option('--post-exec [cmd]', 'execute extra command after change detected')
|
||||
.option('--silent-exec', 'do not output result of post command', false)
|
||||
.option('--test-mode', 'debug mode for test suit')
|
||||
.option('--interpreter <interpreter>', 'the interpreter pm2 should use for executing app (bash, python...)')
|
||||
.option('--env [name]', 'select env_[name] env variables in process config file')
|
||||
.option('--auto-exit', 'exit if all processes are errored/stopped or 0 apps launched')
|
||||
.usage('pm2-dev app.js');
|
||||
|
||||
var pm2 = new PM2.custom({
|
||||
pm2_home : path.join(os.homedir ? os.homedir() : (process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE), '.pm2-dev')
|
||||
});
|
||||
|
||||
pm2.connect(function() {
|
||||
commander.parse(process.argv);
|
||||
});
|
||||
|
||||
function postExecCmd(command, cb) {
|
||||
var exec_cmd = exec(command);
|
||||
|
||||
if (commander.silentExec !== true) {
|
||||
exec_cmd.stdout.on('data', function(data) {
|
||||
process.stdout.write(data);
|
||||
});
|
||||
|
||||
exec_cmd.stderr.on('data', function(data) {
|
||||
process.stderr.write(data);
|
||||
});
|
||||
}
|
||||
|
||||
exec_cmd.on('close', function done() {
|
||||
if (cb) cb(null);
|
||||
});
|
||||
|
||||
exec_cmd.on('error', function (err) {
|
||||
console.error(err.stack || err);
|
||||
});
|
||||
};
|
||||
|
||||
function run(cmd, opts) {
|
||||
var timestamp = opts.timestamp;
|
||||
|
||||
opts.watch = true;
|
||||
opts.autostart = true;
|
||||
opts.autorestart = true;
|
||||
opts.restart_delay = 1000
|
||||
if (opts.autoExit)
|
||||
autoExit();
|
||||
|
||||
if (opts.ignore) {
|
||||
opts.ignore_watch = opts.ignore.split(',')
|
||||
opts.ignore_watch.push('node_modules');
|
||||
}
|
||||
|
||||
if (timestamp === true)
|
||||
timestamp = 'YYYY-MM-DD-HH:mm:ss';
|
||||
|
||||
pm2.start(cmd, opts, function(err, procs) {
|
||||
|
||||
if (err) {
|
||||
console.error(err);
|
||||
pm2.destroy(function() {
|
||||
process.exit(0);
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
if (opts.testMode) {
|
||||
return pm2.disconnect(function() {
|
||||
});
|
||||
}
|
||||
|
||||
fmt.sep();
|
||||
fmt.title('PM2 development mode');
|
||||
fmt.field('Apps started', procs.map(function(p) { return p.pm2_env.name } ));
|
||||
fmt.field('Processes started', chalk.bold(procs.length));
|
||||
fmt.field('Watch and Restart', chalk.green('Enabled'));
|
||||
fmt.field('Ignored folder', opts.ignore_watch || 'node_modules');
|
||||
if (opts.postExec)
|
||||
fmt.field('Post restart cmd', opts.postExec);
|
||||
fmt.sep();
|
||||
|
||||
setTimeout(function() {
|
||||
pm2.Client.launchBus(function(err, bus) {
|
||||
bus.on('process:event', function(packet) {
|
||||
if (packet.event == 'online') {
|
||||
if (opts.postExec)
|
||||
postExecCmd(opts.postExec);
|
||||
}
|
||||
});
|
||||
});
|
||||
}, 1000);
|
||||
|
||||
Log.devStream(pm2.Client, 'all', opts.raw, timestamp, false);
|
||||
|
||||
process.on('SIGINT', function() {
|
||||
console.log('>>>>> [PM2 DEV] Stopping current development session');
|
||||
pm2.delete('all', function() {
|
||||
pm2.destroy(function() {
|
||||
process.exit(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
commander.command('*')
|
||||
.action(function(cmd, opts){
|
||||
run(cmd, commander);
|
||||
});
|
||||
|
||||
commander.command('start <file|json_file>')
|
||||
.description('start target config file/script in development mode')
|
||||
.action(function(cmd, opts) {
|
||||
run(cmd, commander);
|
||||
});
|
||||
|
||||
function exitPM2() {
|
||||
if (pm2 && pm2.connected == true) {
|
||||
console.log(chalk.green.bold('>>> Exiting PM2'));
|
||||
pm2.kill(function() {
|
||||
process.exit(0);
|
||||
});
|
||||
}
|
||||
else
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
function autoExit(final) {
|
||||
setTimeout(function() {
|
||||
pm2.list(function(err, apps) {
|
||||
if (err) console.error(err.stack || err);
|
||||
|
||||
var online_count = 0;
|
||||
|
||||
apps.forEach(function(app) {
|
||||
if (app.pm2_env.status == cst.ONLINE_STATUS ||
|
||||
app.pm2_env.status == cst.LAUNCHING_STATUS)
|
||||
online_count++;
|
||||
});
|
||||
|
||||
if (online_count == 0) {
|
||||
console.log('0 application online, exiting');
|
||||
if (final == true)
|
||||
process.exit(1);
|
||||
else
|
||||
autoExit(true);
|
||||
return false;
|
||||
}
|
||||
autoExit(false);
|
||||
});
|
||||
}, 3000);
|
||||
}
|
||||
|
||||
if (process.argv.length == 2) {
|
||||
commander.outputHelp();
|
||||
exitPM2();
|
||||
}
|
||||
101
api.hyungi.net/node_modules/pm2/lib/binaries/Runtime.js
generated
vendored
Normal file
101
api.hyungi.net/node_modules/pm2/lib/binaries/Runtime.js
generated
vendored
Normal file
@@ -0,0 +1,101 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
var commander = require('commander');
|
||||
|
||||
var PM2 = require('../..');
|
||||
var Log = require('../../lib/API/Log');
|
||||
var cst = require('../../constants.js');
|
||||
var pkg = require('../../package.json');
|
||||
var path = require('path');
|
||||
|
||||
var pm2;
|
||||
|
||||
// Do not print banner
|
||||
process.env.PM2_DISCRETE_MODE = true;
|
||||
|
||||
commander.version(pkg.version)
|
||||
.description('pm2-runtime is an automatic pmx injection that runs in simulated no-daemon environment')
|
||||
.option('--auto-manage', 'keep application online after command exit')
|
||||
.option('--fast-boot', 'boot app faster by keeping pm2 runtime online in background (effective at second exit/start)')
|
||||
.option('--web [port]', 'launch process web api on [port] default to 9615')
|
||||
.option('--secret [key]', 'PM2 plus secret key')
|
||||
.option('--public [key]', 'PM2 plus public key')
|
||||
.option('--machine-name [name]', 'PM2 plus machine name')
|
||||
.option('--env [name]', 'select env_[name] env variables in process config file')
|
||||
.option('--watch', 'Watch and Restart')
|
||||
.option('-i --instances <number>', 'launch [number] instances with load-balancer')
|
||||
.usage('pm2-runtime app.js');
|
||||
|
||||
commander.command('*')
|
||||
.action(function(cmd){
|
||||
pm2 = new PM2.custom({
|
||||
pm2_home : path.join(process.env.HOME, '.pm3'),
|
||||
secret_key : cst.SECRET_KEY || commander.secret,
|
||||
public_key : cst.PUBLIC_KEY || commander.public,
|
||||
machine_name : cst.MACHINE_NAME || commander.machineName
|
||||
});
|
||||
|
||||
pm2.connect(function() {
|
||||
if (commander.web) {
|
||||
var port = commander.web === true ? cst.WEB_PORT : commander.web;
|
||||
pm2.web(port);
|
||||
}
|
||||
|
||||
pm2.start(cmd, commander, function(err, obj) {
|
||||
if (process.env.PM2_RUNTIME_DEBUG) {
|
||||
return pm2.disconnect(function() {});
|
||||
}
|
||||
|
||||
if (err) {
|
||||
console.error(err);
|
||||
return process.exit(1);
|
||||
}
|
||||
|
||||
var pm_id = obj[0].pm2_env.pm_id;
|
||||
|
||||
if (commander.instances == undefined) {
|
||||
return pm2.attach(pm_id, function() {
|
||||
exitPM2();
|
||||
});
|
||||
}
|
||||
|
||||
if (commander.json === true)
|
||||
Log.jsonStream(pm2.Client, pm_id);
|
||||
else if (commander.format === true)
|
||||
Log.formatStream(pm2.Client, pm_id, false, 'YYYY-MM-DD-HH:mm:ssZZ');
|
||||
else
|
||||
Log.stream(pm2.Client, 'all', true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
if (process.argv.length == 2) {
|
||||
commander.outputHelp();
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
process.on('SIGINT', function() {
|
||||
exitPM2();
|
||||
});
|
||||
|
||||
process.on('SIGTERM', function() {
|
||||
exitPM2();
|
||||
});
|
||||
|
||||
commander.parse(process.argv);
|
||||
|
||||
function exitPM2() {
|
||||
console.log('Exited at %s', new Date());
|
||||
if (commander.autoManage)
|
||||
return process.exit(0);
|
||||
|
||||
if (commander.fastBoot) {
|
||||
return pm2.delete('all', function() {
|
||||
process.exit(0);
|
||||
});
|
||||
}
|
||||
pm2.kill(function() {
|
||||
process.exit(0);
|
||||
});
|
||||
}
|
||||
192
api.hyungi.net/node_modules/pm2/lib/binaries/Runtime4Docker.js
generated
vendored
Normal file
192
api.hyungi.net/node_modules/pm2/lib/binaries/Runtime4Docker.js
generated
vendored
Normal file
@@ -0,0 +1,192 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Specialized PM2 CLI for Containers
|
||||
*/
|
||||
var commander = require('commander');
|
||||
var PM2 = require('../..');
|
||||
var Log = require('../../lib/API/Log');
|
||||
var cst = require('../../constants.js');
|
||||
var pkg = require('../../package.json');
|
||||
var path = require('path');
|
||||
var DEFAULT_FAIL_COUNT = 3;
|
||||
|
||||
process.env.PM2_DISCRETE_MODE = true;
|
||||
|
||||
commander.version(pkg.version)
|
||||
.description('pm2-runtime is a drop-in replacement Node.js binary for containers')
|
||||
.option('-i --instances <number>', 'launch [number] of processes automatically load-balanced. Increase overall performances and performance stability.')
|
||||
.option('--secret [key]', '[MONITORING] PM2 plus secret key')
|
||||
.option('--no-autostart', 'add an app without automatic start')
|
||||
.option('--no-autorestart', 'start an app without automatic restart')
|
||||
.option('--stop-exit-codes <exit_codes...>', 'specify a list of exit codes that should skip automatic restart')
|
||||
.option('--node-args <node_args>', 'space delimited arguments to pass to node in cluster mode - e.g. --node-args="--debug=7001 --trace-deprecation"')
|
||||
.option('-n --name <name>', 'set a <name> for script')
|
||||
.option('--max-memory-restart <memory>', 'specify max memory amount used to autorestart (in octet or use syntax like 100M)')
|
||||
.option('-c --cron <cron_pattern>', 'restart a running process based on a cron pattern')
|
||||
.option('--interpreter <interpreter>', 'the interpreter pm2 should use for executing app (bash, python...)')
|
||||
.option('--public [key]', '[MONITORING] PM2 plus public key')
|
||||
.option('--machine-name [name]', '[MONITORING] PM2 plus machine name')
|
||||
.option('--trace', 'enable transaction tracing with km')
|
||||
.option('--v8', 'enable v8 data collecting')
|
||||
.option('--format', 'output logs formated like key=val')
|
||||
.option('--raw', 'raw output (default mode)')
|
||||
.option('--formatted', 'formatted log output |id|app|log')
|
||||
.option('--json', 'output logs in json format')
|
||||
.option('--delay <seconds>', 'delay start of configuration file by <seconds>', 0)
|
||||
.option('--web [port]', 'launch process web api on [port] (default to 9615)')
|
||||
.option('--only <application-name>', 'only act on one application of configuration')
|
||||
.option('--no-auto-exit', 'do not exit if all processes are errored/stopped or 0 apps launched')
|
||||
.option('--env [name]', 'inject env_[name] env variables in process config file')
|
||||
.option('--watch', 'watch and restart application on file change')
|
||||
.option('--error <path>', 'error log file destination (default disabled)', '/dev/null')
|
||||
.option('--output <path>', 'output log file destination (default disabled)', '/dev/null')
|
||||
.option('--deep-monitoring', 'enable all monitoring tools (equivalent to --v8 --event-loop-inspector --trace)')
|
||||
.allowUnknownOption()
|
||||
.usage('app.js');
|
||||
|
||||
commander.command('*')
|
||||
.action(function(cmd){
|
||||
Runtime.instanciate(cmd);
|
||||
});
|
||||
|
||||
commander.command('start <app.js|json_file>')
|
||||
.description('start an application or json ecosystem file')
|
||||
.action(function(cmd) {
|
||||
Runtime.instanciate(cmd);
|
||||
});
|
||||
|
||||
if (process.argv.length == 2) {
|
||||
commander.outputHelp();
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
var Runtime = {
|
||||
pm2 : null,
|
||||
instanciate : function(cmd) {
|
||||
this.pm2 = new PM2.custom({
|
||||
pm2_home : process.env.PM2_HOME || path.join(process.env.HOME, '.pm2'),
|
||||
secret_key : cst.SECRET_KEY || commander.secret,
|
||||
public_key : cst.PUBLIC_KEY || commander.public,
|
||||
machine_name : cst.MACHINE_NAME || commander.machineName,
|
||||
daemon_mode : process.env.PM2_RUNTIME_DEBUG || false
|
||||
});
|
||||
|
||||
this.pm2.connect(function(err, pm2_meta) {
|
||||
process.on('SIGINT', function() {
|
||||
Runtime.exit();
|
||||
});
|
||||
|
||||
process.on('SIGTERM', function() {
|
||||
Runtime.exit();
|
||||
});
|
||||
|
||||
Runtime.startLogStreaming();
|
||||
Runtime.startApp(cmd, function(err) {
|
||||
if (err) {
|
||||
console.error(err.message || err);
|
||||
return Runtime.exit();
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Log Streaming Management
|
||||
*/
|
||||
startLogStreaming : function() {
|
||||
if (commander.json === true)
|
||||
Log.jsonStream(this.pm2.Client, 'all');
|
||||
else if (commander.format === true)
|
||||
Log.formatStream(this.pm2.Client, 'all', false, 'YYYY-MM-DD-HH:mm:ssZZ');
|
||||
else
|
||||
Log.stream(this.pm2.Client, 'all', !commander.formatted, commander.timestamp, true);
|
||||
},
|
||||
|
||||
/**
|
||||
* Application Startup
|
||||
*/
|
||||
startApp : function(cmd, cb) {
|
||||
function exec() {
|
||||
this.pm2.start(cmd, commander, function(err, obj) {
|
||||
if (err)
|
||||
return cb(err);
|
||||
if (obj && obj.length == 0)
|
||||
return cb(new Error(`0 application started (no apps to run on ${cmd})`))
|
||||
|
||||
if (commander.web) {
|
||||
var port = commander.web === true ? cst.WEB_PORT : commander.web;
|
||||
Runtime.pm2.web(port);
|
||||
}
|
||||
|
||||
if (commander.autoExit) {
|
||||
setTimeout(function() {
|
||||
Runtime.autoExitWorker();
|
||||
}, 4000);
|
||||
}
|
||||
|
||||
// For Testing purpose (allow to auto exit CLI)
|
||||
if (process.env.PM2_RUNTIME_DEBUG)
|
||||
Runtime.pm2.disconnect(function() {});
|
||||
|
||||
return cb(null, obj);
|
||||
});
|
||||
}
|
||||
// via --delay <seconds> option
|
||||
setTimeout(exec.bind(this), commander.delay * 1000);
|
||||
},
|
||||
|
||||
/**
|
||||
* Exit runtime mgmt
|
||||
*/
|
||||
exit : function(code) {
|
||||
if (!this.pm2) return process.exit(1);
|
||||
|
||||
this.pm2.kill(function() {
|
||||
process.exit(code || 0);
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Exit current PM2 instance if 0 app is online
|
||||
* function activated via --auto-exit
|
||||
*/
|
||||
autoExitWorker : function(fail_count) {
|
||||
var interval = 2000;
|
||||
|
||||
if (typeof(fail_count) =='undefined')
|
||||
fail_count = DEFAULT_FAIL_COUNT;
|
||||
|
||||
var timer = setTimeout(function () {
|
||||
Runtime.pm2.list(function (err, apps) {
|
||||
if (err) {
|
||||
console.error('Could not run pm2 list');
|
||||
return Runtime.autoExitWorker();
|
||||
}
|
||||
|
||||
var appOnline = 0;
|
||||
|
||||
apps.forEach(function (app) {
|
||||
if (!app.pm2_env.pmx_module &&
|
||||
(app.pm2_env.status === cst.ONLINE_STATUS ||
|
||||
app.pm2_env.status === cst.LAUNCHING_STATUS)) {
|
||||
appOnline++;
|
||||
}
|
||||
});
|
||||
|
||||
if (appOnline === 0) {
|
||||
console.log('0 application online, retry =', fail_count);
|
||||
if (fail_count <= 0)
|
||||
return Runtime.exit(2);
|
||||
return Runtime.autoExitWorker(--fail_count);
|
||||
}
|
||||
|
||||
Runtime.autoExitWorker();
|
||||
});
|
||||
}, interval);
|
||||
|
||||
timer.unref();
|
||||
}
|
||||
}
|
||||
|
||||
commander.parse(process.argv);
|
||||
Reference in New Issue
Block a user