├── LICENSE ├── examples ├── v1 │ ├── auto-save.js │ ├── killfast.js │ ├── modulechild.js │ ├── env_args.js │ ├── infinite-recurse.js │ ├── echo.coffee │ ├── stop-after5.js │ ├── apps │ │ ├── no-name-echo.json │ │ ├── auto-kill-echo.json │ │ ├── default-path-echo.json │ │ ├── killfast.json │ │ ├── args.json │ │ ├── cron-pm2.json │ │ ├── multi-pm2.json │ │ ├── cluster-pm2.json │ │ ├── echo-pm2.json │ │ ├── all-pm2.json │ │ └── env-pm2.json │ ├── child.js-pm2.json │ ├── string-crash.js │ ├── killslow.js │ ├── moduleparent.js │ ├── env.js │ ├── kill-slow.js │ ├── throw.js │ ├── killtoofast.js │ ├── inside.json │ ├── sendmsg.js │ ├── sigint.js │ ├── kill-not-so-fast.js │ ├── cwd.js │ ├── child-env.js │ ├── child-pm2.json │ ├── require.js │ ├── child2.js │ ├── harmony.js │ ├── leak.js │ ├── inside.js │ ├── exec_watch.json │ ├── json.js │ ├── echokill.js │ ├── 001-test.js │ ├── start-args.js │ ├── auto-restart-all.js │ ├── args.js │ ├── echo.js │ ├── child.js │ ├── expose_method.js │ ├── tree.js │ ├── interact.js │ ├── beforeExit.js │ ├── null.js │ ├── child-echo.json │ ├── auto-restart-threshold.js │ ├── package.json │ ├── malformated.json │ ├── udp.js │ ├── graceful-exit.js │ ├── exit.js │ ├── process.json │ ├── programmatic.js │ └── wrap.js ├── extra-lang │ ├── echo.rb │ ├── bashscript.sh │ ├── echo.php │ └── echo.py ├── binary │ ├── ls │ ├── ls.yml │ ├── http.js │ └── ecosystem.json ├── transpilers │ ├── echo.ls │ ├── echo.coffee │ ├── echo.ts │ └── http.ts ├── pmx │ ├── elements │ │ ├── error.js │ │ ├── log-cluster.js │ │ ├── log.js │ │ ├── notify.js │ │ ├── event.js │ │ ├── meter.js │ │ ├── counter.js │ │ ├── histogram.js │ │ ├── metric.js │ │ ├── trace.js │ │ ├── cluster.js │ │ └── http.js │ └── app.js ├── keymetrics-integration │ ├── pid_info.js │ ├── event.js │ ├── throw.js │ ├── auto-init.js │ ├── process-transpose.js │ ├── custom_action.js │ ├── scoped-actions.js │ ├── custom_action_with_params.js │ ├── keymetrics-load.js │ ├── pm2_probe.js │ ├── keymetrics-test.js │ └── actions-fibonacci.js ├── throw.js ├── process-file │ ├── connection_check.sh │ ├── worker.js │ ├── http.js │ ├── process.json │ └── process.config.js ├── promise_rejection.js ├── process-actions.js ├── remote-action.js ├── wait-ready │ ├── ecosystem.json │ └── app.js ├── echo.js ├── process-metrics.js ├── custom-action │ ├── index.js │ └── package.json ├── tcp.js ├── custom-nodejs-version │ ├── ecosystem.config.js │ └── http.js ├── module-init │ ├── package.json │ └── index.js ├── signals │ └── http.js ├── graceful-http.js ├── module-sample │ └── package.json └── http.js ├── .gitattributes ├── test ├── fixtures │ ├── process.json │ ├── watcher │ │ ├── donotwatchme.dir │ │ │ └── .gitkeep │ │ ├── watchme.sym │ │ ├── server-watch.bak.js │ │ ├── server-watch.js │ │ └── server-watch.json │ ├── git │ │ ├── COMMIT_EDITMSG │ │ ├── HEAD │ │ ├── refs │ │ │ ├── heads │ │ │ │ └── master │ │ │ └── remotes │ │ │ │ └── origin │ │ │ │ └── master │ │ ├── index │ │ ├── description │ │ ├── objects │ │ │ ├── 5d │ │ │ │ └── a45b6659e5cba8f444616f4e18529ad5dde72f │ │ │ ├── 7a │ │ │ │ └── e6d7c64d39da2167c33993e1f4f0233e8eb6f0 │ │ │ └── e6 │ │ │ │ └── 9de29bb2d1d6434b8b29ae775ad8c2e48c5391 │ │ ├── logs │ │ │ ├── HEAD │ │ │ └── refs │ │ │ │ ├── remotes │ │ │ │ └── origin │ │ │ │ │ └── master │ │ │ │ └── heads │ │ │ │ └── master │ │ ├── hooks │ │ │ ├── post-update.sample │ │ │ ├── pre-applypatch.sample │ │ │ ├── applypatch-msg.sample │ │ │ └── commit-msg.sample │ │ ├── info │ │ │ └── exclude │ │ └── config │ ├── log-json │ │ ├── one-echo.js │ │ └── ecosystem.json │ ├── serve │ │ ├── index.html │ │ ├── 404.html │ │ └── ecosystem.json │ ├── toto.js │ ├── binary-py-file.py │ ├── module-fixture │ │ ├── node_modules │ │ │ └── pmx │ │ │ │ ├── test │ │ │ │ ├── transaction.pmx.js │ │ │ │ ├── fixtures │ │ │ │ │ ├── scoped-action.mocha.js │ │ │ │ │ ├── module │ │ │ │ │ │ ├── module.fixture.js │ │ │ │ │ │ └── package.json │ │ │ │ │ ├── notify.mock.js │ │ │ │ │ ├── notify_catch_all.mock.js │ │ │ │ │ ├── scoped-action.fixture.js │ │ │ │ │ ├── monitor.mock.js │ │ │ │ │ ├── monitor2.mock.js │ │ │ │ │ ├── transpose.fixture.js │ │ │ │ │ └── histogram.fixture.js │ │ │ │ ├── mocha.opts │ │ │ │ ├── event.mock.js │ │ │ │ ├── proc.mock.js │ │ │ │ ├── proc-option.mock.js │ │ │ │ ├── express │ │ │ │ │ ├── package.json │ │ │ │ │ └── app.js │ │ │ │ ├── transaction │ │ │ │ │ ├── package.json │ │ │ │ │ └── app.mock.auto.js │ │ │ │ ├── helpers │ │ │ │ │ └── plan.js │ │ │ │ ├── pmx.mocha.js │ │ │ │ └── event.mocha.js │ │ │ │ ├── node_modules │ │ │ │ ├── json-stringify-safe │ │ │ │ │ ├── .npmignore │ │ │ │ │ ├── test │ │ │ │ │ │ └── mocha.opts │ │ │ │ │ ├── CHANGELOG.md │ │ │ │ │ ├── LICENSE │ │ │ │ │ ├── Makefile │ │ │ │ │ └── stringify.js │ │ │ │ └── debug │ │ │ │ │ ├── .jshintrc │ │ │ │ │ ├── .npmignore │ │ │ │ │ ├── node_modules │ │ │ │ │ └── ms │ │ │ │ │ │ ├── .npmignore │ │ │ │ │ │ ├── README.md │ │ │ │ │ │ └── LICENSE │ │ │ │ │ ├── component.json │ │ │ │ │ ├── bower.json │ │ │ │ │ └── Makefile │ │ │ │ ├── index.js │ │ │ │ ├── .npmignore │ │ │ │ ├── lib │ │ │ │ ├── common.js │ │ │ │ ├── utils │ │ │ │ │ ├── units.js │ │ │ │ │ ├── probes │ │ │ │ │ │ ├── Counter.js │ │ │ │ │ │ └── Meter.js │ │ │ │ │ ├── transport.js │ │ │ │ │ ├── proxy.js │ │ │ │ │ └── EWMA.js │ │ │ │ ├── probes │ │ │ │ │ └── pacemaker.js │ │ │ │ └── events.js │ │ │ │ ├── .travis.yml │ │ │ │ ├── CHANGELOG.md │ │ │ │ └── examples │ │ │ │ └── package.json │ │ └── package.json │ ├── path1 │ │ ├── iminpath1.js │ │ └── path2 │ │ │ └── iminpath2.js │ ├── throw.js │ ├── binary-js-file │ ├── binary-js-file.js │ ├── bashscript.sh │ ├── cron.js │ ├── yaml-configuration │ │ ├── malformated.yml │ │ ├── echo.js │ │ ├── echo.py │ │ ├── apps.yml │ │ ├── apps.yaml │ │ └── child.js │ ├── echo.coffee │ ├── killnotsofast.js │ ├── start-consistency │ │ ├── child.json │ │ └── child.js │ ├── app-config-update │ │ ├── args1.json │ │ ├── args2.json │ │ └── echo.js │ ├── env.js │ ├── interpreter │ │ ├── echo.coffee │ │ ├── echo.ls │ │ └── echo.ts │ ├── throw-string.js │ ├── echo-pm2.json │ ├── js-configuration │ │ └── app.js │ ├── echoto-pm2.json │ ├── insidePm2Process.js │ ├── echo-env.js │ ├── echo-to-pm2.json │ ├── harmony.json │ ├── quit.js │ ├── env-switching │ │ ├── child.js │ │ └── app.json │ ├── killtoofast.js │ ├── json-reload │ │ ├── echo-env.js │ │ ├── max-mem-0.json │ │ ├── max-mem.json │ │ ├── big-array.js │ │ ├── echo-pre.json │ │ └── echo-post.json │ ├── docker │ │ └── expressor │ │ │ ├── worker.js │ │ │ ├── process.json │ │ │ ├── app.js │ │ │ └── package.json │ ├── inside │ │ ├── inner_restart.sh │ │ ├── echo.js │ │ ├── start_inside.js │ │ ├── restart_inside.js │ │ └── reload_inside.js │ ├── watch │ │ ├── app-watch.json │ │ ├── app-watch-rename.json │ │ ├── app.json │ │ └── http.js │ ├── interface │ │ ├── log_out.js │ │ ├── process_exception.js │ │ ├── human_event.js │ │ ├── promise_rejection.js │ │ ├── process_exception_with_logs.js │ │ └── child.js │ ├── no-vizion.json │ ├── extra-lang │ │ ├── echo.php │ │ ├── echo.py │ │ └── apps.json │ ├── pm2-dev │ │ ├── app.json │ │ └── app.js │ ├── promise │ │ ├── empty-rejection.js │ │ └── rejection.js │ ├── python-script.py │ ├── no-restart.json │ ├── echo.js │ ├── server.js │ ├── args │ │ ├── echo.js │ │ └── params_check.js │ ├── path-resolution │ │ ├── echo.js │ │ ├── ecosystem2.config.js │ │ └── ecosystem.config.js │ ├── signal.js │ ├── multi-echo.json │ ├── big-array.js │ ├── conf.json │ ├── cluster-pm2.json │ ├── network.js │ ├── events │ │ ├── custom_action.js │ │ ├── own_event.js │ │ └── custom_action_with_params.js │ ├── signals │ │ └── delayed_sigint.js │ ├── startProcessInsidePm2.json │ ├── stdout-stderr.js │ ├── harmony.js │ ├── args.js │ ├── cluster │ │ └── sigint_catcher.js │ ├── source-map │ │ ├── main.js │ │ ├── main.js.map │ │ ├── models.js.map │ │ └── models.js │ ├── throw-later.js │ ├── env.json │ ├── homogen-json-action │ │ ├── all.json │ │ └── http.js │ ├── throw-later1.json │ ├── no_cwd_change.json │ ├── 001-test.js │ ├── env-refreshed.json │ ├── send-data-process │ │ └── return-data.js │ ├── throw-later.json │ ├── cron │ │ ├── mock-cron-no-exit.js │ │ └── mock-cron.js │ ├── custom_actions │ │ └── index.js │ ├── append-env-to-name.json │ ├── change_cwd.json │ ├── path-check.js │ ├── all.json │ ├── nvm-node-version │ │ ├── http.js │ │ ├── ecosystem.json │ │ └── ecosystem-change.json │ ├── configuration.js │ ├── echo-post.json │ ├── containerizer │ │ ├── Dockerfile.dev │ │ └── Dockerfile.prod │ ├── configuration.json │ ├── local_require.js │ ├── delayed_exit.js │ ├── child.js │ ├── echo2.js │ ├── echo3.js │ ├── big-array-es6.js │ ├── graceful-exit-no-listen.js │ ├── child_no_http.js │ ├── startProcessInsidePm2.js │ ├── http.js │ ├── all2.json │ ├── env-ecosystem.json │ ├── graceful-exit-send.js │ ├── graceful-exit.js │ ├── wait_ready_event │ │ ├── http-wait-start_nocb.js │ │ └── http-wait-start.js │ ├── big-array-listen.js │ └── listen-timeout │ │ └── wait-ready.js ├── mocha.opts ├── interface │ ├── mocha.opts │ ├── password.mocha.js │ ├── filter.mocha.js │ └── README.md ├── programmatic │ ├── mocha.opts │ └── api.backward.compatibility.mocha.js ├── benchmarks │ ├── result.monit │ ├── monit-daemon.sh │ └── monit.sh ├── bash │ ├── js-configuration.sh │ ├── piped-config.sh │ ├── append-env-to-name.sh │ ├── get-set.sh │ ├── listen-timeout.sh │ ├── resurrect.sh │ ├── cli-ux.sh │ ├── issues │ │ └── 2337.sh │ ├── startup.sh │ ├── right-exit-code.sh │ ├── startOrX.sh │ ├── wrapped-fork.sh │ ├── interact.sh │ ├── operate-regex.sh │ ├── vizion.sh │ ├── multiparam.sh │ ├── start-consistency.sh │ ├── gracefulReload3.sh │ ├── pm2-dev.sh │ ├── gracefulReload2.sh │ ├── harmony.sh │ ├── fork.sh │ ├── smart-start.sh │ ├── yaml-configuration.sh │ ├── gracefulReload.sh │ ├── log-custom.sh │ ├── homogen-json-action.sh │ ├── signal.sh │ ├── binary.sh │ ├── file-descriptor.sh │ ├── log-reload.sh │ └── reset.sh ├── parallel_programmatic_tests.sh ├── helpers │ └── plan.js ├── programmatic_commands.txt └── README.md ├── bin ├── pm2-dev └── rundev ├── pres ├── pm2-dev.png ├── pm2-v2.png ├── schema.png ├── pm2-desc.png ├── pm2-list.png ├── pm2-logs.png ├── pm2-monit.png ├── pm2.20d3ef.png ├── legacy-logo.png ├── cluster-support.png └── pm2-versioning-metadata.png ├── .bithoundrc ├── lib ├── templates │ ├── ecosystem-simple.tpl │ ├── Dockerfiles │ │ ├── Dockerfile-java.tpl │ │ ├── Dockerfile-ruby.tpl │ │ └── Dockerfile-nodejs.tpl │ ├── logrotate.d │ │ └── pm2 │ └── init-scripts │ │ ├── systemd.tpl │ │ ├── openrc.tpl │ │ └── launchd.tpl ├── API │ └── interpreter.json ├── Interactor │ ├── internal-ip.js │ └── RemoteActions │ │ └── ScopedExecution.js ├── keymetrics.bkcp └── keymetrics ├── .gitignore ├── .npmignore ├── packager ├── debian │ ├── description │ ├── copyright │ ├── lintian-overrides │ └── control.in ├── deploy.sh └── build-dist.sh ├── .travis.yml ├── index.js ├── .github ├── ISSUE_TEMPLATE.md └── PULL_REQUEST_TEMPLATE.md ├── .editorconfig └── Makefile /LICENSE: -------------------------------------------------------------------------------- 1 | GNU-AGPL-3.0.txt 2 | -------------------------------------------------------------------------------- /examples/v1/auto-save.js: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /test/fixtures/process.json: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /test/mocha.opts: -------------------------------------------------------------------------------- 1 | --timeout 5000 2 | -------------------------------------------------------------------------------- /test/fixtures/watcher/donotwatchme.dir/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/interface/mocha.opts: -------------------------------------------------------------------------------- 1 | --timeout 5000 2 | -------------------------------------------------------------------------------- /test/programmatic/mocha.opts: -------------------------------------------------------------------------------- 1 | --timeout 5000 2 | -------------------------------------------------------------------------------- /examples/v1/killfast.js: -------------------------------------------------------------------------------- 1 | 2 | process.exit(1); 3 | -------------------------------------------------------------------------------- /test/fixtures/git/COMMIT_EDITMSG: -------------------------------------------------------------------------------- 1 | first commit 2 | -------------------------------------------------------------------------------- /test/fixtures/git/HEAD: -------------------------------------------------------------------------------- 1 | ref: refs/heads/master 2 | -------------------------------------------------------------------------------- /test/fixtures/log-json/one-echo.js: -------------------------------------------------------------------------------- 1 | console.log('echo') -------------------------------------------------------------------------------- /test/fixtures/serve/index.html: -------------------------------------------------------------------------------- 1 | good shit right there -------------------------------------------------------------------------------- /test/fixtures/watcher/watchme.sym: -------------------------------------------------------------------------------- 1 | ./donotwatchme.dir -------------------------------------------------------------------------------- /test/fixtures/serve/404.html: -------------------------------------------------------------------------------- 1 | your file doesnt exist believe me -------------------------------------------------------------------------------- /test/fixtures/toto.js: -------------------------------------------------------------------------------- 1 | 2 | console.log(process.env.TOTO); 3 | -------------------------------------------------------------------------------- /examples/v1/modulechild.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | console.log(module.parent); 4 | -------------------------------------------------------------------------------- /bin/pm2-dev: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | require('../lib/DevCli.js'); 4 | -------------------------------------------------------------------------------- /bin/rundev: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | require('../lib/DevCli.js'); 4 | -------------------------------------------------------------------------------- /test/fixtures/binary-py-file.py: -------------------------------------------------------------------------------- 1 | while True: 2 | print 'hello' 3 | -------------------------------------------------------------------------------- /test/fixtures/module-fixture/node_modules/pmx/test/transaction.pmx.js: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/fixtures/path1/iminpath1.js: -------------------------------------------------------------------------------- 1 | 2 | console.log(process.cwd()); 3 | -------------------------------------------------------------------------------- /test/fixtures/throw.js: -------------------------------------------------------------------------------- 1 | 2 | throw new Error('Exit error message'); 3 | -------------------------------------------------------------------------------- /examples/v1/env_args.js: -------------------------------------------------------------------------------- 1 | 2 | console.log(process.env.PASSED_VARIABLE); 3 | -------------------------------------------------------------------------------- /examples/v1/infinite-recurse.js: -------------------------------------------------------------------------------- 1 | function x() { 2 | x(); 3 | } 4 | x(); 5 | -------------------------------------------------------------------------------- /test/fixtures/path1/path2/iminpath2.js: -------------------------------------------------------------------------------- 1 | 2 | console.log(process.cwd()); 3 | -------------------------------------------------------------------------------- /test/fixtures/binary-js-file: -------------------------------------------------------------------------------- 1 | setInterval(function () {console.log("test")}, 5000) -------------------------------------------------------------------------------- /test/fixtures/binary-js-file.js: -------------------------------------------------------------------------------- 1 | setInterval(function () {console.log("test")}, 5000) -------------------------------------------------------------------------------- /test/fixtures/git/refs/heads/master: -------------------------------------------------------------------------------- 1 | 7ae6d7c64d39da2167c33993e1f4f0233e8eb6f0 2 | -------------------------------------------------------------------------------- /examples/extra-lang/echo.rb: -------------------------------------------------------------------------------- 1 | 2 | while 1 do 3 | puts "lol" 4 | sleep 1 5 | end 6 | -------------------------------------------------------------------------------- /pres/pm2-dev.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sidthesloth92/pm2/master/pres/pm2-dev.png -------------------------------------------------------------------------------- /pres/pm2-v2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sidthesloth92/pm2/master/pres/pm2-v2.png -------------------------------------------------------------------------------- /pres/schema.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sidthesloth92/pm2/master/pres/schema.png -------------------------------------------------------------------------------- /test/fixtures/module-fixture/node_modules/pmx/test/fixtures/scoped-action.mocha.js: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /.bithoundrc: -------------------------------------------------------------------------------- 1 | { 2 | "critics": { 3 | "lint": {"engine": "semistandard"} 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /examples/binary/ls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sidthesloth92/pm2/master/examples/binary/ls -------------------------------------------------------------------------------- /examples/binary/ls.yml: -------------------------------------------------------------------------------- 1 | apps: 2 | - script : './ls' 3 | exec_interpreter : 'none' 4 | -------------------------------------------------------------------------------- /examples/v1/echo.coffee: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env coffee 2 | 3 | setInterval (-> console.log 'ok'), 500 -------------------------------------------------------------------------------- /pres/pm2-desc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sidthesloth92/pm2/master/pres/pm2-desc.png -------------------------------------------------------------------------------- /pres/pm2-list.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sidthesloth92/pm2/master/pres/pm2-list.png -------------------------------------------------------------------------------- /pres/pm2-logs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sidthesloth92/pm2/master/pres/pm2-logs.png -------------------------------------------------------------------------------- /pres/pm2-monit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sidthesloth92/pm2/master/pres/pm2-monit.png -------------------------------------------------------------------------------- /pres/pm2.20d3ef.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sidthesloth92/pm2/master/pres/pm2.20d3ef.png -------------------------------------------------------------------------------- /test/fixtures/bashscript.sh: -------------------------------------------------------------------------------- 1 | while true; do 2 | ls -l 3 | sleep 5 4 | done 5 | 6 | -------------------------------------------------------------------------------- /test/fixtures/cron.js: -------------------------------------------------------------------------------- 1 | 2 | setInterval(function() { 3 | console.log('ok'); 4 | }, 500); 5 | -------------------------------------------------------------------------------- /test/fixtures/git/refs/remotes/origin/master: -------------------------------------------------------------------------------- 1 | 7ae6d7c64d39da2167c33993e1f4f0233e8eb6f0 2 | -------------------------------------------------------------------------------- /test/fixtures/yaml-configuration/malformated.yml: -------------------------------------------------------------------------------- 1 | { 2 | "ASDSDASD": "ASDSADSAD" 3 | } 4 | -------------------------------------------------------------------------------- /examples/extra-lang/bashscript.sh: -------------------------------------------------------------------------------- 1 | while true; do 2 | ls -l 3 | sleep 5 4 | done 5 | 6 | -------------------------------------------------------------------------------- /examples/transpilers/echo.ls: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env lsc 2 | 3 | setInterval (-> console.log 'ok'), 500 -------------------------------------------------------------------------------- /examples/v1/stop-after5.js: -------------------------------------------------------------------------------- 1 | 2 | setTimeout(function() { 3 | process.exit(0); 4 | }, 5000); 5 | -------------------------------------------------------------------------------- /pres/legacy-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sidthesloth92/pm2/master/pres/legacy-logo.png -------------------------------------------------------------------------------- /test/fixtures/echo.coffee: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env coffee 2 | 3 | setInterval (-> console.log 'ok'), 500 -------------------------------------------------------------------------------- /examples/pmx/elements/error.js: -------------------------------------------------------------------------------- 1 | 2 | setInterval(function() { 3 | new Error('toto'); 4 | }, 10); 5 | -------------------------------------------------------------------------------- /examples/transpilers/echo.coffee: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env coffee 2 | 3 | setInterval (-> console.log 'ok'), 500 -------------------------------------------------------------------------------- /examples/v1/apps/no-name-echo.json: -------------------------------------------------------------------------------- 1 | { 2 | "script" : "examples/echo.js", 3 | "max" : "1" 4 | } 5 | -------------------------------------------------------------------------------- /examples/v1/child.js-pm2.json: -------------------------------------------------------------------------------- 1 | { 2 | "script":"examples/child.js", 3 | "name":"child.js" 4 | } 5 | -------------------------------------------------------------------------------- /examples/v1/string-crash.js: -------------------------------------------------------------------------------- 1 | 2 | function crash() { 3 | throw 'crashed'; 4 | } 5 | 6 | crash(); 7 | -------------------------------------------------------------------------------- /pres/cluster-support.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sidthesloth92/pm2/master/pres/cluster-support.png -------------------------------------------------------------------------------- /test/fixtures/git/index: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sidthesloth92/pm2/master/test/fixtures/git/index -------------------------------------------------------------------------------- /test/fixtures/killnotsofast.js: -------------------------------------------------------------------------------- 1 | setInterval(function() { 2 | console.log('ALIVE'); 3 | }, 500); 4 | -------------------------------------------------------------------------------- /test/fixtures/module-fixture/node_modules/pmx/node_modules/json-stringify-safe/.npmignore: -------------------------------------------------------------------------------- 1 | /*.tgz 2 | -------------------------------------------------------------------------------- /test/fixtures/start-consistency/child.json: -------------------------------------------------------------------------------- 1 | { 2 | script:"./child.js", 3 | name :"child" 4 | } 5 | -------------------------------------------------------------------------------- /examples/v1/killslow.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | setTimeout(function() { 4 | throw new Error('ok'); 5 | }, 1100); 6 | -------------------------------------------------------------------------------- /test/fixtures/app-config-update/args1.json: -------------------------------------------------------------------------------- 1 | { 2 | "script" : "echo.js", 3 | "node_args" : "" 4 | } 5 | -------------------------------------------------------------------------------- /test/fixtures/env.js: -------------------------------------------------------------------------------- 1 | setInterval(function() { 2 | console.log(process.env.TEST_VARIABLE); 3 | }, 100); 4 | -------------------------------------------------------------------------------- /test/fixtures/git/description: -------------------------------------------------------------------------------- 1 | Unnamed repository; edit this file 'description' to name the repository. 2 | -------------------------------------------------------------------------------- /test/fixtures/interpreter/echo.coffee: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env coffee 2 | 3 | setInterval (-> console.log 'ok'), 500 -------------------------------------------------------------------------------- /test/fixtures/module-fixture/node_modules/pmx/index.js: -------------------------------------------------------------------------------- 1 | 2 | module.exports = exports = require("./lib"); 3 | -------------------------------------------------------------------------------- /test/fixtures/throw-string.js: -------------------------------------------------------------------------------- 1 | 2 | function crash() { 3 | throw 'crashed'; 4 | } 5 | 6 | crash(); 7 | -------------------------------------------------------------------------------- /examples/v1/moduleparent.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | var a =require('./modulechild.js'); 4 | console.log(module.children); 5 | -------------------------------------------------------------------------------- /test/fixtures/echo-pm2.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "echo", 3 | "script" : "echo.js", 4 | "options": [""] 5 | } 6 | -------------------------------------------------------------------------------- /test/fixtures/js-configuration/app.js: -------------------------------------------------------------------------------- 1 | 2 | setInterval(function() { 3 | console.log('ok'); 4 | }, 1000); 5 | -------------------------------------------------------------------------------- /test/fixtures/module-fixture/node_modules/pmx/node_modules/debug/.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "laxbreak": true 3 | } 4 | -------------------------------------------------------------------------------- /test/fixtures/app-config-update/args2.json: -------------------------------------------------------------------------------- 1 | { 2 | "script" : "echo.js", 3 | "node_args" : "--harmony" 4 | } 5 | -------------------------------------------------------------------------------- /test/fixtures/echoto-pm2.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "echoto", 3 | "script" : "echoto.js", 4 | "options": [""] 5 | } 6 | -------------------------------------------------------------------------------- /test/fixtures/insidePm2Process.js: -------------------------------------------------------------------------------- 1 | setInterval(function(){ 2 | console.log(process.env.TEST_VARIABLE); 3 | }, 500); -------------------------------------------------------------------------------- /examples/keymetrics-integration/pid_info.js: -------------------------------------------------------------------------------- 1 | 2 | // ps -p 5828 -o pid,vsz=MEMORY -o user,group=GROUP -o comm,args=ARGS 3 | -------------------------------------------------------------------------------- /examples/throw.js: -------------------------------------------------------------------------------- 1 | 2 | setTimeout(function() { 3 | throw new Error('New error thrown automatically'); 4 | }, 1200); 5 | -------------------------------------------------------------------------------- /examples/v1/env.js: -------------------------------------------------------------------------------- 1 | setInterval(function() { 2 | console.log('env NODE_ENV = ', process.env.NODE_ENV); 3 | }, 1000); 4 | -------------------------------------------------------------------------------- /examples/v1/kill-slow.js: -------------------------------------------------------------------------------- 1 | 2 | setTimeout(function() { 3 | console.log('exit'); 4 | process.exit(1); 5 | }, 1000); 6 | -------------------------------------------------------------------------------- /pres/pm2-versioning-metadata.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sidthesloth92/pm2/master/pres/pm2-versioning-metadata.png -------------------------------------------------------------------------------- /test/fixtures/echo-env.js: -------------------------------------------------------------------------------- 1 | 2 | setInterval(function() { 3 | console.log(process.env.ECHO_MSG || 'ok'); 4 | }, 100); 5 | -------------------------------------------------------------------------------- /test/fixtures/echo-to-pm2.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "echo-to", 3 | "script" : "echo-to.js", 4 | "options": [""] 5 | } 6 | -------------------------------------------------------------------------------- /test/fixtures/harmony.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "ES6", 3 | "script" : "harmony.js", 4 | "node_args" : "--harmony" 5 | } 6 | -------------------------------------------------------------------------------- /test/fixtures/interpreter/echo.ls: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env lsc 2 | 3 | setInterval (-> console.log 'Hello Livescript!'), 500 4 | -------------------------------------------------------------------------------- /test/fixtures/quit.js: -------------------------------------------------------------------------------- 1 | 2 | console.log('HEY!'); 3 | 4 | setTimeout(function() { 5 | process.exit(1); 6 | }, 3000); 7 | -------------------------------------------------------------------------------- /examples/extra-lang/echo.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/v1/throw.js: -------------------------------------------------------------------------------- 1 | 2 | setTimeout(function() { 3 | throw new Error('New error thrown automatically'); 4 | }, 1200); 5 | -------------------------------------------------------------------------------- /test/fixtures/env-switching/child.js: -------------------------------------------------------------------------------- 1 | 2 | setInterval(function() { 3 | console.log(process.env.NODE_ENV); 4 | }, 1000); 5 | -------------------------------------------------------------------------------- /test/fixtures/killtoofast.js: -------------------------------------------------------------------------------- 1 | 2 | setInterval(function() { 3 | console.log('BOUM'); 4 | process.exit(1); 5 | }, 30); 6 | -------------------------------------------------------------------------------- /examples/pmx/elements/log-cluster.js: -------------------------------------------------------------------------------- 1 | setInterval(function() { 2 | console.log('log'); 3 | console.error('log'); 4 | }, 200); 5 | -------------------------------------------------------------------------------- /examples/pmx/elements/log.js: -------------------------------------------------------------------------------- 1 | 2 | setInterval(function() { 3 | console.log('log'); 4 | console.error('log'); 5 | }, 200); 6 | -------------------------------------------------------------------------------- /test/fixtures/json-reload/echo-env.js: -------------------------------------------------------------------------------- 1 | 2 | setInterval(function() { 3 | console.log(process.env.ECHO_MSG || 'ok'); 4 | }, 100); 5 | -------------------------------------------------------------------------------- /test/fixtures/module-fixture/node_modules/pmx/node_modules/json-stringify-safe/test/mocha.opts: -------------------------------------------------------------------------------- 1 | --recursive 2 | --require must 3 | -------------------------------------------------------------------------------- /examples/v1/apps/auto-kill-echo.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "auto-kill", 3 | "script" : "./examples/echokill.js", 4 | "max" : "10" 5 | } 6 | -------------------------------------------------------------------------------- /examples/v1/apps/default-path-echo.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "echo-default", 3 | "script" : "examples/echo.js", 4 | "max" : "1" 5 | } 6 | -------------------------------------------------------------------------------- /test/fixtures/docker/expressor/worker.js: -------------------------------------------------------------------------------- 1 | 2 | setInterval(function() { 3 | console.log('Worker finished his job'); 4 | }, 1000); 5 | -------------------------------------------------------------------------------- /lib/templates/ecosystem-simple.tpl: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | apps : [{ 3 | name : "app1", 4 | script : "./app.js" 5 | }] 6 | } 7 | -------------------------------------------------------------------------------- /test/fixtures/inside/inner_restart.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | $PM2_PATH restart echo 4 | $PM2_PATH restart echo 5 | $PM2_PATH restart echo 6 | -------------------------------------------------------------------------------- /test/fixtures/module-fixture/node_modules/pmx/node_modules/debug/.npmignore: -------------------------------------------------------------------------------- 1 | support 2 | test 3 | examples 4 | example 5 | *.sock 6 | dist 7 | -------------------------------------------------------------------------------- /test/fixtures/module-fixture/node_modules/pmx/test/mocha.opts: -------------------------------------------------------------------------------- 1 | --require should 2 | --reporter spec 3 | --timeout 30000000 4 | --slow 300 5 | -------------------------------------------------------------------------------- /test/fixtures/watch/app-watch.json: -------------------------------------------------------------------------------- 1 | { 2 | apps: [{ 3 | script : 'http.js', 4 | name : 'http', 5 | watch : true 6 | }] 7 | } 8 | -------------------------------------------------------------------------------- /examples/extra-lang/echo.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | import time 3 | 4 | while 1: 5 | print("Start : %s" % time.ctime()) 6 | time.sleep(1) 7 | -------------------------------------------------------------------------------- /test/fixtures/interface/log_out.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | console.log('outmsg'); 4 | 5 | console.error('errmsg'); 6 | 7 | setInterval(function() {}, 100); 8 | -------------------------------------------------------------------------------- /test/fixtures/json-reload/max-mem-0.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "max_mem", 3 | "script" : "big-array.js", 4 | "max_memory_restart" : "300M" 5 | } 6 | -------------------------------------------------------------------------------- /test/fixtures/json-reload/max-mem.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "max_mem", 3 | "script" : "big-array.js", 4 | "max_memory_restart" : "19M" 5 | } 6 | -------------------------------------------------------------------------------- /examples/process-file/connection_check.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | foo() { 4 | echo "Hello Bash!" 5 | } 6 | 7 | while true; do foo; sleep 2; done 8 | -------------------------------------------------------------------------------- /test/fixtures/watch/app-watch-rename.json: -------------------------------------------------------------------------------- 1 | { 2 | apps: [{ 3 | script : 'http.js', 4 | name : 'http', 5 | watch : true 6 | }] 7 | } 8 | -------------------------------------------------------------------------------- /examples/pmx/elements/notify.js: -------------------------------------------------------------------------------- 1 | 2 | const pmx = require('pmx'); 3 | 4 | setInterval(function() { 5 | pmx.notify({ success : false }); 6 | }, 200); 7 | -------------------------------------------------------------------------------- /test/fixtures/no-vizion.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name" : "no_vizion", 4 | "script" : "./echo.js", 5 | "vizion" : false 6 | } 7 | ] 8 | -------------------------------------------------------------------------------- /examples/v1/killtoofast.js: -------------------------------------------------------------------------------- 1 | 2 | console.log('im a kamikazy'); 3 | 4 | setInterval(function() { 5 | console.log('BOUM'); 6 | process.exit(1); 7 | }, 30); 8 | -------------------------------------------------------------------------------- /test/fixtures/app-config-update/echo.js: -------------------------------------------------------------------------------- 1 | 2 | var i = 0; 3 | setInterval(function() { 4 | console.log('ok', i++); 5 | }, 2000); 6 | 7 | console.log('ok'); 8 | -------------------------------------------------------------------------------- /test/fixtures/extra-lang/echo.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/fixtures/module-fixture/node_modules/pmx/.npmignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | *.log 3 | *.log 4 | test/child 5 | *.iml 6 | .idea/** 7 | sample/pmx-server-stats 8 | -------------------------------------------------------------------------------- /test/fixtures/module-fixture/node_modules/pmx/test/fixtures/module/module.fixture.js: -------------------------------------------------------------------------------- 1 | 2 | var pmx = require('../../..'); 3 | 4 | var conf = pmx.initModule(); 5 | -------------------------------------------------------------------------------- /test/fixtures/pm2-dev/app.json: -------------------------------------------------------------------------------- 1 | { 2 | "script": "app.js", 3 | "watch": ["server", "client"], 4 | "ignore_watch" : ["node_modules", "client/img"] 5 | } 6 | -------------------------------------------------------------------------------- /test/fixtures/promise/empty-rejection.js: -------------------------------------------------------------------------------- 1 | 2 | setTimeout(function() { 3 | Promise.reject(); 4 | }, 1000); 5 | 6 | setInterval(function() { 7 | }, 1000); 8 | -------------------------------------------------------------------------------- /test/fixtures/python-script.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | if __name__ == "__main__": 4 | while 1: 5 | print 'Script.py: alive' 6 | time.sleep(1) 7 | -------------------------------------------------------------------------------- /examples/v1/inside.json: -------------------------------------------------------------------------------- 1 | 2 | [{ 3 | "name" : "inside", 4 | "script":"examples/inside.js" 5 | },{ 6 | "name" : "echo", 7 | "script":"examples/echo.js" 8 | }] 9 | -------------------------------------------------------------------------------- /test/fixtures/module-fixture/node_modules/pmx/node_modules/debug/node_modules/ms/.npmignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | test 3 | History.md 4 | Makefile 5 | component.json 6 | -------------------------------------------------------------------------------- /examples/v1/apps/killfast.json: -------------------------------------------------------------------------------- 1 | { 2 | "min_uptime" : "100", 3 | "max_restarts" : "400", 4 | "name" : "auto-kill", 5 | "script" : "./examples/killfast.js" 6 | } 7 | -------------------------------------------------------------------------------- /test/fixtures/no-restart.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name" : "no_restart_app", 4 | "script" : "./killtoofast.js", 5 | "autorestart" : false 6 | } 7 | ] 8 | -------------------------------------------------------------------------------- /test/fixtures/promise/rejection.js: -------------------------------------------------------------------------------- 1 | 2 | setTimeout(function() { 3 | Promise.reject(new Error('Errorla')); 4 | }, 1000); 5 | 6 | setInterval(function() { 7 | }, 1000); 8 | -------------------------------------------------------------------------------- /examples/process-file/worker.js: -------------------------------------------------------------------------------- 1 | 2 | setInterval(function() { 3 | console.log('Worker has finished his job.'); 4 | console.error('Worker has finished his job.'); 5 | }, 1000); 6 | -------------------------------------------------------------------------------- /examples/promise_rejection.js: -------------------------------------------------------------------------------- 1 | var p = new Promise(function(resolve, reject) { 2 | throw new Error('fail') 3 | return resolve('ok') 4 | }) 5 | 6 | p.then(function(e) { 7 | }) 8 | -------------------------------------------------------------------------------- /examples/v1/sendmsg.js: -------------------------------------------------------------------------------- 1 | 2 | setInterval(function() { 3 | process.send({ 4 | type : 'miami', 5 | data : { msg : 'i can communicate with others'} 6 | }); 7 | }, 1000); 8 | -------------------------------------------------------------------------------- /examples/v1/sigint.js: -------------------------------------------------------------------------------- 1 | 2 | process.on('SIGINT', function() { 3 | // Do othing for tests 4 | }); 5 | 6 | setInterval(function() { 7 | console.log('I\'m alive'); 8 | }, 2000); 9 | -------------------------------------------------------------------------------- /test/fixtures/echo.js: -------------------------------------------------------------------------------- 1 | 2 | setInterval(function() { 3 | console.log('echo.js'); 4 | }, 50); 5 | 6 | setInterval(function() { 7 | console.error('echo.js-error'); 8 | }, 50); 9 | -------------------------------------------------------------------------------- /test/fixtures/interface/process_exception.js: -------------------------------------------------------------------------------- 1 | 2 | var axm = require('pmx'); 3 | 4 | axm.catchAll(); 5 | 6 | setTimeout(function() { 7 | throw new Error('Exit'); 8 | }, 200); 9 | -------------------------------------------------------------------------------- /test/fixtures/module-fixture/node_modules/pmx/test/fixtures/notify.mock.js: -------------------------------------------------------------------------------- 1 | 2 | var axm = require('../..'); 3 | 4 | setTimeout(function() { 5 | axm.notify('hey'); 6 | }, 100); 7 | -------------------------------------------------------------------------------- /test/fixtures/server.js: -------------------------------------------------------------------------------- 1 | var http = require('http'); 2 | 3 | http.createServer(function(req, res) { 4 | res.writeHead(200); 5 | res.end("hello world\n"); 6 | }).listen(8020); 7 | -------------------------------------------------------------------------------- /examples/v1/kill-not-so-fast.js: -------------------------------------------------------------------------------- 1 | 2 | console.log('start'); 3 | 4 | setTimeout(function() { 5 | console.log('exit'); 6 | throw new Error('Exitasdsadasdsda unacepted !!'); 7 | }, 300); 8 | -------------------------------------------------------------------------------- /test/fixtures/args/echo.js: -------------------------------------------------------------------------------- 1 | 2 | setInterval(function() { 3 | console.log('echo.js'); 4 | }, 5000); 5 | 6 | setInterval(function() { 7 | console.error('echo.js-error'); 8 | }, 5000); 9 | -------------------------------------------------------------------------------- /test/fixtures/git/objects/5d/a45b6659e5cba8f444616f4e18529ad5dde72f: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sidthesloth92/pm2/master/test/fixtures/git/objects/5d/a45b6659e5cba8f444616f4e18529ad5dde72f -------------------------------------------------------------------------------- /test/fixtures/git/objects/7a/e6d7c64d39da2167c33993e1f4f0233e8eb6f0: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sidthesloth92/pm2/master/test/fixtures/git/objects/7a/e6d7c64d39da2167c33993e1f4f0233e8eb6f0 -------------------------------------------------------------------------------- /test/fixtures/git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sidthesloth92/pm2/master/test/fixtures/git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 -------------------------------------------------------------------------------- /test/fixtures/inside/echo.js: -------------------------------------------------------------------------------- 1 | 2 | setInterval(function() { 3 | console.log('echo.js'); 4 | }, 500); 5 | 6 | setInterval(function() { 7 | console.error('echo.js-error'); 8 | }, 500); 9 | -------------------------------------------------------------------------------- /test/fixtures/watcher/server-watch.bak.js: -------------------------------------------------------------------------------- 1 | var http = require('http'); 2 | 3 | http.createServer(function(req, res) { 4 | res.writeHead(200); 5 | res.end('hey'); 6 | }).listen(8010); 7 | -------------------------------------------------------------------------------- /test/fixtures/yaml-configuration/echo.js: -------------------------------------------------------------------------------- 1 | 2 | setInterval(function() { 3 | console.log('ok'); 4 | }, 100); 5 | 6 | setInterval(function() { 7 | console.error('thisnok'); 8 | }, 100); 9 | -------------------------------------------------------------------------------- /test/fixtures/git/logs/HEAD: -------------------------------------------------------------------------------- 1 | 0000000000000000000000000000000000000000 7ae6d7c64d39da2167c33993e1f4f0233e8eb6f0 jshkurti 1429209718 +0200 commit (initial): first commit 2 | -------------------------------------------------------------------------------- /test/fixtures/path-resolution/echo.js: -------------------------------------------------------------------------------- 1 | 2 | setInterval(function() { 3 | console.log('echo.js'); 4 | }, 50); 5 | 6 | setInterval(function() { 7 | console.error('echo.js-error'); 8 | }, 50); 9 | -------------------------------------------------------------------------------- /test/fixtures/serve/ecosystem.json: -------------------------------------------------------------------------------- 1 | [{ 2 | "name" : "frontend", 3 | "script" : "serve", 4 | "env": { 5 | "PM2_SERVE_PORT": 8081, 6 | "PM2_SERVE_PATH": "." 7 | } 8 | }] 9 | -------------------------------------------------------------------------------- /test/fixtures/signal.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | setInterval(function() { 4 | console.log('ok'); 5 | }, 1000); 6 | 7 | process.on('SIGUSR2', function () { 8 | console.log('SIGUSR2'); 9 | }); 10 | -------------------------------------------------------------------------------- /test/fixtures/git/logs/refs/remotes/origin/master: -------------------------------------------------------------------------------- 1 | 0000000000000000000000000000000000000000 7ae6d7c64d39da2167c33993e1f4f0233e8eb6f0 jshkurti 1429209819 +0200 update by push 2 | -------------------------------------------------------------------------------- /test/fixtures/module-fixture/node_modules/pmx/lib/common.js: -------------------------------------------------------------------------------- 1 | 2 | var Common = module.exports = {}; 3 | 4 | Common.getDate = function getDate() { 5 | return Math.round(Date.now() / 1000); 6 | }; 7 | -------------------------------------------------------------------------------- /test/fixtures/multi-echo.json: -------------------------------------------------------------------------------- 1 | [{ 2 | "name" : "echo2", 3 | "script" : "echo.js", 4 | "max" : "1" 5 | }, { 6 | "name" : "echo3", 7 | "script" : "echo.js", 8 | "max" : "1" 9 | }] 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | *.log 3 | *.log 4 | *.pid 5 | test/child 6 | *.iml 7 | .idea/** 8 | *.heapsnapshot 9 | *.cpuprofile 10 | .cache-require-paths.json 11 | dist/ 12 | *.deb 13 | *.rpm 14 | -------------------------------------------------------------------------------- /examples/v1/cwd.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | console.log(process.env.PWD); 4 | console.log(process.cwd()); 5 | console.log(__dirname); 6 | 7 | require('./echo.js'); 8 | 9 | console.log(process.cwd()); 10 | 11 | -------------------------------------------------------------------------------- /test/fixtures/big-array.js: -------------------------------------------------------------------------------- 1 | 2 | var obj = {}; 3 | var i = 0; 4 | 5 | setInterval(function() { 6 | obj[i] = Array.apply(null, new Array(99999)).map(String.prototype.valueOf,"hi"); 7 | i++; 8 | }, 2); 9 | -------------------------------------------------------------------------------- /test/fixtures/conf.json: -------------------------------------------------------------------------------- 1 | // TG! 2 | [{ 3 | // Application 1 4 | name : "echo", 5 | script : 'toto.js', 6 | env : { 7 | "TOTO" : process.env.NODE_ENV || 'vazytg' 8 | } 9 | }] 10 | -------------------------------------------------------------------------------- /test/fixtures/docker/expressor/process.json: -------------------------------------------------------------------------------- 1 | { 2 | apps : [{ 3 | script : 'app.js', 4 | name : 'Express', 5 | instances : '1' 6 | }, { 7 | script : 'worker.js' 8 | }] 9 | } 10 | -------------------------------------------------------------------------------- /test/fixtures/git/logs/refs/heads/master: -------------------------------------------------------------------------------- 1 | 0000000000000000000000000000000000000000 7ae6d7c64d39da2167c33993e1f4f0233e8eb6f0 jshkurti 1429209718 +0200 commit (initial): first commit 2 | -------------------------------------------------------------------------------- /test/fixtures/watcher/server-watch.js: -------------------------------------------------------------------------------- 1 | var http = require('http'); 2 | 3 | http.createServer(function(req, res) { 4 | res.writeHead(200); 5 | res.end('hey'); 6 | }).listen(8010); 7 | console.log("edit") -------------------------------------------------------------------------------- /examples/v1/child-env.js: -------------------------------------------------------------------------------- 1 | 2 | var http = require('http'); 3 | 4 | http.createServer(function(req, res) { 5 | res.writeHead(200); 6 | res.end(process.env.PORT_ENV); 7 | }).listen(process.env.PORT_ENV); 8 | -------------------------------------------------------------------------------- /test/fixtures/cluster-pm2.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "serv-clust", 3 | "script" : "server.js", 4 | "max" : "10", 5 | "instances" : "4", 6 | "env_test" : { 7 | "NODE_ENV" : "TEST" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /test/fixtures/network.js: -------------------------------------------------------------------------------- 1 | 2 | var http = require('http'); 3 | var i = 0; 4 | 5 | http.createServer(function(req, res) { 6 | res.writeHead(200); 7 | res.end("hello world\n" + i++); 8 | }).listen(8004); 9 | -------------------------------------------------------------------------------- /test/benchmarks/result.monit: -------------------------------------------------------------------------------- 1 | ========= Fri Aug 22 14:11:29 EDT 2014 2 | 14:11:35 61012 3 | ========= Fri Aug 22 14:11:45 EDT 2014 4 | 14:11:50 59984 5 | ========= Fri Aug 22 14:12:47 EDT 2014 6 | 14:12:52 59464 7 | -------------------------------------------------------------------------------- /test/fixtures/events/custom_action.js: -------------------------------------------------------------------------------- 1 | 2 | var axm = require('pmx'); 3 | 4 | axm.action('refresh:db', function(reply) { 5 | console.log('Refreshing'); 6 | reply({success : true, subobj : { a : 'b'}}); 7 | }); 8 | -------------------------------------------------------------------------------- /examples/v1/child-pm2.json: -------------------------------------------------------------------------------- 1 | { 2 | "script":"examples/child.js", 3 | "name":"SERVERONE", 4 | "instances":10, 5 | "error_file":"errfile.log", 6 | "out_file":"outfile.log", 7 | "pid_file":"pidfile.pid" 8 | } 9 | -------------------------------------------------------------------------------- /examples/v1/require.js: -------------------------------------------------------------------------------- 1 | 2 | var util = require('util'); 3 | 4 | console.log(util.inspect(require.main)); 5 | setInterval(function() { 6 | console.log(util.inspect(require.main)); 7 | }, 8000); 8 | 9 | 10 | -------------------------------------------------------------------------------- /test/fixtures/json-reload/big-array.js: -------------------------------------------------------------------------------- 1 | 2 | var obj = {}; 3 | var i = 0; 4 | 5 | setInterval(function() { 6 | obj[i] = Array.apply(null, new Array(99999)).map(String.prototype.valueOf,"hi"); 7 | i++; 8 | }, 40); 9 | -------------------------------------------------------------------------------- /test/fixtures/signals/delayed_sigint.js: -------------------------------------------------------------------------------- 1 | 2 | setInterval(function() { 3 | // Do nothing to keep process alive 4 | }, 1000); 5 | 6 | process.on('SIGINT', function () { 7 | console.log('SIGINT cb called'); 8 | }); 9 | -------------------------------------------------------------------------------- /test/fixtures/startProcessInsidePm2.json: -------------------------------------------------------------------------------- 1 | [{ 2 | "name" : "masterProcess", 3 | "script" : "./startProcessInsidePm2.js", 4 | "exec_mode" : "fork_mode", 5 | "min_uptime" : "100", 6 | "max_restarts" : "50" 7 | }] -------------------------------------------------------------------------------- /examples/v1/apps/args.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "echo", 3 | "script" : "./examples/args.js", 4 | "instances" : "1", 5 | "args" : "['--toto=heya coco', '-d', '1']", 6 | "cron_restart" : "* * * * * *" 7 | } 8 | -------------------------------------------------------------------------------- /test/fixtures/json-reload/echo-pre.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "echo-json", 3 | "script" : "echo-env.js", 4 | "log_date_format" : "YYYY-MM-DD HH:mm Z", 5 | "out_file" : "echo-test.log", 6 | "merge_logs" : true 7 | } 8 | -------------------------------------------------------------------------------- /test/fixtures/stdout-stderr.js: -------------------------------------------------------------------------------- 1 | 2 | process.stdout.write('outwrite', 'utf8', function() { 3 | console.log('outcb'); 4 | }); 5 | 6 | process.stderr.write('errwrite', 'utf8', function() { 7 | console.log('errcb'); 8 | }); 9 | -------------------------------------------------------------------------------- /examples/v1/apps/cron-pm2.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "echo", 3 | "script" : "./examples/args.js", 4 | "instances" : "1", 5 | "args" : "['--toto=heya coco', '-d', '1']", 6 | "cron_restart" : "* * * * * *" 7 | } 8 | -------------------------------------------------------------------------------- /examples/v1/apps/multi-pm2.json: -------------------------------------------------------------------------------- 1 | [{ 2 | "name" : "echo", 3 | "script" : "./examples/args.js", 4 | "instances" : "1", 5 | "args" : "['--toto=heya coco', '-d', '1']", 6 | "cron_restart" : "* * * * * *" 7 | }] 8 | -------------------------------------------------------------------------------- /examples/v1/child2.js: -------------------------------------------------------------------------------- 1 | 2 | var axm = require('pmx'); 3 | axm.http(); 4 | var http = require('http'); 5 | 6 | http.createServer(function(req, res) { 7 | res.writeHead(200); 8 | res.end('hoy'); 9 | }).listen(8000); 10 | -------------------------------------------------------------------------------- /examples/v1/harmony.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert') 2 | , s = new Set() 3 | ; 4 | 5 | s.add('a'); 6 | 7 | assert.ok(s.has('a')); 8 | 9 | setInterval(function() { 10 | console.log(s.has('a')); 11 | }, 1000); 12 | -------------------------------------------------------------------------------- /lib/templates/Dockerfiles/Dockerfile-java.tpl: -------------------------------------------------------------------------------- 1 | FROM anapsix/alpine-java:latest 2 | 3 | RUN apk update && apk add git && rm -rf /var/cache/apk/* 4 | RUN npm install pm2@next -g 5 | RUN mkdir -p /var/app 6 | 7 | WORKDIR /var/app 8 | -------------------------------------------------------------------------------- /lib/templates/Dockerfiles/Dockerfile-ruby.tpl: -------------------------------------------------------------------------------- 1 | FROM anapsix/alpine-ruby:latest 2 | 3 | RUN apk update && apk add git && rm -rf /var/cache/apk/* 4 | RUN npm install pm2@next -g 5 | RUN mkdir -p /var/app 6 | 7 | WORKDIR /var/app 8 | -------------------------------------------------------------------------------- /test/fixtures/args/params_check.js: -------------------------------------------------------------------------------- 1 | 2 | process.argv.shift(); 3 | process.argv.shift(); 4 | 5 | process.argv.forEach(function(val, index) { 6 | console.log(val); 7 | }); 8 | 9 | setInterval(function() { }, 1000); 10 | -------------------------------------------------------------------------------- /test/fixtures/events/own_event.js: -------------------------------------------------------------------------------- 1 | 2 | var axm = require('pmx'); 3 | 4 | setInterval(function() { 5 | axm.emit('user:register', { 6 | user : 'toto@gmail.com', 7 | mail : 'hey@gmail.com' 8 | }); 9 | }, 200); 10 | -------------------------------------------------------------------------------- /test/fixtures/harmony.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert') 2 | , s = new Set() 3 | ; 4 | 5 | s.add('a'); 6 | 7 | assert.ok(s.has('a')); 8 | 9 | setInterval(function() { 10 | console.log(s.has('a')); 11 | }, 1000); 12 | -------------------------------------------------------------------------------- /test/fixtures/module-fixture/node_modules/pmx/.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | branches: 3 | only: 4 | - master 5 | - development 6 | node_js: 7 | - "iojs" 8 | - "0.12" 9 | - "0.11" 10 | - "0.10" 11 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | test 2 | apps 3 | doc 4 | pres 5 | *.log 6 | *.pid 7 | examples 8 | *.pyc 9 | .github 10 | .cache-require-paths.json 11 | *.heapsnapshot 12 | packager 13 | artifacts 14 | .editorconfig 15 | .bithoundrc 16 | dist 17 | -------------------------------------------------------------------------------- /examples/process-actions.js: -------------------------------------------------------------------------------- 1 | var pmx = require('pmx'); 2 | 3 | pmx.action('hello', function(reply) { 4 | reply({ answer : 'world' }); 5 | }); 6 | 7 | setInterval(function() { 8 | // Keep application online 9 | }, 100); 10 | -------------------------------------------------------------------------------- /examples/v1/leak.js: -------------------------------------------------------------------------------- 1 | 2 | var leak = []; 3 | 4 | setInterval(function() { 5 | for (var i = 0; i < 10; i++) { 6 | var str = i.toString() + " on a stick, short and stout!"; 7 | leak.push(str); 8 | } 9 | }, 50); 10 | -------------------------------------------------------------------------------- /test/fixtures/args.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | if (process.argv.indexOf('-d') == -1 || process.argv.indexOf('-a') == -1) { 4 | process.exit(); 5 | } else { 6 | setInterval(function() { 7 | console.log('ok'); 8 | }, 500); 9 | } 10 | -------------------------------------------------------------------------------- /test/fixtures/cluster/sigint_catcher.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | setInterval(function() { 4 | // Do nothing to keep process alive 5 | }, 1000); 6 | 7 | process.on('SIGINT', function () { 8 | console.log('SIGINT cb called'); 9 | }); 10 | -------------------------------------------------------------------------------- /examples/pmx/elements/event.js: -------------------------------------------------------------------------------- 1 | 2 | const pmx = require('pmx'); 3 | 4 | setInterval(function() { 5 | pmx.emit('user:register', { 6 | user : 'Alex registered', 7 | email : 'thorustor@gmail.com' 8 | }); 9 | }, 200); 10 | -------------------------------------------------------------------------------- /examples/v1/inside.js: -------------------------------------------------------------------------------- 1 | 2 | var pm2 = require('..'); 3 | 4 | pm2.connect(function() { 5 | setInterval(function() { 6 | pm2.restart('echo', function() { 7 | console.log(arguments); 8 | }); 9 | }, 2000); 10 | }); 11 | -------------------------------------------------------------------------------- /test/fixtures/inside/start_inside.js: -------------------------------------------------------------------------------- 1 | 2 | var PM2 = require('../../..'); 3 | 4 | var pm2 = new PM2.custom({ 5 | cwd : __dirname 6 | }); 7 | 8 | PM2.start('./echo.js', function(err, app) { 9 | if (err) throw err; 10 | }); 11 | -------------------------------------------------------------------------------- /test/fixtures/source-map/main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var models_1 = require('./models'); 3 | console.log(models_1.UserMessage); 4 | setTimeout(function () { 5 | throw new Error('errr'); 6 | }, 200); 7 | //# sourceMappingURL=main.js.map 8 | -------------------------------------------------------------------------------- /test/fixtures/throw-later.js: -------------------------------------------------------------------------------- 1 | var timer = setInterval(function(){ 2 | console.log('tick', Date.now()); 3 | }, 100); 4 | 5 | setTimeout(function(){ 6 | clearInterval(timer); 7 | throw new Error('error has been caught') 8 | }, 350); 9 | -------------------------------------------------------------------------------- /examples/pmx/elements/meter.js: -------------------------------------------------------------------------------- 1 | 2 | const pmx = require('pmx'); 3 | const Probe = pmx.probe(); 4 | 5 | var metric = Probe.meter({ 6 | name : 'Meter' 7 | }); 8 | 9 | setInterval(function() { 10 | metric.mark() 11 | }, 200); 12 | -------------------------------------------------------------------------------- /test/fixtures/inside/restart_inside.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | var PM2 = require('../../..'); 4 | 5 | var pm2 = new PM2.custom({ 6 | cwd : __dirname 7 | }); 8 | 9 | PM2.restart('echo', function(err, app) { 10 | if (err) throw err; 11 | }); 12 | -------------------------------------------------------------------------------- /test/fixtures/module-fixture/node_modules/pmx/test/fixtures/notify_catch_all.mock.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | var axm = require('../..'); 4 | 5 | axm.catchAll(); 6 | 7 | setTimeout(function() { 8 | throw new Error('global error'); 9 | }, 200); 10 | -------------------------------------------------------------------------------- /examples/remote-action.js: -------------------------------------------------------------------------------- 1 | 2 | var pmx = require('pmx'); 3 | 4 | pmx.action('example', function(reply) { 5 | reply({success:true}); 6 | }); 7 | 8 | setInterval(function() { 9 | // Do not auto exit on empty event loop 10 | }, 1000); 11 | -------------------------------------------------------------------------------- /examples/wait-ready/ecosystem.json: -------------------------------------------------------------------------------- 1 | { 2 | "apps": [{ 3 | "name": "app", 4 | "script": "app.js", 5 | "instances": 2, 6 | "exec_mode": "cluster", 7 | "wait_ready": true, 8 | "listen_timeout": 15000 9 | }] 10 | } 11 | -------------------------------------------------------------------------------- /test/bash/js-configuration.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | SRC=$(cd $(dirname "$0"); pwd) 4 | source "${SRC}/include.sh" 5 | cd $file_path/js-configuration 6 | 7 | $pm2 start ecosystem.config.js 8 | should 'should have started 1 processes' 'online' 1 -------------------------------------------------------------------------------- /test/fixtures/extra-lang/echo.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | import os 3 | import time 4 | 5 | while 1: 6 | try: 7 | print(os.environ['DEFAULT_STR']) 8 | except KeyError: 9 | print('RAWPython') 10 | time.sleep(1) 11 | -------------------------------------------------------------------------------- /test/fixtures/inside/reload_inside.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | var PM2 = require('../../..'); 5 | 6 | var pm2 = new PM2.custom({ 7 | cwd : __dirname 8 | }); 9 | 10 | PM2.reload('echo', function(err, app) { 11 | if (err) throw err; 12 | }); 13 | -------------------------------------------------------------------------------- /examples/pmx/elements/counter.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | const pmx = require('pmx'); 4 | const Probe = pmx.probe(); 5 | 6 | var metric = Probe.counter({ 7 | name : 'Counter' 8 | }); 9 | 10 | setInterval(function() { 11 | metric.inc() 12 | }, 500); 13 | -------------------------------------------------------------------------------- /examples/v1/exec_watch.json: -------------------------------------------------------------------------------- 1 | [{ 2 | "script":"examples/child.js", 3 | "name":"SERVERONE", 4 | "instances":10, 5 | "watch" : true, 6 | "error_file":"errfile.log", 7 | "out_file":"outfile.log", 8 | "pid_file":"pidfile.pid" 9 | }] 10 | -------------------------------------------------------------------------------- /examples/v1/json.js: -------------------------------------------------------------------------------- 1 | 2 | setInterval(function() { 3 | console.log({ 4 | hey : 'hay', 5 | ho : { 6 | si : 'si', 7 | ca : ['boum'] 8 | } 9 | }); 10 | var a = {a: 'a', b: 'b'}; 11 | console.log(a); 12 | }, 1000); 13 | -------------------------------------------------------------------------------- /test/fixtures/yaml-configuration/echo.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | import os 3 | import time 4 | 5 | while 1: 6 | try: 7 | print(os.environ['DEFAULT_STR']) 8 | except KeyError: 9 | print('RAWPython') 10 | time.sleep(1) 11 | -------------------------------------------------------------------------------- /test/fixtures/env.json: -------------------------------------------------------------------------------- 1 | [{ 2 | "name" : "appname", 3 | "script" : "./env.js", 4 | "out_file" : "out-env.log", 5 | "merge_logs" : true, 6 | "env": { 7 | "NODE_ENV": "production", 8 | "TEST_VARIABLE": "YES" 9 | } 10 | }] 11 | -------------------------------------------------------------------------------- /test/fixtures/git/hooks/post-update.sample: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # An example hook script to prepare a packed repository for use over 4 | # dumb transports. 5 | # 6 | # To enable this hook, rename this file to "post-update". 7 | 8 | exec git update-server-info 9 | -------------------------------------------------------------------------------- /test/fixtures/homogen-json-action/all.json: -------------------------------------------------------------------------------- 1 | { 2 | "apps" : [{ 3 | "script" : "http.js", 4 | "name" : "http", 5 | "instances" : 4 6 | }, { 7 | "script" : "http.js", 8 | "name" : "http2", 9 | "instances" : 2 10 | }] 11 | } 12 | -------------------------------------------------------------------------------- /test/fixtures/interface/human_event.js: -------------------------------------------------------------------------------- 1 | 2 | var axm = require('pmx'); 3 | 4 | setInterval(function() { 5 | axm.emit('content:page:created', { 6 | msg : 'A CMS page has been created', 7 | user : 'Francois Debiole' 8 | }); 9 | }, 200); 10 | -------------------------------------------------------------------------------- /test/fixtures/throw-later1.json: -------------------------------------------------------------------------------- 1 | { 2 | "apps" : [{ 3 | "name" : "throw-later", 4 | "script" : "throw-later.js", 5 | "error_file" : "err.log", 6 | "out_file" : "out.log", 7 | "merge_logs" : true 8 | }] 9 | } 10 | -------------------------------------------------------------------------------- /examples/v1/echokill.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | setInterval(function() { 4 | console.log('log message from echo auto kill'); 5 | }, 800); 6 | 7 | setTimeout(function() { 8 | console.error('error message, killing my self'); 9 | process.exit(10); 10 | }, 3000); 11 | -------------------------------------------------------------------------------- /examples/v1/apps/cluster-pm2.json: -------------------------------------------------------------------------------- 1 | { 2 | "script" : "./examples/child.js", 3 | "error_file" : "errLog.log", 4 | "out_file" : "outLog.log", 5 | "pid_file" : "child", 6 | "instances" : "4", 7 | "min_uptime" : "10", 8 | "max_restarts" : "4" 9 | } 10 | -------------------------------------------------------------------------------- /test/fixtures/no_cwd_change.json: -------------------------------------------------------------------------------- 1 | [{ 2 | "name" : "iminpath1", 3 | "script" : "iminpath1.js", 4 | "out_file" : "./iminpath1.log" 5 | },{ 6 | "name" : "iminpath2", 7 | "script" : "iminpath2.js", 8 | "out_file" : "./iminpath2.log" 9 | }] 10 | -------------------------------------------------------------------------------- /test/fixtures/watcher/server-watch.json: -------------------------------------------------------------------------------- 1 | [{ 2 | "name" : "server-watch", 3 | "script" : "./server-watch.bak.js", 4 | "watch" : ["**"], 5 | "ignore_watch" : ["*.log"], 6 | "watch_options" : { 7 | "followSymlinks": true 8 | } 9 | }] 10 | -------------------------------------------------------------------------------- /examples/keymetrics-integration/event.js: -------------------------------------------------------------------------------- 1 | 2 | var axm = require('pmx'); 3 | 4 | setInterval(function() { 5 | 6 | axm.emit('content:page:created', { 7 | msg : 'A CMS page has been created', 8 | user : 'Francois Debiole' 9 | }); 10 | 11 | }, 1000); 12 | -------------------------------------------------------------------------------- /examples/keymetrics-integration/throw.js: -------------------------------------------------------------------------------- 1 | 2 | var axm = require('pmx'); 3 | 4 | axm.catchAll(); 5 | 6 | setTimeout(function() { 7 | console.log('log message from echo auto kill'); 8 | throw new Error('Exitasdsadasdsda unacepted 222222 !!'); 9 | }, 2000); 10 | -------------------------------------------------------------------------------- /test/fixtures/interpreter/echo.ts: -------------------------------------------------------------------------------- 1 | 2 | class Greeter { 3 | constructor(public greeting: string) { } 4 | greet() { 5 | return this.greeting; 6 | } 7 | }; 8 | 9 | var greeter = new Greeter("Hello Typescript!"); 10 | 11 | console.log(greeter.greet()); 12 | -------------------------------------------------------------------------------- /test/fixtures/start-consistency/child.js: -------------------------------------------------------------------------------- 1 | 2 | require('pmx').init({ 3 | http : true 4 | }); 5 | 6 | var http = require('http'); 7 | 8 | var server = http.createServer(function(req, res) { 9 | res.writeHead(200); 10 | res.end('hey'); 11 | }).listen(8000); 12 | -------------------------------------------------------------------------------- /examples/v1/001-test.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | setInterval(function() { 5 | console.log('log message from echo.js'); 6 | }, 1500); 7 | 8 | setTimeout(function() { 9 | setInterval(function() { 10 | console.error('err msg from echo.js'); 11 | }, 1500); 12 | }, 750); 13 | -------------------------------------------------------------------------------- /examples/v1/start-args.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | var pm2 = require('..'); 4 | 5 | pm2.connect(function() { 6 | pm2.start(__dirname + '/args.js', { 7 | scriptArgs : ['-i', 'sisi', '-x', 'toto'] 8 | }, function(err, res) { 9 | console.log(arguments); 10 | }); 11 | }); 12 | -------------------------------------------------------------------------------- /test/fixtures/001-test.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | setInterval(function() { 5 | console.log('log message from echo.js'); 6 | }, 1500); 7 | 8 | setTimeout(function() { 9 | setInterval(function() { 10 | console.error('err msg from echo.js'); 11 | }, 1500); 12 | }, 750); 13 | -------------------------------------------------------------------------------- /test/fixtures/env-refreshed.json: -------------------------------------------------------------------------------- 1 | [{ 2 | "name" : "appname", 3 | "script" : "./env.js", 4 | "out_file" : "out-env.log", 5 | "merge_logs" : true, 6 | "env": { 7 | "NODE_ENV": "production", 8 | "TEST_VARIABLE": { "HEYYYY": true } 9 | } 10 | }] 11 | -------------------------------------------------------------------------------- /examples/transpilers/echo.ts: -------------------------------------------------------------------------------- 1 | 2 | class Greeter { 3 | constructor(public greeting: string) { } 4 | greet() { 5 | return "

" + this.greeting + "

"; 6 | } 7 | }; 8 | 9 | var greeter = new Greeter("Hello, world!"); 10 | 11 | console.log(greeter.greet()); 12 | -------------------------------------------------------------------------------- /examples/v1/auto-restart-all.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | var pm2 = require('..'); 5 | 6 | setTimeout(function() { 7 | pm2.connect(function() { 8 | pm2.restart('all', function() { 9 | pm2.disconnect(function() { 10 | 11 | }); 12 | }); 13 | }); 14 | }, 3000); 15 | -------------------------------------------------------------------------------- /lib/API/interpreter.json: -------------------------------------------------------------------------------- 1 | { 2 | ".sh" : "bash", 3 | ".py" : "python", 4 | ".rb" : "ruby", 5 | ".php" : "php", 6 | ".pl" : "perl", 7 | ".js" : "node", 8 | ".coffee" : "coffee", 9 | ".ls" : "lsc", 10 | ".ts" : "ts-node" 11 | } 12 | -------------------------------------------------------------------------------- /lib/templates/logrotate.d/pm2: -------------------------------------------------------------------------------- 1 | %HOME_PATH%/pm2.log %HOME_PATH%/logs/* { 2 | rotate 12 3 | weekly 4 | missingok 5 | notifempty 6 | compress 7 | delaycompress 8 | copytruncate 9 | create 0640 %USER% %USER% 10 | } 11 | -------------------------------------------------------------------------------- /packager/debian/description: -------------------------------------------------------------------------------- 1 | Advanced Process Manager 2 | PM2: Process Manager for Node.js 3 | 4 | PM2 is a Process Manager mainly for Node.js that allows to automatically increase performance and stability while enhancing the process management experience for developer and DevOps. 5 | -------------------------------------------------------------------------------- /test/fixtures/interface/promise_rejection.js: -------------------------------------------------------------------------------- 1 | var p = new Promise(function(resolve, reject) { 2 | //setTimeout(function() { 3 | //throw new Error('fail') 4 | abc = asdsad; 5 | 6 | return resolve('ok') 7 | //}, 200) 8 | }) 9 | 10 | p.then(function(e) { 11 | }) 12 | -------------------------------------------------------------------------------- /test/fixtures/yaml-configuration/apps.yml: -------------------------------------------------------------------------------- 1 | apps: 2 | - name: test 3 | script: echo.js 4 | - name: HTTP 5 | script: child.js 6 | instances: 4 7 | - name: PythonApp 8 | script: echo.py 9 | interpreter: /usr/bin/python3 10 | interpreter_args: -u 11 | -------------------------------------------------------------------------------- /test/fixtures/send-data-process/return-data.js: -------------------------------------------------------------------------------- 1 | 2 | process.on('message', function(packet) { 3 | if (packet.topic == 'process:msg') { 4 | process.send({ 5 | topic : 'process:msg', 6 | data : { 7 | success : true 8 | } 9 | }); 10 | } 11 | }); 12 | -------------------------------------------------------------------------------- /test/fixtures/source-map/main.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"main.js","sourceRoot":"","sources":["../app/main.ts"],"names":[],"mappings":";AACA,uBAA0B,UAAU,CAAC,CAAA;AAErC,OAAO,CAAC,GAAG,CAAC,oBAAW,CAAC,CAAC;AAEzB,UAAU,CAAC;IACT,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC;AAC1B,CAAC,EAAE,IAAI,CAAC,CAAC"} -------------------------------------------------------------------------------- /examples/v1/args.js: -------------------------------------------------------------------------------- 1 | 2 | process.argv.forEach(function (val, index, array) { 3 | console.log(index + ': ' + val); 4 | }); 5 | 6 | console.log('Argv2 = ', process.argv[2]); 7 | 8 | setInterval(function() { 9 | console.log('HERE ARE MY ARGS !!! = ', process.argv); 10 | }, 800); 11 | -------------------------------------------------------------------------------- /test/fixtures/git/info/exclude: -------------------------------------------------------------------------------- 1 | # git ls-files --others --exclude-from=.git/info/exclude 2 | # Lines that start with '#' are comments. 3 | # For a project mostly in C, the following would be a good set of 4 | # exclude patterns (uncomment them if you want to use them): 5 | # *.[oa] 6 | # *~ 7 | -------------------------------------------------------------------------------- /test/fixtures/throw-later.json: -------------------------------------------------------------------------------- 1 | { 2 | "apps" : [{ 3 | "name" : "throw-later", 4 | "script" : "throw-later.js", 5 | "error_file" : "err.log", 6 | "out_file" : "out.log", 7 | "log_file" : "entire.log", 8 | "merge_logs" : true 9 | }] 10 | } 11 | -------------------------------------------------------------------------------- /test/fixtures/watch/app.json: -------------------------------------------------------------------------------- 1 | { 2 | apps: [{ 3 | script : 'http.js', 4 | name : 'http', 5 | watch : false, 6 | env : { 7 | SHOULDBETHERE : 'toto' 8 | }, 9 | env_production : { 10 | SHOULDBETHERE : 'TYPEENV PRODUCTION' 11 | } 12 | }] 13 | } 14 | -------------------------------------------------------------------------------- /lib/templates/Dockerfiles/Dockerfile-nodejs.tpl: -------------------------------------------------------------------------------- 1 | FROM mhart/alpine-node:latest 2 | 3 | RUN apk update && apk add git && rm -rf /var/cache/apk/* 4 | RUN npm install pm2@next -g 5 | RUN mkdir -p /var/app 6 | 7 | WORKDIR /var/app 8 | 9 | COPY ./package.json /var/app 10 | RUN npm install 11 | -------------------------------------------------------------------------------- /packager/debian/copyright: -------------------------------------------------------------------------------- 1 | Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ 2 | Upstream-Name: PM2 3 | Upstream-Contact: Alexandre Strzelewicz 4 | Source: http://pm2.o/ 5 | 6 | Files: * 7 | Copyright: 2013-present, Keymetrics 8 | License: AGPLv3 9 | -------------------------------------------------------------------------------- /test/fixtures/module-fixture/node_modules/pmx/test/event.mock.js: -------------------------------------------------------------------------------- 1 | 2 | var axm = require('..'); 3 | 4 | setInterval(function() { 5 | axm.emit('test', { 6 | user : 'toto', 7 | subobj : { 8 | subobj : { 9 | a : 'b' 10 | } 11 | } 12 | }); 13 | }, 100); 14 | -------------------------------------------------------------------------------- /examples/echo.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | setInterval(function() { 4 | console.log('log message from echo.js'); 5 | console.warn({ json : true }); 6 | }, 1500); 7 | 8 | setTimeout(function() { 9 | setInterval(function() { 10 | console.error('err msg from echo.js'); 11 | }, 1500); 12 | }, 750); 13 | -------------------------------------------------------------------------------- /test/fixtures/cron/mock-cron-no-exit.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | setTimeout(function() { 4 | process.send({ 5 | 'cron_restart' : 1 6 | }); 7 | }, 1000); 8 | 9 | process.on('SIGINT', function() { 10 | console.log('SIGINT signal received'); 11 | }); 12 | 13 | setInterval(function() { 14 | }, 100); 15 | -------------------------------------------------------------------------------- /test/fixtures/module-fixture/node_modules/pmx/test/proc.mock.js: -------------------------------------------------------------------------------- 1 | 2 | var axm = require('..'); 3 | 4 | axm.action('test:nab', {comment : 'This is a test', display : true}, function(reply) { 5 | console.log('CHILD: Action test called from external process'); 6 | reply({ res : 'hello moto'}); 7 | }); 8 | -------------------------------------------------------------------------------- /examples/process-metrics.js: -------------------------------------------------------------------------------- 1 | 2 | var Probe = require('pmx').probe(); 3 | 4 | var counter = 0; 5 | 6 | var metric = Probe.metric({ 7 | name : 'Counter', 8 | value : function() { 9 | return counter; 10 | } 11 | }); 12 | 13 | setInterval(function() { 14 | counter++; 15 | }, 100); 16 | -------------------------------------------------------------------------------- /examples/v1/echo.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | setInterval(function() { 4 | console.log('log message from echo.js'); 5 | console.warn({ json : true }); 6 | }, 1500); 7 | 8 | setTimeout(function() { 9 | setInterval(function() { 10 | console.error('err msg from echo.js'); 11 | }, 1500); 12 | }, 750); 13 | -------------------------------------------------------------------------------- /test/fixtures/docker/expressor/app.js: -------------------------------------------------------------------------------- 1 | 2 | var express = require('express'); 3 | var app = express(); 4 | 5 | app.get('/', function (req, res) { 6 | res.send('Hello Bro! yes'); 7 | }); 8 | 9 | app.listen(3000, function () { 10 | console.log('Example app listening on port 3000!'); 11 | }); 12 | -------------------------------------------------------------------------------- /test/fixtures/module-fixture/node_modules/pmx/test/proc-option.mock.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | var axm = require('..'); 4 | 5 | axm.action('test:with:options', function(options, reply) { 6 | console.log('CHILD: Action test called from external process'); 7 | reply({ res : 'hello moto', options : options}); 8 | }); 9 | -------------------------------------------------------------------------------- /test/fixtures/custom_actions/index.js: -------------------------------------------------------------------------------- 1 | 2 | var pmx = require('pmx'); 3 | 4 | pmx.action('ping', function(reply) { 5 | return reply({ 'pong' : 'hehe' }) 6 | }); 7 | 8 | pmx.action('param', function(data, reply) { 9 | return reply(data) 10 | }); 11 | 12 | setInterval(function() { 13 | }, 1000); 14 | -------------------------------------------------------------------------------- /examples/custom-action/index.js: -------------------------------------------------------------------------------- 1 | 2 | var pmx = require('pmx'); 3 | 4 | pmx.action('ping', function(reply) { 5 | return reply({ 'pong' : 'hehe' }) 6 | }); 7 | 8 | pmx.action('param', function(data, reply) { 9 | return reply({ data : data }) 10 | }); 11 | 12 | setInterval(function() { 13 | }, 1000); 14 | -------------------------------------------------------------------------------- /examples/tcp.js: -------------------------------------------------------------------------------- 1 | var net = require('net'); 2 | 3 | var server = net.createServer(function (socket) { 4 | socket.write('Welcome to the Telnet server of the process' + (process.env.NODE_APP_INSTANCE || 'must be run on pm2')); 5 | }).listen(8888, function() { 6 | console.log('Listening on port %s', 8888); 7 | }); 8 | -------------------------------------------------------------------------------- /examples/v1/apps/echo-pm2.json: -------------------------------------------------------------------------------- 1 | { 2 | "script" : "examples/echo.js", 3 | "error_file" : "errEcho.log", 4 | "out_file" : "outEcho.log", 5 | "name" : "ok", 6 | "pid_file" : "echo.pid", 7 | "max" : "1", 8 | "exec_mode" : "cluster_mode", 9 | "port" : "9001", 10 | "env_variable" : "TOTO" 11 | } 12 | -------------------------------------------------------------------------------- /test/fixtures/env-switching/app.json: -------------------------------------------------------------------------------- 1 | { 2 | script : './child.js', 3 | // Default environment 4 | env : { 5 | NODE_ENV : 'normal' 6 | }, 7 | // Prod 8 | env_production : { 9 | NODE_ENV : 'production' 10 | }, 11 | // Test 12 | env_test : { 13 | NODE_ENV : 'test' 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /test/fixtures/append-env-to-name.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name": "web", 4 | "script": "echo.js", 5 | "append_env_to_name": true, 6 | "env_dev": { 7 | "NODE_ENV": "dev", 8 | "PORT": 4000 9 | }, 10 | "env_prod": { 11 | "NODE_ENV": "prod", 12 | "PORT": 3000 13 | } 14 | } 15 | ] -------------------------------------------------------------------------------- /test/fixtures/change_cwd.json: -------------------------------------------------------------------------------- 1 | [{ 2 | "name" : "iminpath1", 3 | "script" : "iminpath1.js", 4 | "cwd" : "path1", 5 | "out_file" : "./iminpath1.log" 6 | },{ 7 | "name" : "iminpath2", 8 | "script" : "iminpath2.js", 9 | "cwd" : "path1/path2", 10 | "out_file" : "./iminpath2.log" 11 | }] 12 | -------------------------------------------------------------------------------- /test/fixtures/json-reload/echo-post.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "echo-json", 3 | "script" : "echo-env.js", 4 | "log_date_format" : "DD", 5 | "out_file" : "echo-test.log", 6 | "merge_logs" : true, 7 | "env" : { 8 | "ECHO_MSG" : "YAY" 9 | }, 10 | "env_production" : { 11 | "ECHO_MSG" : "WOW" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /test/fixtures/path-check.js: -------------------------------------------------------------------------------- 1 | console.log(__filename); 2 | console.log(module.filename); 3 | console.log(module.parent); 4 | console.log(module.children); 5 | console.log(__dirname); 6 | console.log(module); 7 | console.log(process.env.PWD); 8 | console.log(require.main.filename); 9 | console.log(require.main === module); 10 | -------------------------------------------------------------------------------- /test/fixtures/yaml-configuration/apps.yaml: -------------------------------------------------------------------------------- 1 | apps: 2 | - name: test 3 | script: echo.js 4 | - name: HTTP 5 | script: child.js 6 | instances: 4 7 | - name: PythonApp 8 | script: echo.py 9 | interpreter: /usr/bin/python3 10 | interpreter_args: -u 11 | env: 12 | DEFAULT_STR: 'PYTHONENV' 13 | -------------------------------------------------------------------------------- /examples/v1/child.js: -------------------------------------------------------------------------------- 1 | 2 | var http = require('http'); 3 | 4 | var server = http.createServer(function(req, res) { 5 | res.writeHead(200); 6 | res.end('hey'); 7 | }).listen(process.env.PORT || 8000, function() { 8 | console.log('App listening on port %d in env %s', process.env.PORT || 8000, process.env.NODE_ENV); 9 | }); 10 | -------------------------------------------------------------------------------- /examples/binary/http.js: -------------------------------------------------------------------------------- 1 | 2 | var http = require('http'); 3 | 4 | var server = http.createServer(function(req, res) { 5 | res.writeHead(200); 6 | res.end('hey'); 7 | }).listen(process.env.PORT || 8000, function() { 8 | console.log('App listening on port %d in env %s', process.env.PORT || 8000, process.env.NODE_ENV); 9 | }); 10 | -------------------------------------------------------------------------------- /examples/pmx/elements/histogram.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | const pmx = require('pmx'); 4 | const Probe = pmx.probe(); 5 | 6 | var metric = Probe.histogram({ 7 | name : 'Histogram' 8 | }); 9 | 10 | var latency; 11 | 12 | setInterval(function() { 13 | latency = Math.round(Math.random() * 100); 14 | metric.update(latency); 15 | }, 100); 16 | -------------------------------------------------------------------------------- /examples/v1/apps/all-pm2.json: -------------------------------------------------------------------------------- 1 | [{ 2 | "name" : "echo", 3 | "script" : "./examples/echo.js", 4 | "instances" : "1" 5 | },{ 6 | "name" : "api", 7 | "script" : "./examples/child.js", 8 | "instances" : "4", 9 | "error_file" : "./examples/child-err.log", 10 | "out_file" : "./examples/child-out.log" 11 | }] 12 | -------------------------------------------------------------------------------- /packager/deploy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | VERSION=`node dist/bin/pm2 --version` 4 | CMD_SEND="artifacts/pm2_${VERSION}_all.deb marketing@ssh.km:~/packages" 5 | CMD_PUB="cd /var/www/apt/ubuntu; reprepro includedeb xenial ~/packages/pm2_${VERSION}_all.deb" 6 | 7 | echo $CMD_PUB 8 | scp $CMD_SEND 9 | ssh marketing@ssh.km -C $CMD_PUB 10 | -------------------------------------------------------------------------------- /test/fixtures/git/config: -------------------------------------------------------------------------------- 1 | [core] 2 | repositoryformatversion = 0 3 | filemode = true 4 | bare = false 5 | logallrefupdates = true 6 | [remote "origin"] 7 | url = https://github.com/jshkurti/pm2_travis.git 8 | fetch = +refs/heads/*:refs/remotes/origin/* 9 | [branch "master"] 10 | remote = origin 11 | merge = refs/heads/master 12 | -------------------------------------------------------------------------------- /examples/pmx/elements/metric.js: -------------------------------------------------------------------------------- 1 | 2 | const pmx = require('pmx'); 3 | const Probe = pmx.probe(); 4 | 5 | var data = 10; 6 | 7 | var metric = Probe.metric({ 8 | name : 'Realtime user', 9 | value : function() { 10 | return data; 11 | } 12 | }); 13 | 14 | setInterval(function() { 15 | data = Math.random(); 16 | }, 500); 17 | -------------------------------------------------------------------------------- /examples/process-file/http.js: -------------------------------------------------------------------------------- 1 | 2 | var http = require('http'); 3 | 4 | var server = http.createServer(function(req, res) { 5 | res.writeHead(200); 6 | res.end('hey'); 7 | }).listen(process.env.PORT || 8000, function() { 8 | console.log('App listening on port %d in env %s', process.env.PORT || 8000, process.env.NODE_ENV); 9 | }); 10 | -------------------------------------------------------------------------------- /examples/custom-action/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "custom-action", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "dependencies" : { 7 | "pmx" : "*" 8 | }, 9 | "scripts": { 10 | "test": "echo \"Error: no test specified\" && exit 1" 11 | }, 12 | "author": "", 13 | "license": "ISC" 14 | } 15 | -------------------------------------------------------------------------------- /test/fixtures/all.json: -------------------------------------------------------------------------------- 1 | [{ 2 | "name" : "echo", 3 | "script" : "./echo.js" 4 | },{ 5 | "name" : "child", 6 | "script" : "./child.js", 7 | "instances" : "4", 8 | "error_file" : "./child-err.log", 9 | "out_file" : "./child-out.log" 10 | },{ 11 | "name" : "api-2", 12 | "script" : "./server.js" 13 | }] 14 | -------------------------------------------------------------------------------- /test/fixtures/nvm-node-version/http.js: -------------------------------------------------------------------------------- 1 | 2 | var http = require('http'); 3 | 4 | var server = http.createServer(function(req, res) { 5 | res.writeHead(200); 6 | res.end('hey'); 7 | }).listen(process.env.PORT || 8000, function() { 8 | console.log('App listening on port %d in env %s', process.env.PORT || 8000, process.env.NODE_ENV); 9 | }); 10 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "0.12" 4 | - "4" 5 | - "6" 6 | - "7" 7 | os: 8 | - linux 9 | before_install: 10 | - sudo apt-get -qq update 11 | - sudo apt-get install python3 12 | - sudo apt-get install php5-cli 13 | services: 14 | - docker 15 | notifications: 16 | slack: pm2-nodejs:5Lolyw2LMnwy8fziqOGILQxG 17 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013 the PM2 project authors. All rights reserved. 3 | * Use of this source code is governed by a license that 4 | * can be found in the LICENSE file. 5 | */ 6 | 7 | process.env.PM2_PROGRAMMATIC = 'true'; 8 | 9 | var API = require('./lib/API.js'); 10 | 11 | module.exports = new API; 12 | module.exports.custom = API; 13 | -------------------------------------------------------------------------------- /test/fixtures/configuration.js: -------------------------------------------------------------------------------- 1 | [{ 2 | name : "echo", 3 | script : [".", "/", "e", "cho.js"].join('') 4 | },{ 5 | name : "child", 6 | script : "./child.js", 7 | instances : "4", 8 | error_file : "./child-err.log", 9 | out_file : "./child-out.log" 10 | },{ 11 | name : "api-2", 12 | script : "./server.js" 13 | }] 14 | -------------------------------------------------------------------------------- /test/fixtures/cron/mock-cron.js: -------------------------------------------------------------------------------- 1 | 2 | setTimeout(function() { 3 | process.send({ 4 | 'cron_restart' : 1 5 | }); 6 | }, 1000); 7 | 8 | process.on('SIGINT', function() { 9 | console.log('SIGINT signal received'); 10 | setTimeout(function() { 11 | process.exit(0); 12 | }, 1000); 13 | }); 14 | 15 | setInterval(function() { 16 | }, 100); 17 | -------------------------------------------------------------------------------- /test/fixtures/interface/process_exception_with_logs.js: -------------------------------------------------------------------------------- 1 | 2 | var pmx = require('pmx'); 3 | 4 | pmx.action('exception', function(reply) { 5 | console.log('Im going to crash'); 6 | console.log('I will crash muhahah'); 7 | throw new Error('CRASHED'); 8 | 9 | return reply({ sucess: true}); 10 | }); 11 | 12 | setInterval(function() { 13 | }, 1000); 14 | -------------------------------------------------------------------------------- /test/fixtures/module-fixture/node_modules/pmx/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2 | # 0.2.27 3 | 4 | - Remove debug message 5 | - Rename module 6 | - Auto instanciation 7 | 8 | # 0.2.25 9 | 10 | - Add ip address on each transaction 11 | 12 | # 0.2.24 13 | 14 | - Add unit option for Histogram and Meter 15 | 16 | # 0.2.23 17 | 18 | - Include Counter, Meter, Metric and Histogram 19 | -------------------------------------------------------------------------------- /examples/keymetrics-integration/auto-init.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | var pmx = require('pmx').init(); 4 | 5 | var http = require('http'); 6 | 7 | http.createServer(function(req, res) { 8 | res.writeHead(200); 9 | res.end('hey'); 10 | }).listen(8005); 11 | 12 | pmx.action('refresh:db2', {comment : 'Refresh main database'}, function(reply) { 13 | throw new Error('hey'); 14 | }); 15 | -------------------------------------------------------------------------------- /examples/v1/apps/env-pm2.json: -------------------------------------------------------------------------------- 1 | { 2 | "script" : "examples/env.js", 3 | "error_file" : "errEcho.log", 4 | "out_file" : "outEcho.log", 5 | "name" : "ok", 6 | "pid_file" : "echo.pid", 7 | "max" : "1", 8 | "exec_mode" : "cluster_mode", 9 | "port" : "9001", 10 | "env_variable" : "TOTO", 11 | "TEST_VARIABLE" : "YESSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSIR" 12 | } 13 | -------------------------------------------------------------------------------- /examples/v1/expose_method.js: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Example of usage : https://github.com/Unitech/pm2/pull/214 4 | */ 5 | process.on("message", function (msg) { 6 | console.log('got message', msg); 7 | if ( "type" in msg && msg.type === "god:heap" ) { 8 | var heap = process.memoryUsage().heapUsed; 9 | process.send({type:"process:heap", heap:heap}); 10 | } 11 | }); 12 | -------------------------------------------------------------------------------- /packager/build-dist.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -ex 4 | 5 | #npm run build 6 | npm pack 7 | rm -rf dist 8 | mkdir dist 9 | mv pm2-*.tgz dist/pack.tgz 10 | 11 | cd dist 12 | tar -xzf pack.tgz --strip 1 13 | rm -rf pack.tgz 14 | npm install --production 15 | cd .. 16 | 17 | tar -cvzf dist/pm2-v`node dist/bin/pm2 --version`.tar.gz dist/* 18 | shasum -a 256 dist/pm2-*.tar.gz 19 | -------------------------------------------------------------------------------- /test/fixtures/homogen-json-action/http.js: -------------------------------------------------------------------------------- 1 | var pmx = require('pmx').init({ 2 | http : true 3 | }); 4 | 5 | var probe = pmx.probe(); 6 | 7 | var http = require('http'); 8 | 9 | var server = http.createServer(function(req, res) { 10 | res.writeHead(200); 11 | res.end('hey'); 12 | }).listen(8000, function() { 13 | console.log('App listening on port 8000'); 14 | }); 15 | -------------------------------------------------------------------------------- /examples/v1/tree.js: -------------------------------------------------------------------------------- 1 | 2 | var spawn = require('child_process').spawn, 3 | grep = spawn('top', [], { stdio: 'inherit' }); 4 | 5 | 6 | var http = require('http'); 7 | 8 | 9 | var normal = require('child_process').fork('examples/child.js', ['normal']); 10 | 11 | http.createServer(function(req, res) { 12 | res.writeHead(200); 13 | res.end('hoy'); 14 | }).listen(8010); 15 | -------------------------------------------------------------------------------- /test/fixtures/echo-post.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "echo-json", 3 | "script" : "echo-env.js", 4 | "log_date_format" : "DD", 5 | "out_file" : "echo-test.log", 6 | "merge_logs" : true, 7 | "env" : { 8 | "ECHO_MSG" : "YAY" 9 | }, 10 | "env_production" : { 11 | "ECHO_MSG" : "WOW" 12 | }, 13 | "env_testing" : { 14 | "ECHO_MSG" : "TEST" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /test/fixtures/module-fixture/node_modules/pmx/test/express/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "express", 3 | "version": "0.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "dependencies" : { 10 | "express" : "*" 11 | }, 12 | "author": "", 13 | "license": "ISC" 14 | } 15 | -------------------------------------------------------------------------------- /examples/custom-nodejs-version/ecosystem.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | /** 3 | * Application configuration section 4 | * http://pm2.keymetrics.io/docs/usage/application-declaration/ 5 | */ 6 | apps : [ 7 | // First application 8 | { 9 | name : "API", 10 | script : "http.js", 11 | interpreter : "node@6.9.0" 12 | } 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /test/fixtures/module-fixture/node_modules/pmx/test/transaction/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "transaction", 3 | "version": "0.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "devDependencies" : { 10 | "express" : "*" 11 | }, 12 | "author": "", 13 | "license": "ISC" 14 | } 15 | -------------------------------------------------------------------------------- /test/bash/piped-config.sh: -------------------------------------------------------------------------------- 1 | 2 | #!/usr/bin/env bash 3 | 4 | SRC=$(cd $(dirname "$0"); pwd) 5 | source "${SRC}/include.sh" 6 | 7 | cd $file_path 8 | 9 | ############# TEST 10 | 11 | echo -e "\033[1mRunning tests:\033[0m" 12 | 13 | cat all.json | $pm2 start - 14 | should 'should start processes' 'online' 6 15 | 16 | cat all.json | $pm2 delete - 17 | should 'should delete all processes' 'name' 0 18 | -------------------------------------------------------------------------------- /test/fixtures/containerizer/Dockerfile.dev: -------------------------------------------------------------------------------- 1 | FROM mhart/alpine-node:latest 2 | 3 | RUN apk update && apk add git && rm -rf /var/cache/apk/* 4 | RUN npm install pm2@next -g 5 | RUN mkdir -p /var/app 6 | 7 | WORKDIR /var/app 8 | 9 | COPY ./package.json /var/app 10 | RUN npm install 11 | 12 | ## DEVELOPMENT MODE 13 | ENV NODE_ENV=development 14 | CMD ["pm2-docker", "start", "--auto-exit", "index.js"] 15 | -------------------------------------------------------------------------------- /test/fixtures/module-fixture/node_modules/pmx/test/fixtures/module/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "module", 3 | "version": "1.0.0", 4 | "description": "comment", 5 | "main": "module.fixture.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "config" : { 10 | "initial" : "init-val" 11 | }, 12 | "author": "strzel", 13 | "license": "ISC" 14 | } 15 | -------------------------------------------------------------------------------- /examples/module-init/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "init-module", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "apps" : [{ 10 | "script" : "index.js", 11 | "env" : { 12 | "PM2_WAIT_FOR_INIT" : 500 13 | } 14 | }], 15 | "author": "", 16 | "license": "ISC" 17 | } 18 | -------------------------------------------------------------------------------- /test/bash/append-env-to-name.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | SRC=$(cd $(dirname "$0"); pwd) 4 | source "${SRC}/include.sh" 5 | 6 | cd $file_path 7 | 8 | ## Test #1 9 | 10 | $pm2 start append-env-to-name.json --env dev 11 | should 'have started app with name web-dev' "name: 'web-dev'" 3 12 | 13 | $pm2 start append-env-to-name.json --env prod 14 | should 'have started same app with name : web-prod' "name: 'web-prod'" 3 -------------------------------------------------------------------------------- /test/benchmarks/monit-daemon.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | while [ true ] 4 | do 5 | PM2_PID=`pgrep "pm2: Daemon" -o` 6 | 7 | # Run garbage collector 8 | kill -SIGILL $PM2_PID 9 | sleep 5 10 | 11 | FILE="/proc/$PM2_PID/smaps" 12 | Rss=`echo 0 $(cat $FILE | grep Rss | awk '{print $2}' | sed 's#^#+#') | bc;` 13 | 14 | echo `date +%H:%M:%S` $Rss >> $RESULT_FILE 15 | sleep 100 16 | done 17 | -------------------------------------------------------------------------------- /test/fixtures/configuration.json: -------------------------------------------------------------------------------- 1 | // TG! 2 | [{ 3 | // Application 1 4 | name : "echo", 5 | script : [".", "/", "e", "cho.js"].join('') 6 | },{ 7 | // APplication 2 8 | name : "child", 9 | script : "./child.js", 10 | instances : "4", 11 | error_file : "./child-err.log", 12 | out_file : "./child-out.log" 13 | },{ 14 | name : "api-2", 15 | script : "./server.js" 16 | }] 17 | -------------------------------------------------------------------------------- /test/fixtures/docker/expressor/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@keymetrics/expressor", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "express": "^4.14.0", 13 | "passport" : "*", 14 | "redis" : "*" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /test/fixtures/containerizer/Dockerfile.prod: -------------------------------------------------------------------------------- 1 | FROM mhart/alpine-node:latest 2 | 3 | RUN apk update && apk add git && rm -rf /var/cache/apk/* 4 | RUN npm install pm2@next -g 5 | RUN mkdir -p /var/app 6 | 7 | WORKDIR /var/app 8 | 9 | COPY ./package.json /var/app 10 | RUN npm install 11 | 12 | ## PRODUCTION MODE 13 | ENV NODE_ENV=production 14 | COPY . /var/app/ 15 | CMD ["pm2-docker", "start", "--auto-exit", "index.js"] 16 | -------------------------------------------------------------------------------- /test/fixtures/module-fixture/node_modules/pmx/test/fixtures/scoped-action.fixture.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | var pmx = require('../..'); 4 | 5 | pmx.scopedAction('scoped:action', function(opts, res) { 6 | var i = setInterval(function() { 7 | // Emit progress data 8 | res.send('data random'); 9 | }, 100); 10 | 11 | setTimeout(function() { 12 | clearInterval(i); 13 | res.end('end data'); 14 | }, 800); 15 | }); 16 | -------------------------------------------------------------------------------- /test/fixtures/local_require.js: -------------------------------------------------------------------------------- 1 | var paths = require('module').globalPaths; 2 | 3 | if (Array.isArray(paths)) { 4 | var found = false; 5 | paths.forEach(function(elem) { 6 | if (elem === process.env.NODE_PATH) { 7 | found = true; 8 | } 9 | }); 10 | 11 | if (!found) 12 | process.exit(1); 13 | else 14 | setInterval(function keepAlive() {}, 10000); 15 | } 16 | else { 17 | process.exit(1); 18 | } 19 | -------------------------------------------------------------------------------- /test/fixtures/module-fixture/node_modules/pmx/test/fixtures/monitor.mock.js: -------------------------------------------------------------------------------- 1 | 2 | var axm = require('../..'); 3 | 4 | var obj = axm.enableProbes(); 5 | 6 | var i = 2; 7 | 8 | obj.it_works = true; 9 | obj.value = 20; 10 | obj.i = i; 11 | 12 | setTimeout(function() { 13 | i = 4; 14 | obj.it_works = false; 15 | obj.value = 99; 16 | 17 | setTimeout(function() { 18 | axm.stopProbes(); 19 | }, 1100); 20 | }, 1100); 21 | -------------------------------------------------------------------------------- /test/fixtures/path-resolution/ecosystem2.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | /** 3 | * Application configuration section 4 | * http://pm2.keymetrics.io/docs/usage/application-declaration/ 5 | */ 6 | apps : [ 7 | { 8 | name : "test", 9 | script : "./echo.js", 10 | out_file : 'echo-out.log', 11 | error_file : 'echo-err.log', 12 | pid_file : 'echo-pid.log' 13 | } 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /examples/signals/http.js: -------------------------------------------------------------------------------- 1 | 2 | process.on('SIGINT', function() { 3 | console.log('Exiting'); 4 | process.exit(0); 5 | }); 6 | 7 | var http = require('http'); 8 | 9 | var server = http.createServer(function(req, res) { 10 | res.writeHead(200); 11 | res.end('hey'); 12 | }).listen(process.env.PORT || 8000, function() { 13 | console.log('App listening on port %d in env %s', process.env.PORT || 8000, process.env.NODE_ENV); 14 | }); 15 | -------------------------------------------------------------------------------- /examples/v1/interact.js: -------------------------------------------------------------------------------- 1 | 2 | var pm2 = require('..'); 3 | 4 | var MACHINE_NAME = 'hk1'; 5 | var PRIVATE_KEY = 'z1ormi95vomgq66'; 6 | var PUBLIC_KEY = 'oa0m7nuhdfibi16'; 7 | 8 | pm2.connect(true, function() { 9 | pm2.start({ 10 | script : '../test/fixtures/child.js', 11 | name : 'production-app' 12 | }, function() { 13 | pm2.interact(PRIVATE_KEY, PUBLIC_KEY, MACHINE_NAME, function() { 14 | }); 15 | }); 16 | }); 17 | -------------------------------------------------------------------------------- /test/fixtures/path-resolution/ecosystem.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | /** 3 | * Application configuration section 4 | * http://pm2.keymetrics.io/docs/usage/application-declaration/ 5 | */ 6 | apps : [ 7 | { 8 | name : "test", 9 | script : "./echo.js", 10 | out_file : '~/echo-out.log', 11 | error_file : '~/echo-err.log', 12 | pid_file : '~/echo-pid.log' 13 | } 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /examples/v1/beforeExit.js: -------------------------------------------------------------------------------- 1 | 2 | var stopped = false; 3 | 4 | function work() { 5 | console.log('working'); 6 | !stopped && setTimeout(work, 1000); 7 | } 8 | 9 | function stop() { 10 | console.log('shutting down'); 11 | stopped = true; 12 | } 13 | 14 | process.once('SIGINT', stop); // CTRL-C 15 | 16 | process.on('beforeExit', function() { 17 | console.log('exited cleanly :)'); 18 | process.exit(0); 19 | }); 20 | 21 | work(); 22 | -------------------------------------------------------------------------------- /examples/v1/null.js: -------------------------------------------------------------------------------- 1 | var pmx = require('pmx'); 2 | var http = require('http'); 3 | 4 | http.createServer(function(req, res) { 5 | res.end('Thanks'); 6 | }).listen(5445); 7 | 8 | pmx.action('db:test', {comment: 'Simply test'}, function(reply) { 9 | reply({test: "WOWOWOWOWOW", length: 12}); 10 | }); 11 | 12 | pmx.action('throw', {comment: 'Simply test'}, function(reply) { 13 | throw { success : 'false', length: 12 }; 14 | }); 15 | -------------------------------------------------------------------------------- /test/fixtures/delayed_exit.js: -------------------------------------------------------------------------------- 1 | var exit = function() { 2 | console.log("Delay exit in 2 secs"); 3 | setTimeout(function(){ 4 | process.exit(); 5 | }, 2000); 6 | }; 7 | 8 | process.on('SIGTERM', function() { 9 | console.log('Got SIGTERM signal.'); 10 | exit(); 11 | }); 12 | 13 | process.on('SIGINT', function() { 14 | console.log('Got SIGINT signal'); 15 | exit(); 16 | }); 17 | 18 | setInterval(function keepMeAlive() {}, 1000); 19 | -------------------------------------------------------------------------------- /examples/keymetrics-integration/process-transpose.js: -------------------------------------------------------------------------------- 1 | 2 | var Probe = require('pmx').probe(); 3 | 4 | var counter = 0; 5 | 6 | var metric = Probe.transpose({ 7 | name : 'data-flow', 8 | data : function() { 9 | return { 10 | a : { 11 | b : { 12 | data : 'textflow', 13 | array : [ 'yes', 'it', 'is' ] 14 | } 15 | } 16 | } 17 | } 18 | }); 19 | 20 | setInterval(function() { 21 | }, 100); 22 | -------------------------------------------------------------------------------- /test/fixtures/child.js: -------------------------------------------------------------------------------- 1 | 2 | var http = require('http'); 3 | 4 | http.createServer(function(req, res) { 5 | res.writeHead(200); 6 | res.end('hey'); 7 | }).listen(0); 8 | 9 | process.on('message', function(msg) { 10 | if (msg == 'shutdown') { 11 | console.log('Closing all connections...'); 12 | setTimeout(function() { 13 | console.log('Finished closing connections'); 14 | process.exit(0); 15 | }, 100); 16 | } 17 | }); 18 | -------------------------------------------------------------------------------- /test/fixtures/echo2.js: -------------------------------------------------------------------------------- 1 | 2 | var http = require('http'); 3 | 4 | http.createServer(function(req, res) { 5 | res.writeHead(200); 6 | res.end('hey'); 7 | }).listen(0); 8 | 9 | process.on('message', function(msg) { 10 | if (msg == 'shutdown') { 11 | console.log('Closing all connections...'); 12 | setTimeout(function() { 13 | console.log('Finished closing connections'); 14 | process.exit(0); 15 | }, 100); 16 | } 17 | }); 18 | -------------------------------------------------------------------------------- /test/fixtures/pm2-dev/app.js: -------------------------------------------------------------------------------- 1 | var http = require('http'); 2 | 3 | http.createServer(function(req, res) { 4 | res.writeHead(200); 5 | res.end('hey'); 6 | }).listen(0); 7 | 8 | process.on('message', function(msg) { 9 | if (msg == 'shutdown') { 10 | console.log('Closing all connections...'); 11 | setTimeout(function() { 12 | console.log('Finished closing connections'); 13 | process.exit(0); 14 | }, 100); 15 | } 16 | }); 17 | -------------------------------------------------------------------------------- /examples/v1/child-echo.json: -------------------------------------------------------------------------------- 1 | { 2 | "apps" : [{ 3 | "script":"examples/child.js", 4 | "name":"API-web", 5 | "instances":3 6 | },{ 7 | "script":"examples/echo.js", 8 | "instances":2 9 | }], 10 | "deploy" : { 11 | "production" : { 12 | "user" : "node", 13 | "host" : "212.83.163.168", 14 | "repo" : "git@github.com:Unitech/eip-vitrine.git", 15 | "path" : "/var/www/test-deploy" 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /test/fixtures/echo3.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | var http = require('http'); 4 | 5 | http.createServer(function(req, res) { 6 | res.writeHead(200); 7 | res.end('hey'); 8 | }).listen(0); 9 | 10 | process.on('message', function(msg) { 11 | if (msg == 'shutdown') { 12 | console.log('Closing all connections...'); 13 | setTimeout(function() { 14 | console.log('Finished closing connections'); 15 | process.exit(0); 16 | }, 100); 17 | } 18 | }); 19 | -------------------------------------------------------------------------------- /test/fixtures/module-fixture/node_modules/pmx/node_modules/debug/component.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "debug", 3 | "repo": "visionmedia/debug", 4 | "description": "small debugging utility", 5 | "version": "2.2.0", 6 | "keywords": [ 7 | "debug", 8 | "log", 9 | "debugger" 10 | ], 11 | "main": "browser.js", 12 | "scripts": [ 13 | "browser.js", 14 | "debug.js" 15 | ], 16 | "dependencies": { 17 | "rauchg/ms.js": "0.7.1" 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /examples/module-init/index.js: -------------------------------------------------------------------------------- 1 | 2 | var pmx = require('pmx'); 3 | 4 | /** 5 | * set "PM2_WAIT_FOR_INIT" : TIME to tell PM2 to show human infos 6 | */ 7 | pmx.configureModule({ 8 | human_info : [ 9 | [ 'Description', 'Gridcontrol is now running, tasdkkals dk als dkl askdl\nasd lsdakl kdsald asdsd\nAnd hthis like that and bla blab\nYESY!' ], 10 | [ 'Port', 8000], 11 | [ 'Grid name', 'Sisi la grid'] 12 | ] 13 | }); 14 | 15 | setInterval(() => {}, 1000); 16 | -------------------------------------------------------------------------------- /test/fixtures/interface/child.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | var http = require('http'); 5 | 6 | http.createServer(function(req, res) { 7 | res.writeHead(200); 8 | res.end('hey'); 9 | }).listen(8000); 10 | 11 | process.on('message', function(msg) { 12 | if (msg == 'shutdown') { 13 | console.log('Closing all connections...'); 14 | setTimeout(function() { 15 | console.log('Finished closing connections'); 16 | process.exit(0); 17 | }, 100); 18 | } 19 | }); 20 | -------------------------------------------------------------------------------- /examples/keymetrics-integration/custom_action.js: -------------------------------------------------------------------------------- 1 | 2 | var axm = require('pmx'); 3 | 4 | axm.action('getEnv', function(reply) { 5 | reply(process.env); 6 | }); 7 | 8 | axm.action('sayHello', function(reply) { 9 | reply({ 10 | msg : 'Yes hello and so? Xie Xie' 11 | }); 12 | }); 13 | 14 | axm.action('throwError', function(reply) { 15 | //@todo : replying a error does not work 16 | reply(new Error('Error thrown')); 17 | throw new Error('asdadsadsasd'); 18 | }); 19 | -------------------------------------------------------------------------------- /test/bash/get-set.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | SRC=$(cd $(dirname "$0"); pwd) 4 | source "${SRC}/include.sh" 5 | 6 | cd $file_path 7 | 8 | $pm2 unset all 9 | spec "Should unset all variables" 10 | 11 | ls ~/.pm2/module_conf.json 12 | spec "Should file exists" 13 | 14 | $pm2 set key1 val1 15 | cat ~/.pm2/module_conf.json | grep "key1" 16 | spec "Should key exists" 17 | 18 | $pm2 unset key1 19 | cat ~/.pm2/module_conf.json | grep "key1" 20 | ispec "Should key not exists" 21 | -------------------------------------------------------------------------------- /test/fixtures/yaml-configuration/child.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | var http = require('http'); 5 | 6 | http.createServer(function(req, res) { 7 | res.writeHead(200); 8 | res.end('hey'); 9 | }).listen(8000); 10 | 11 | process.on('message', function(msg) { 12 | if (msg == 'shutdown') { 13 | console.log('Closing all connections...'); 14 | setTimeout(function() { 15 | console.log('Finished closing connections'); 16 | process.exit(0); 17 | }, 100); 18 | } 19 | }); 20 | -------------------------------------------------------------------------------- /test/bash/listen-timeout.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | #export PM2_GRACEFUL_LISTEN_TIMEOUT=1000 4 | 5 | SRC=$(cd $(dirname "$0"); pwd) 6 | source "${SRC}/include.sh" 7 | cd $file_path/listen-timeout/ 8 | 9 | echo -e "\033[1mENV REFRESH\033[0m" 10 | 11 | $pm2 start wait-ready.js -i 1 --wait-ready --listen-timeout 5000 12 | 13 | timeout 2 $pm2 reload all 14 | should 'should have started 1 clustered app' 'online' 1 15 | should 'should restart processes with new name' 'restart_time: 1' 1 16 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 9 | 10 | **What's going wrong?** 11 | **How could we reproduce this issue?** 12 | 13 | ## Supporting information 14 | 15 | ``` 16 | PM2 version: `pm2 -v` 17 | Node version: `node -v` 18 | Windows? Mac? Linux? 19 | ``` 20 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Please always submit pull requests on the development branch. 2 | 3 | | Q | A 4 | | ------------- | --- 5 | | Bug fix? | yes/no 6 | | New feature? | yes/no 7 | | BC breaks? | no 8 | | Deprecations? | no 9 | | Tests pass? | yes 10 | | Fixed tickets | #1234, #5678 11 | | License | MIT 12 | | Doc PR | https://github.com/pm2-hive/pm2-hive.github.io/pulls 13 | 14 | *Please update this template with something that matches your PR* 15 | -------------------------------------------------------------------------------- /examples/graceful-http.js: -------------------------------------------------------------------------------- 1 | 2 | var http = require('http'); 3 | 4 | process.on('SIGINT', function() { 5 | console.log('Graceful closing...'); 6 | server.close(function() { 7 | process.exit(0); 8 | }); 9 | }); 10 | 11 | var server = http.createServer(function(req, res) { 12 | res.writeHead(200); 13 | res.end('hey'); 14 | }).listen(process.env.PORT || 8000, function() { 15 | console.log('App listening on port %d in env %s', process.env.PORT || 8000, process.env.NODE_ENV); 16 | }); 17 | -------------------------------------------------------------------------------- /test/fixtures/big-array-es6.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | var obj = {}; 4 | var i = 0; 5 | 6 | setInterval(function() { 7 | obj[i] = Array.apply(null, new Array(99999)).map(String.prototype.valueOf,"hi"); 8 | i++; 9 | }, 2); 10 | 11 | 12 | (function testHarmony() { 13 | // 14 | // Harmony test 15 | // 16 | try { 17 | var assert = require('assert') 18 | , s = new Set(); 19 | s.add('a'); 20 | assert.ok(s.has('a')); 21 | console.log('● ES6 mode'.green); 22 | } catch(e) {} 23 | })(); 24 | -------------------------------------------------------------------------------- /test/fixtures/git/hooks/pre-applypatch.sample: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # An example hook script to verify what is about to be committed 4 | # by applypatch from an e-mail message. 5 | # 6 | # The hook should exit with non-zero status after issuing an 7 | # appropriate message if it wants to stop the commit. 8 | # 9 | # To enable this hook, rename this file to "pre-applypatch". 10 | 11 | . git-sh-setup 12 | test -x "$GIT_DIR/hooks/pre-commit" && 13 | exec "$GIT_DIR/hooks/pre-commit" ${1+"$@"} 14 | : 15 | -------------------------------------------------------------------------------- /test/fixtures/module-fixture/node_modules/pmx/lib/utils/units.js: -------------------------------------------------------------------------------- 1 | // Time units, as found in Java: 2 | // see: http://download.oracle.com/javase/6/docs/api/java/util/concurrent/TimeUnit.html 3 | exports.NANOSECONDS = 1 / (1000 * 1000); 4 | exports.MICROSECONDS = 1 / 1000; 5 | exports.MILLISECONDS = 1; 6 | exports.SECONDS = 1000 * exports.MILLISECONDS; 7 | exports.MINUTES = 60 * exports.SECONDS; 8 | exports.HOURS = 60 * exports.MINUTES; 9 | exports.DAYS = 24 * exports.HOURS; 10 | -------------------------------------------------------------------------------- /test/bash/resurrect.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | SRC=$(cd $(dirname "$0"); pwd) 4 | source "${SRC}/include.sh" 5 | cd $file_path 6 | 7 | $pm2 start echo.js -i 4 8 | spec "should start 4 processes" 9 | $pm2 save 10 | spec "should save process list" 11 | ls ~/.pm2/dump.pm2 12 | spec "should dump file exists" 13 | $pm2 resurrect 14 | spec "should resurrect" 15 | should 'should have still 4 apps started' 'online' 4 16 | $pm2 delete all 17 | $pm2 resurrect 18 | should 'should have still 4 apps started' 'online' 4 19 | -------------------------------------------------------------------------------- /test/fixtures/graceful-exit-no-listen.js: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Example of graceful exit that does not listen 4 | * 5 | * $ pm2 gracefulReload all 6 | */ 7 | 8 | process.on('message', function(msg) { 9 | if (msg == 'shutdown') { 10 | console.log('Closing all connections...'); 11 | setTimeout(function() { 12 | console.log('Finished closing connections'); 13 | process.exit(0); 14 | }, 1500); 15 | } 16 | }); 17 | 18 | setInterval(function () 19 | { 20 | console.log('tick'); 21 | }, 4000); 22 | -------------------------------------------------------------------------------- /test/fixtures/module-fixture/node_modules/pmx/test/helpers/plan.js: -------------------------------------------------------------------------------- 1 | 2 | var assert = require('assert'); 3 | 4 | function Plan(count, done) { 5 | this.done = done; 6 | this.count = count; 7 | } 8 | 9 | Plan.prototype.ok = function(expression) { 10 | assert(expression); 11 | 12 | if (this.count === 0) { 13 | assert(false, 'Too many assertions called'); 14 | } else { 15 | this.count--; 16 | } 17 | 18 | if (this.count === 0) { 19 | this.done(); 20 | } 21 | }; 22 | 23 | module.exports = Plan; 24 | -------------------------------------------------------------------------------- /test/fixtures/child_no_http.js: -------------------------------------------------------------------------------- 1 | var pmx = require('pmx').init({ 2 | http: false 3 | }); 4 | 5 | var http = require('http'); 6 | 7 | http.createServer(function(req, res) { 8 | res.writeHead(200); 9 | res.end('hey'); 10 | }).listen(8000); 11 | 12 | process.on('message', function(msg) { 13 | if (msg == 'shutdown') { 14 | console.log('Closing all connections...'); 15 | setTimeout(function() { 16 | console.log('Finished closing connections'); 17 | process.exit(0); 18 | }, 100); 19 | } 20 | }); 21 | -------------------------------------------------------------------------------- /test/fixtures/module-fixture/node_modules/pmx/test/express/app.js: -------------------------------------------------------------------------------- 1 | 2 | var axm = require('../..'); 3 | var express = require('express'); 4 | var app = express(); 5 | 6 | var err = new Error('jajajja'); 7 | 8 | err.url = 'http://thd.com/'; 9 | 10 | axm.notify(err); 11 | 12 | app.get('/', function(req, res){ 13 | res.send('Hello World'); 14 | }); 15 | 16 | app.get('/error', function(req, res, next){ 17 | next(new Error('toto')); 18 | }); 19 | 20 | app.use(axm.expressErrorHandler()); 21 | 22 | 23 | app.listen(3001); 24 | -------------------------------------------------------------------------------- /test/fixtures/module-fixture/node_modules/pmx/test/pmx.mocha.js: -------------------------------------------------------------------------------- 1 | 2 | var pmx = require('..'); 3 | 4 | describe('PMX driver', function() { 5 | it('should have the right properties', function(done) { 6 | pmx.should.have.property('emit'); 7 | pmx.should.have.property('action'); 8 | done(); 9 | }); 10 | 11 | describe('Event module', function() { 12 | it('should not hang if process not forked', function(done) { 13 | pmx.emit('testo', { data : 'ok' }); 14 | done(); 15 | }); 16 | 17 | }); 18 | }); 19 | -------------------------------------------------------------------------------- /examples/v1/auto-restart-threshold.js: -------------------------------------------------------------------------------- 1 | var pmx = require('pmx'); 2 | 3 | var Probe = pmx.probe(); 4 | 5 | var i = 0; 6 | 7 | var val = Probe.metric({ 8 | name : 'test', 9 | value : function() { 10 | return i; 11 | }, 12 | alert : { 13 | mode : 'threshold', 14 | value : 20, 15 | msg : 'more than 20', 16 | func : function() { 17 | console.log('exiting'); 18 | process.exit(1); 19 | } 20 | } 21 | }); 22 | 23 | 24 | 25 | setInterval(function() { 26 | console.log(i); 27 | i++; 28 | }, 200); 29 | -------------------------------------------------------------------------------- /examples/v1/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "example-module", 3 | "version": "0.3.21", 4 | "description": "Keymetrics++ and PM2 adapter", 5 | "main": "scoped-action.js", 6 | "dependencies": { 7 | }, 8 | "scripts": { 9 | "test": "DEBUG='axm:*' mocha test/*.mocha.js" 10 | }, 11 | "repository": { 12 | "type": "git", 13 | "url": "https://github.com/keymetrics/pmx.git" 14 | }, 15 | "config" : { 16 | "aconfig-var" : true, 17 | "var2" : false 18 | }, 19 | "author": "Keymetrics I/O", 20 | "license": "MIT" 21 | } 22 | -------------------------------------------------------------------------------- /packager/debian/lintian-overrides: -------------------------------------------------------------------------------- 1 | # No changelog file at the moment 2 | pm2: debian-changelog-file-missing 3 | # node-gyp throws this 4 | pm2: python-script-but-no-python-dep 5 | # Some .js files in node_modules have 0777 permissions instead of 0666 6 | pm2: executable-not-elf-or-script 7 | # Some node_modules have node in shebang 8 | pm2: unusual-interpreter 9 | # Third-party licenses 10 | pm2: extra-license-file 11 | # lib/async.js in node_modules 12 | pm2: embedded-javascript-library 13 | # No manpage... yet! 14 | pm2: binary-without-manpage 15 | -------------------------------------------------------------------------------- /examples/wait-ready/app.js: -------------------------------------------------------------------------------- 1 | const http = require('http'); 2 | 3 | const port = 3000; 4 | 5 | const app = http.createServer((_, res) => { 6 | res.writeHead(200); 7 | res.end('Hello!'); 8 | }); 9 | 10 | console.log('Starting app...'); 11 | 12 | process.on('SIGINT', (msg) => { 13 | console.log('Just got SIGINTed, but I dont care'); 14 | }); 15 | 16 | setTimeout(() => { 17 | app.listen(port, () => { 18 | console.log(`Listening on ${port}`); 19 | if (process.send) { 20 | process.send('ready'); 21 | } 22 | }); 23 | }, 10000); 24 | -------------------------------------------------------------------------------- /test/fixtures/git/hooks/applypatch-msg.sample: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # An example hook script to check the commit log message taken by 4 | # applypatch from an e-mail message. 5 | # 6 | # The hook should exit with non-zero status after issuing an 7 | # appropriate message if it wants to stop the commit. The hook is 8 | # allowed to edit the commit message file. 9 | # 10 | # To enable this hook, rename this file to "applypatch-msg". 11 | 12 | . git-sh-setup 13 | test -x "$GIT_DIR/hooks/commit-msg" && 14 | exec "$GIT_DIR/hooks/commit-msg" ${1+"$@"} 15 | : 16 | -------------------------------------------------------------------------------- /examples/module-sample/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "example-module", 3 | "version": "0.3.21", 4 | "description": "Keymetrics++ and PM2 adapter", 5 | "main": "scoped-action.js", 6 | "dependencies": { 7 | }, 8 | "scripts": { 9 | "test": "DEBUG='axm:*' mocha test/*.mocha.js" 10 | }, 11 | "repository": { 12 | "type": "git", 13 | "url": "https://github.com/keymetrics/pmx.git" 14 | }, 15 | "config" : { 16 | "aconfig-var" : true, 17 | "var2" : false 18 | }, 19 | "author": "Keymetrics I/O", 20 | "license": "MIT" 21 | } 22 | -------------------------------------------------------------------------------- /test/fixtures/startProcessInsidePm2.js: -------------------------------------------------------------------------------- 1 | var PM2 = require('../..'); 2 | 3 | /** 4 | * New gen API 5 | */ 6 | var pm2 = new PM2.custom(); 7 | 8 | //console.log(process.env); 9 | 10 | pm2.connect(function(err) { 11 | 12 | console.error(' ----------------------' ); 13 | 14 | pm2.start('./insidePm2Process.js', { 15 | name: 'insideProcess', 16 | 'output': './inside-out.log', 17 | merge_logs: true 18 | }, function(err, proc){ 19 | if(err){ 20 | console.log(err); 21 | return process.exit(1); 22 | } 23 | }); 24 | 25 | 26 | }); 27 | -------------------------------------------------------------------------------- /test/fixtures/module-fixture/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "example-module", 3 | "version": "0.3.21", 4 | "description": "Keymetrics++ and PM2 adapter", 5 | "main": "scoped-action.js", 6 | "dependencies": { 7 | }, 8 | "scripts": { 9 | "test": "DEBUG='axm:*' mocha test/*.mocha.js" 10 | }, 11 | "repository": { 12 | "type": "git", 13 | "url": "https://github.com/keymetrics/pmx.git" 14 | }, 15 | "config" : { 16 | "aconfig-var" : true, 17 | "var2" : false 18 | }, 19 | "author": "Keymetrics I/O", 20 | "license": "MIT" 21 | } 22 | -------------------------------------------------------------------------------- /test/parallel_programmatic_tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | export NODE_ENV='test' 4 | 5 | function fail { 6 | echo -e "######## \033[31m ✘ $1\033[0m" 7 | } 8 | 9 | function success { 10 | echo -e "\033[32m------------> ✔ $1\033[0m" 11 | } 12 | 13 | function spec { 14 | [ $? -eq 0 ] || fail "$1" 15 | success "$1" 16 | } 17 | 18 | pkill -f PM2 19 | 20 | cd test/ 21 | 22 | parallel --gnu --keep-order --joblog joblog --halt now,fail=1 -j+0 < programmatic_commands.txt 23 | spec "Should text have passed" 24 | cat joblog 25 | 26 | # possible to pass --tmux 27 | -------------------------------------------------------------------------------- /test/bash/cli-ux.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | SRC=$(cd $(dirname "$0"); pwd) 4 | source "${SRC}/include.sh" 5 | 6 | 7 | echo -e "\033[1mRunning tests:\033[0m" 8 | 9 | which wrk 10 | spec "You should have wrk benchmark in your /usr/bin" 11 | 12 | killall node 13 | 14 | cd $file_path 15 | $pm2 start cluster-pm2.json 16 | $pm2 start cluster-pm2.json -f 17 | $pm2 start cluster-pm2.json -f 18 | $pm2 start cluster-pm2.json -f 19 | spec "start cluster" 20 | 21 | wrk -c 500 -t 500 -d 8 http://localhost:8020 &> /dev/null & 22 | $pm2 monit 23 | $pm2 list 24 | $pm2 stop 25 | -------------------------------------------------------------------------------- /test/bash/issues/2337.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | SRC=$(cd $(dirname "$0"); pwd) 4 | source "${SRC}/../include.sh" 5 | cd $file_path 6 | 7 | echo -e "\033[1mRunning tests for json files :\033[0m" 8 | 9 | $pm2 start echo.js --name zero -f 10 | $pm2 start echo.js --name one -f 11 | $pm2 start echo.js --name two -f 12 | should 'should have 3 processes online' 'online' 3 13 | $pm2 stop 0 14 | $pm2 stop 2 15 | $pm2 start echo.js --name three -f 16 | $pm2 ls 17 | should 'should have 2 processes online' 'online' 2 18 | should 'should have 2 processes stopped' 'stopped' 2 19 | -------------------------------------------------------------------------------- /test/bash/startup.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [ "$EUID" -ne 0 ] 4 | then 5 | echo "Please run as root" 6 | exit 7 | fi 8 | 9 | SRC=$(cd $(dirname "$0"); pwd) 10 | source "${SRC}/include.sh" 11 | 12 | cd $file_path 13 | 14 | $pm2 startup upstart -u $USER --hp $HOME 15 | spec "should startup command generation exited succesfully" 16 | test -e /etc/init.d/pm2-$USER 17 | spec "should have generated upstart file" 18 | $pm2 unstartup upstart 19 | spec "should have disabled startup" 20 | ! test -e /etc/init.d/pm2-$USER 21 | spec "should have deleted upstart file" 22 | -------------------------------------------------------------------------------- /test/fixtures/http.js: -------------------------------------------------------------------------------- 1 | 2 | var http = require('http'); 3 | 4 | var app = http.createServer(function(req, res) { 5 | res.writeHead(200); 6 | res.end('hey'); 7 | }) 8 | 9 | var listener = app.listen(0, function() { 10 | console.log('Listening on port ' + listener.address().port); 11 | }); 12 | 13 | process.on('message', function(msg) { 14 | if (msg == 'shutdown') { 15 | console.log('Closing all connections...'); 16 | setTimeout(function() { 17 | console.log('Finished closing connections'); 18 | process.exit(0); 19 | }, 100); 20 | } 21 | }); 22 | -------------------------------------------------------------------------------- /examples/v1/malformated.json: -------------------------------------------------------------------------------- 1 | { 2 | "apps" : [{ 3 | "exec_interpreter" : "node, 4 | "exec_mode" : "cluster_mode", 5 | "instances" : 0, 6 | "log_date_format" : "YYYY-MM-DD HH:mm Z", 7 | "max_memory_restart" : "160", 8 | "merge_logs" : true, 9 | "name" : "hapi_playground", 10 | "script" : "child.js", 11 | "cwd" : "examples", 12 | "node_args" : "--harmony", 13 | "ignore_watch" : ["[\\/\\\\]\\./", "log"], 14 | "watch" : true 15 | }] 16 | } 17 | -------------------------------------------------------------------------------- /test/fixtures/nvm-node-version/ecosystem.json: -------------------------------------------------------------------------------- 1 | { 2 | /** 3 | * Application configuration section 4 | * http://pm2.keymetrics.io/docs/usage/application-declaration/ 5 | */ 6 | apps : [ 7 | 8 | // First application 9 | { 10 | name : "http-4.6", 11 | script : "http.js", 12 | interpreter : "node@4.6.0" 13 | }, 14 | { 15 | name : "http-6.7", 16 | script : "http.js", 17 | force : true, 18 | env : { 19 | PORT : 8002 20 | }, 21 | interpreter : "node@6.7.0" 22 | }, 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /examples/v1/udp.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | var punt = require('punt'); 5 | var server = punt.bind('0.0.0.0:5000'); 6 | var a = punt.connect('0.0.0.0:5000'); 7 | var b = punt.connect('0.0.0.0:5000'); 8 | var c = punt.connect('0.0.0.0:5000'); 9 | 10 | server.on('message', function(msg){ 11 | console.log(msg); 12 | }); 13 | 14 | setInterval(function(){ 15 | a.send({ hello: 'world' }); 16 | }, 150); 17 | 18 | setInterval(function(){ 19 | b.send('hello world'); 20 | }, 150); 21 | 22 | setInterval(function(){ 23 | c.send(new Buffer('hello')); 24 | }, 150); 25 | 26 | process.emit('listening'); 27 | -------------------------------------------------------------------------------- /packager/debian/control.in: -------------------------------------------------------------------------------- 1 | Package: pm2 2 | Version: $VERSION-1 3 | Depends: nodejs 4 | Conflicts: nodejs (<< 0.12.0) 5 | Section: devel 6 | Priority: optional 7 | Architecture: all 8 | Installed-Size: $INSTALLED_SIZE 9 | Maintainer: Alexandre Strzelewicz 10 | Homepage: http://pm2.io/ 11 | Description: Production Process Manager. 12 | PM2: Process Manager for Node.js. 13 | . 14 | PM2 is a Process Manager mainly for Node.js that allows to automatically increase performance and stability while enhancing the process management experience for developer and DevOps. 15 | -------------------------------------------------------------------------------- /test/fixtures/all2.json: -------------------------------------------------------------------------------- 1 | [{ 2 | "name" : "echo", 3 | "script" : "./echo.js", 4 | "instances" : "1", 5 | "env_production" : { 6 | "NODE_ENV" : "production", 7 | "TOTO" : "heymoto" 8 | }, 9 | "env_test" : { 10 | "NODE_ENV" : "test", 11 | "TOTO" : "heyamota" 12 | } 13 | },{ 14 | "name" : "child", 15 | "script" : "./child.js", 16 | "instances" : "1", 17 | "error_file" : "./child-err.log", 18 | "out_file" : "./child-out.log" 19 | },{ 20 | "name" : "api-2", 21 | "script" : "./server.js", 22 | "instances" : "2" 23 | }] 24 | -------------------------------------------------------------------------------- /test/fixtures/env-ecosystem.json: -------------------------------------------------------------------------------- 1 | { 2 | "apps" : [{ 3 | "name" : "env2", 4 | "script" : "./env.js", 5 | "out_file" : "out-env.log", 6 | "merge_logs" : true, 7 | "env": { 8 | "NODE_ENV": "production" 9 | } 10 | }], 11 | "deploy" : { 12 | "production" : { 13 | "user" : "node", 14 | "host" : "212.83.163.1", 15 | "ref" : "origin/master", 16 | "repo" : "git@github.com:repo.git", 17 | "path" : "/var/www/production", 18 | "env" : { 19 | "TEST_VARIABLE": "No worries!" 20 | } 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /test/fixtures/module-fixture/node_modules/pmx/examples/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "example-module", 3 | "version": "0.3.21", 4 | "description": "Keymetrics++ and PM2 adapter", 5 | "main": "scoped-action.js", 6 | "dependencies": { 7 | }, 8 | "scripts": { 9 | "test": "DEBUG='axm:*' mocha test/*.mocha.js" 10 | }, 11 | "repository": { 12 | "type": "git", 13 | "url": "https://github.com/keymetrics/pmx.git" 14 | }, 15 | "config" : { 16 | "aconfig-var" : true, 17 | "var2" : false 18 | }, 19 | "author": "Keymetrics I/O", 20 | "license": "MIT" 21 | } 22 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # top-most EditorConfig file 2 | root = true 3 | 4 | # Unix-style newlines with a newline ending every file 5 | [*] 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | indent_style = space 11 | indent_size = 2 12 | 13 | # JavaScript 14 | [*.js] 15 | indent_style = space 16 | indent_size = 2 17 | 18 | # YAML 19 | [*.yml] 20 | indent_style = space 21 | indent_size = 3 22 | 23 | # JSON 24 | [*.json] 25 | indent_style = space 26 | indent_size = 2 27 | 28 | # SHELL 29 | [*.sh] 30 | indent_style = space 31 | indent_size = 2 32 | -------------------------------------------------------------------------------- /lib/templates/init-scripts/systemd.tpl: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=PM2 process manager 3 | Documentation=https://pm2.keymetrics.io/ 4 | After=network.target 5 | 6 | [Service] 7 | Type=forking 8 | User=%USER% 9 | LimitNOFILE=infinity 10 | LimitNPROC=infinity 11 | LimitCORE=infinity 12 | Environment=PATH=%NODE_PATH%:/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin 13 | Environment=PM2_HOME=%HOME_PATH% 14 | PIDFile=%HOME_PATH%/pm2.pid 15 | 16 | ExecStart=%PM2_PATH% resurrect 17 | ExecReload=%PM2_PATH% reload all 18 | ExecStop=%PM2_PATH% kill 19 | 20 | [Install] 21 | WantedBy=multi-user.target 22 | -------------------------------------------------------------------------------- /test/fixtures/module-fixture/node_modules/pmx/test/fixtures/monitor2.mock.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | var axm = require('../..'); 4 | 5 | var obj = axm.enableProbes(); 6 | 7 | var a = { 8 | 'aaa' : { 'ok' : true }, 9 | 'bbb' : { 'ok' : false } 10 | }; 11 | 12 | // Does not refresh because it copies the val 13 | obj.count = Object.keys(a).length; 14 | 15 | obj.countFn = function() { 16 | return Object.keys(a).length; 17 | }; 18 | 19 | setTimeout(function () { 20 | a.ccc = 'test'; 21 | a.ddd = 'test'; 22 | 23 | setTimeout(function () { 24 | axm.stopProbes(); 25 | }, 1100); 26 | }, 1100); 27 | -------------------------------------------------------------------------------- /test/fixtures/nvm-node-version/ecosystem-change.json: -------------------------------------------------------------------------------- 1 | { 2 | /** 3 | * Application configuration section 4 | * http://pm2.keymetrics.io/docs/usage/application-declaration/ 5 | */ 6 | apps : [ 7 | 8 | // First application 9 | { 10 | name : "http-4.6", 11 | script : "http.js", 12 | interpreter : "node@4.5.0" 13 | }, 14 | { 15 | name : "http-6.7", 16 | script : "http.js", 17 | force : true, 18 | env : { 19 | PORT : 8002 20 | }, 21 | interpreter : "node@6.7.0" 22 | }, 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /test/bash/right-exit-code.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | SRC=$(cd $(dirname "$0"); pwd) 4 | source "${SRC}/include.sh" 5 | 6 | cd $file_path 7 | 8 | echo -e "\033[1mRIGHT EXIT CODES:\033[0m" 9 | 10 | $pm2 kill 11 | 12 | $pm2 restart BULLSHIT 13 | ispec "Unknown process = error exit" 14 | 15 | $pm2 restart 666 16 | ispec "Unknown process = error exit" 17 | 18 | $pm2 restart all 19 | ispec "No process = error exit" 20 | 21 | $pm2 stop all 22 | ispec "No process = error exit" 23 | 24 | $pm2 delete 10 25 | ispec "No process = error exit" 26 | 27 | $pm2 delete toto 28 | ispec "No process = error exit" 29 | -------------------------------------------------------------------------------- /test/bash/startOrX.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | SRC=$(cd $(dirname "$0"); pwd) 4 | source "${SRC}/include.sh" 5 | 6 | echo -e "\033[1mStartOrX.sh:\033[0m" 7 | 8 | cd $file_path 9 | 10 | $pm2 startOrRestart all.json 11 | 12 | should 'should start processes' 'online' 6 13 | 14 | $pm2 startOrRestart all.json 15 | 16 | should 'should has restarted app' 'restart_time: 1' 6 17 | 18 | $pm2 startOrReload all.json 19 | 20 | should 'should has reloaded app' 'restart_time: 2' 6 21 | 22 | # slow 23 | # $pm2 startOrGracefulReload all.json 24 | # should 'should has graceful reloaded app' 'restart_time: 3' 8 25 | -------------------------------------------------------------------------------- /test/fixtures/graceful-exit-send.js: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Example of graceful exit that does not listen but sends 'online' 4 | * 5 | * $ pm2 gracefulReload all 6 | */ 7 | 8 | process.on('message', function(msg) { 9 | if (msg == 'shutdown') { 10 | console.log('Closing all connections...'); 11 | setTimeout(function() { 12 | console.log('Finished closing connections'); 13 | process.exit(0); 14 | }, 1500); 15 | } 16 | }); 17 | 18 | setInterval(function () 19 | { 20 | console.log('tick'); 21 | }, 4000); 22 | 23 | setTimeout(function () 24 | { 25 | process.send('online'); 26 | }, 2000); 27 | -------------------------------------------------------------------------------- /test/fixtures/graceful-exit.js: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Example of graceful exit 4 | * 5 | * $ pm2 gracefulReload all 6 | */ 7 | 8 | process.on('message', function(msg) { 9 | if (msg == 'shutdown') { 10 | console.log('Closing all connections...'); 11 | setTimeout(function() { 12 | console.log('Finished closing connections'); 13 | process.exit(0); 14 | }, 1500); 15 | } 16 | }); 17 | 18 | var http = require('http'); 19 | 20 | http.createServer(function(req, res) { 21 | res.writeHead(200); 22 | res.end('hey'); 23 | }).listen(8000, function() { 24 | console.log('listening'); 25 | }); 26 | -------------------------------------------------------------------------------- /test/fixtures/module-fixture/node_modules/pmx/lib/probes/pacemaker.js: -------------------------------------------------------------------------------- 1 | 2 | module.exports = function(pmx) { 3 | var TIME_INTERVAL = 1000; 4 | 5 | var oldTime = process.hrtime(); 6 | 7 | var histogram = pmx.probe().histogram({ 8 | name : 'Loop delay', 9 | measurement : 'mean', 10 | unit : 'ms' 11 | }); 12 | 13 | setInterval(function() { 14 | var newTime = process.hrtime(); 15 | var delay = (newTime[0] - oldTime[0]) * 1e3 + (newTime[1] - oldTime[1]) / 1e6 - TIME_INTERVAL; 16 | oldTime = newTime; 17 | histogram.update(delay); 18 | }, TIME_INTERVAL); 19 | }; 20 | -------------------------------------------------------------------------------- /test/interface/password.mocha.js: -------------------------------------------------------------------------------- 1 | 2 | var Password = require('../../lib/Interactor/Password.js'); 3 | var should = require('should'); 4 | 5 | describe('Password test', function() { 6 | var crypted = ''; 7 | 8 | it('should crypt a password', function() { 9 | crypted = Password.generate('testpass'); 10 | }); 11 | 12 | it('should fail with wrong password', function() { 13 | Password.verify('testpasds', crypted).should.be.false; 14 | }); 15 | 16 | it('should success with right password', function() { 17 | Password.verify('testpass', crypted).should.be.true; 18 | }); 19 | 20 | }); 21 | -------------------------------------------------------------------------------- /test/fixtures/wait_ready_event/http-wait-start_nocb.js: -------------------------------------------------------------------------------- 1 | 2 | var http = require('http'); 3 | 4 | var app = http.createServer(function(req, res) { 5 | res.writeHead(200); 6 | res.end('hey'); 7 | }) 8 | 9 | 10 | var listener = app.listen(0, function() { 11 | console.log('Listening on port ' + listener.address().port); 12 | }); 13 | 14 | process.on('message', function(msg) { 15 | if (msg == 'shutdown') { 16 | console.log('Closing all connections...'); 17 | setTimeout(function() { 18 | console.log('Finished closing connections'); 19 | process.exit(0); 20 | }, 100); 21 | } 22 | }); 23 | -------------------------------------------------------------------------------- /examples/keymetrics-integration/scoped-actions.js: -------------------------------------------------------------------------------- 1 | 2 | var pmx = require('pmx'); 3 | 4 | pmx.scopedAction('simple test', function(data, emitter) { 5 | var i = setInterval(function() { 6 | emitter.send('output-stream'); 7 | }, 100); 8 | 9 | setTimeout(function() { 10 | 11 | emitter.end('end'); 12 | clearInterval(i); 13 | }, 3000); 14 | }); 15 | 16 | pmx.scopedAction('throwing error', function(data, emitter) { 17 | var i = setInterval(function() { 18 | emitter.send('output-stream'); 19 | }, 100); 20 | 21 | setTimeout(function() { 22 | 23 | throw new Error('errr'); 24 | }, 1000); 25 | }); 26 | -------------------------------------------------------------------------------- /test/bash/wrapped-fork.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | SRC=$(cd $(dirname "$0"); pwd) 4 | source "${SRC}/include.sh" 5 | 6 | cd $file_path 7 | 8 | echo "################## Wrapped fork ###################" 9 | 10 | echo "Testing wrapped fork mode values" 11 | 12 | rm path-check1.txt 13 | rm path-check2.txt 14 | 15 | node path-check.js > path-check1.txt 16 | $pm2 start path-check.js --no-autorestart -o path-check2.txt 17 | sleep 1 18 | 19 | OUT=`diff path-check1.txt path-check2.txt` 20 | 21 | echo $OUT 22 | [ -z "$OUT" ] || fail "The outputs are not identical" 23 | success "The outputs are identical" 24 | 25 | $pm2 kill 26 | -------------------------------------------------------------------------------- /test/fixtures/module-fixture/node_modules/pmx/lib/utils/probes/Counter.js: -------------------------------------------------------------------------------- 1 | 2 | // Hacked from https://github.com/felixge/node-measured 3 | 4 | module.exports = Counter; 5 | 6 | function Counter(opts) { 7 | opts = opts || {}; 8 | 9 | this._count = opts.count || 0; 10 | } 11 | 12 | Counter.prototype.val = function() { 13 | return this._count; 14 | }; 15 | 16 | Counter.prototype.inc = function(n) { 17 | this._count += (n || 1); 18 | }; 19 | 20 | Counter.prototype.dec = function(n) { 21 | this._count -= (n || 1); 22 | }; 23 | 24 | Counter.prototype.reset = function(count) { 25 | this._count = count || 0; 26 | }; 27 | -------------------------------------------------------------------------------- /test/fixtures/watch/http.js: -------------------------------------------------------------------------------- 1 | 2 | var http = require('http'); 3 | 4 | var app = http.createServer(function(req, res) { 5 | res.writeHead(200); 6 | res.end('hey'); 7 | }) 8 | 9 | console.log(process.env.TOTO_ENV); 10 | 11 | var listener = app.listen(0, function() { 12 | console.log('Listening on port ' + listener.address().port); 13 | }); 14 | 15 | process.on('message', function(msg) { 16 | if (msg == 'shutdown') { 17 | console.log('Closing all connections...'); 18 | setTimeout(function() { 19 | console.log('Finished closing connections'); 20 | process.exit(0); 21 | }, 100); 22 | } 23 | }); 24 | -------------------------------------------------------------------------------- /test/bash/interact.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | SRC=$(cd $(dirname "$0"); pwd) 4 | source "${SRC}/include.sh" 5 | cd $file_path 6 | 7 | echo -e "\033[1mRunning Interaction tests:\033[0m" 8 | 9 | $pm2 interact stop 10 | 11 | $pm2 interact 12 | 13 | $pm2 interact XXX2 XXX3 homeloc 14 | 15 | $pm2 updatePM2 16 | 17 | $pm2 interact stop 18 | 19 | $pm2 interact 20 | 21 | $pm2 interact info 22 | 23 | $pm2 interact info | grep "XXX2" 24 | spec "Should have XXX2 has public key" 25 | 26 | $pm2 interact info | grep "XXX3" 27 | spec "Should have XXX3 has public key" 28 | 29 | $pm2 list 30 | 31 | $pm2 interact stop 32 | $pm2 kill 33 | -------------------------------------------------------------------------------- /test/fixtures/source-map/models.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"models.js","sourceRoot":"","sources":["../app/models.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAOb;IAGE,qBAAY,OAAe;QACzB,IAAI,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAE/B,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;YAChC,MAAM,IAAI,KAAK,CAAC,oCAAoC,GAAG,OAAO,CAAC,CAAC;QAClE,CAAC;QAED,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED,sBAAI,6BAAI;aAAR;YACE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;QACxB,CAAC;;;OAAA;IAED,sBAAI,gCAAO;aAAX;YACE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC;QAC3B,CAAC;;;OAAA;IACH,kBAAC;AAAD,CAAC,AApBD,IAoBC;AApBY,mBAAW,cAoBvB,CAAA"} -------------------------------------------------------------------------------- /examples/v1/graceful-exit.js: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Example of graceful exit 4 | * 5 | * $ pm2 gracefulReload all 6 | */ 7 | 8 | process.on('message', function(msg) { 9 | if (msg == 'shutdown') { 10 | console.log('Closing all connections...'); 11 | setTimeout(function() { 12 | console.log('Finished closing connections'); 13 | process.exit(0); 14 | }, 1500); 15 | } 16 | }); 17 | 18 | var http = require('http'); 19 | 20 | http.createServer(function(req, res) { 21 | res.writeHead(200); 22 | console.log('got'); 23 | res.end('hey'); 24 | }).listen(8000, function() { 25 | console.log('listening'); 26 | }); 27 | -------------------------------------------------------------------------------- /test/fixtures/wait_ready_event/http-wait-start.js: -------------------------------------------------------------------------------- 1 | 2 | var http = require('http'); 3 | 4 | var app = http.createServer(function(req, res) { 5 | res.writeHead(200); 6 | res.end('hey'); 7 | }) 8 | 9 | 10 | var listener = app.listen(0, function() { 11 | console.log('Listening on port ' + listener.address().port); 12 | process.send('ready'); 13 | }); 14 | 15 | process.on('message', function(msg) { 16 | if (msg == 'shutdown') { 17 | console.log('Closing all connections...'); 18 | setTimeout(function() { 19 | console.log('Finished closing connections'); 20 | process.exit(0); 21 | }, 100); 22 | } 23 | }); 24 | -------------------------------------------------------------------------------- /test/fixtures/big-array-listen.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | var obj = {}; 4 | var i = 0; 5 | 6 | var http = require('http'); 7 | 8 | http.createServer(function(req, res) { 9 | res.writeHead(200); 10 | res.end('hey'); 11 | }).listen(8000); 12 | 13 | process.on('message', function(msg) { 14 | if (msg == 'shutdown') { 15 | console.log('Closing all connections...'); 16 | setTimeout(function() { 17 | console.log('Finished closing connections'); 18 | process.exit(0); 19 | }, 100); 20 | } 21 | }); 22 | 23 | setInterval(function() { 24 | obj[i] = Array.apply(null, new Array(99999)).map(String.prototype.valueOf,"hi"); 25 | i++; 26 | }, 2); 27 | -------------------------------------------------------------------------------- /examples/v1/exit.js: -------------------------------------------------------------------------------- 1 | 2 | // process.on('exit', function() { 3 | // console.log('About to exit.'); 4 | // }); 5 | 6 | // process.on('uncaughtException', function(err) { 7 | // console.log('Caught exception: ' + err); 8 | // }); 9 | 10 | // process.on('SIGINT', function() { 11 | // console.log('Got SIGINT. Press Control-D to exit.'); 12 | // process.exit(1); 13 | // }); 14 | 15 | var worker = require('cluster').worker; 16 | 17 | worker.on('disconnect', function() { 18 | console.log('exiting'); 19 | }); 20 | 21 | 22 | setInterval(function() { 23 | }, 1); 24 | 25 | setInterval(function() { 26 | console.log('ok'); 27 | }, 2000); 28 | console.log('ok'); 29 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | 2 | gen_deb: 3 | ./packager/build-dist.sh 4 | ./packager/build-deb.sh 5 | 6 | publish: 7 | ./packager/deploy.sh 8 | 9 | clean: 10 | find node_modules \( -name "example" -o -name "examples" -o -name "docs" -o -name "jsdoc" -o -name "jsdocs" -o -name "test" -o -name "tests" -o -name "*\.md" -o -name "*\.html" -o -name "*\.eot" -o -name "*\.svg" -o -name "*\.woff" \) -print -exec rm -rf {} \; 11 | find node_modules -type d \( -name "example" -o -name "examples" -o -name "docs" -o -name "jsdoc" -o -name "jsdocs" -o -name "test" -o -name "tests" -o -name "*\.md" -o -name "*\.html" -o -name "*\.eot" -o -name "*\.svg" -o -name "*\.woff" \) -print -exec rm -rf {} \; 12 | -------------------------------------------------------------------------------- /examples/process-file/process.json: -------------------------------------------------------------------------------- 1 | { 2 | apps : [{ 3 | name : 'HTTP-API', 4 | script : 'http.js', 5 | exec_mode : 'cluster', 6 | instances : 'max', 7 | max_memory_restart : '260M', 8 | 9 | ignore_watch : ['node_modules'], 10 | watch : true, 11 | env : { 12 | NODE_ENV : 'normal' 13 | }, 14 | env_production : { 15 | NODE_ENV : 'production' 16 | } 17 | }, { 18 | name : 'Worker', 19 | script : 'worker.js' 20 | }, { 21 | name : 'Checks', 22 | script : 'connection_check.sh' 23 | }] 24 | } 25 | -------------------------------------------------------------------------------- /test/bash/operate-regex.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | SRC=$(cd $(dirname "$0"); pwd) 4 | source "${SRC}/include.sh" 5 | 6 | cd $file_path 7 | 8 | $pm2 start echo.js --name "echo-3" 9 | $pm2 start echo.js --name "echo-1" 10 | $pm2 start echo.js --name "echo-2" 11 | 12 | sleep 0.5 13 | 14 | should 'should have started 3 apps' 'online' 3 15 | 16 | $pm2 stop /echo-[1,2]/ 17 | 18 | should 'should have stopped 2 apps' 'stopped' 2 19 | should 'only one app should still be online' 'online' 1 20 | 21 | $pm2 stop /echo-3/ 22 | should 'should have stopped 1 apps' 'online' 0 23 | 24 | $pm2 restart /echo-[1,2]/ 25 | 26 | should 'should have restarted 2 apps' 'online' 2 27 | 28 | -------------------------------------------------------------------------------- /test/fixtures/module-fixture/node_modules/pmx/node_modules/debug/bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "visionmedia-debug", 3 | "main": "dist/debug.js", 4 | "version": "2.2.0", 5 | "homepage": "https://github.com/visionmedia/debug", 6 | "authors": [ 7 | "TJ Holowaychuk " 8 | ], 9 | "description": "visionmedia-debug", 10 | "moduleType": [ 11 | "amd", 12 | "es6", 13 | "globals", 14 | "node" 15 | ], 16 | "keywords": [ 17 | "visionmedia", 18 | "debug" 19 | ], 20 | "license": "MIT", 21 | "ignore": [ 22 | "**/.*", 23 | "node_modules", 24 | "bower_components", 25 | "test", 26 | "tests" 27 | ] 28 | } 29 | -------------------------------------------------------------------------------- /test/benchmarks/monit.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | RESULT_FILE=result.monit 4 | 5 | export RESULT_FILE=$RESULT_FILE 6 | 7 | launch() { 8 | echo "========= `date`" >> $RESULT_FILE 9 | nohup ./monit-daemon.sh &> monit.log & 10 | } 11 | 12 | ppkill() { 13 | pkill -f monit-daemon.sh ; pkill -f sleep 14 | } 15 | 16 | case "$1" in 17 | start) 18 | launch 19 | ;; 20 | kill) 21 | ppkill 22 | ;; 23 | stop) 24 | ppkill 25 | ;; 26 | restart) 27 | ppkill 28 | launch 29 | ;; 30 | *) 31 | echo "Usage: {start|kill|stop|restart}" 32 | exit 1 33 | ;; 34 | esac 35 | exit $RETVAL 36 | -------------------------------------------------------------------------------- /test/bash/vizion.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | SRC=$(cd $(dirname "$0"); pwd) 4 | source "${SRC}/include.sh" 5 | 6 | cd $file_path 7 | 8 | echo "################## VIZION ###################" 9 | 10 | mv git .git 11 | 12 | ############### 13 | $pm2 kill 14 | $pm2 start echo.js 15 | sleep 1 16 | 17 | should 'should have versioning metadata' 'jshkurti/pm2_travis' 1 18 | 19 | $pm2 delete all 20 | $pm2 start echo.js --no-vizion 21 | sleep 1 22 | 23 | should 'should not have versioning metadata' 'jshkurti/pm2_travis' 0 24 | 25 | $pm2 delete all 26 | $pm2 start no-vizion.json 27 | sleep 1 28 | 29 | should 'should not have versioning metadata' 'jshkurti/pm2_travis' 0 30 | 31 | mv .git git 32 | -------------------------------------------------------------------------------- /examples/process-file/process.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | apps : [{ 3 | name : 'HTTP-API', 4 | script : 'http.js', 5 | exec_mode : 'cluster', 6 | instances : 'max', 7 | max_memory_restart : '260M', 8 | 9 | ignore_watch : ['node_modules'], 10 | env : { 11 | NODE_ENV : 'normal' 12 | }, 13 | env_production : { 14 | NODE_ENV : 'production' 15 | } 16 | }, { 17 | name : 'Worker', 18 | script : 'worker.js', 19 | err_file : 'toto-err.log' 20 | }, { 21 | name : 'Checks', 22 | script : 'connection_check.sh' 23 | }] 24 | } 25 | -------------------------------------------------------------------------------- /test/helpers/plan.js: -------------------------------------------------------------------------------- 1 | 2 | var assert = require('assert'); 3 | 4 | /** 5 | * Description 6 | * @method Plan 7 | * @param {} count 8 | * @param {} done 9 | * @return 10 | */ 11 | function Plan(count, done) { 12 | this.done = done; 13 | this.count = count; 14 | } 15 | 16 | /** 17 | * Description 18 | * @method ok 19 | * @param {} expression 20 | * @return 21 | */ 22 | Plan.prototype.ok = function(expression) { 23 | assert(expression); 24 | 25 | if (this.count === 0) { 26 | assert(false, 'Too many assertions called'); 27 | } else { 28 | this.count--; 29 | } 30 | 31 | if (this.count === 0) { 32 | this.done(); 33 | } 34 | }; 35 | 36 | module.exports = Plan; 37 | -------------------------------------------------------------------------------- /test/bash/multiparam.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | SRC=$(cd $(dirname "$0"); pwd) 4 | source "${SRC}/include.sh" 5 | 6 | cd $file_path 7 | 8 | ############# TEST 9 | 10 | echo -e "\033[1mRunning tests:\033[0m" 11 | 12 | ## Start 13 | $pm2 start child.js echo.js server.js 14 | should 'should app be online' 'online' 3 15 | 16 | ## Restart 17 | $pm2 restart child echo server 18 | should 'should app be online' 'online' 3 19 | should 'should all script been restarted one time' 'restart_time: 1' 3 20 | 21 | ## Stop 22 | $pm2 stop child echo server 23 | should 'should app be stopped' 'stopped' 3 24 | 25 | ## Delete 26 | $pm2 delete child echo server 27 | shouldnot 'should app be deleted' 'stopped' 3 28 | -------------------------------------------------------------------------------- /examples/v1/process.json: -------------------------------------------------------------------------------- 1 | { 2 | "apps" : [{ 3 | "exec_interpreter" : "node", 4 | "exec_mode" : "cluster_mode", 5 | "instances" : 0, 6 | "log_date_format" : "YYYY-MM-DD HH:mm Z", 7 | "max_memory_restart" : "160M", 8 | "merge_logs" : true, 9 | "name" : "hapi_playground", 10 | "script" : "child.js", 11 | "cwd" : "examples", 12 | "node_args" : "--harmony", 13 | "ignore_watch" : ["[\\/\\\\]\\./", "log"], 14 | "watch" : true, 15 | env : { 16 | NODE_ENV : 'normal' 17 | }, 18 | env_production : { 19 | NODE_ENV : 'production' 20 | } 21 | }] 22 | } 23 | -------------------------------------------------------------------------------- /test/fixtures/events/custom_action_with_params.js: -------------------------------------------------------------------------------- 1 | 2 | var axm = require('pmx'); 3 | 4 | axm.action('refresh:db', { comment : 'Refresh the database' }, function(reply) { 5 | console.log('Refreshing'); 6 | reply({success : true}); 7 | }); 8 | 9 | axm.action('chanme:ladb', { comment : 'Refresh la BIG database' }, function(reply) { 10 | console.log('Refreshing BIG DB'); 11 | reply({success : true}); 12 | }); 13 | 14 | axm.action('rm:rf', { comment : 'Delete moi ca plus vite que ca !' }, function(reply) { 15 | console.log('RMING RFING'); 16 | reply({success : true}); 17 | }); 18 | 19 | axm.action('rm:roff', function(reply) { 20 | console.log('RMING RFING'); 21 | reply({success : true}); 22 | }); 23 | -------------------------------------------------------------------------------- /examples/http.js: -------------------------------------------------------------------------------- 1 | 2 | var http = require('http'); 3 | 4 | var server = http.createServer(function(req, res) { 5 | res.writeHead(200); 6 | res.end('hey'); 7 | }).listen(process.env.PORT || 8000, function() { 8 | console.log('App listening on port %d in env %s', process.env.PORT || 8000, process.env.NODE_ENV); 9 | 10 | // 1# Notify application ready 11 | setTimeout(function() { 12 | process.send('ready'); 13 | }, 2000); 14 | 15 | }); 16 | 17 | // // 2# Handle on Exit 18 | process.on('SIGINT', function() { 19 | console.log('Cleanup on exit'); 20 | 21 | server.on('close', function() { 22 | console.log('Connections closed'); 23 | process.exit(0); 24 | }); 25 | 26 | server.close(); 27 | }); 28 | -------------------------------------------------------------------------------- /examples/keymetrics-integration/custom_action_with_params.js: -------------------------------------------------------------------------------- 1 | 2 | var axm = require('pmx'); 3 | 4 | axm.action('refresh:db', { comment : 'Refresh the database' }, function(reply) { 5 | console.log('Refreshing'); 6 | reply({success : true}); 7 | }); 8 | 9 | axm.action('chanme:ladb', { comment : 'Refresh la BIG database' }, function(reply) { 10 | console.log('Refreshing BIG DB'); 11 | reply({success : true}); 12 | }); 13 | 14 | axm.action('rm:rf', { comment : 'Delete moi ca plus vite que ca !' }, function(reply) { 15 | console.log('RMING RFING'); 16 | reply({success : true}); 17 | }); 18 | 19 | axm.action('rm:roff', function(reply) { 20 | console.log('RMING RFING'); 21 | reply({success : true}); 22 | }); 23 | -------------------------------------------------------------------------------- /test/fixtures/extra-lang/apps.json: -------------------------------------------------------------------------------- 1 | { 2 | apps: [{ 3 | "interpreter" : "/usr/bin/python3", 4 | "name" : "echo-python", 5 | "script" : "echo.py", 6 | "interpreter_args" : "-u", 7 | "log" : "python-app.log", 8 | "combine_logs" : true, 9 | "env" : { 10 | DEFAULT_STR : "Python" 11 | }, 12 | "env_production" : { 13 | DEFAULT_STR : "PythonProduction" 14 | } 15 | }, { 16 | "exec_interpreter" : "/usr/bin/php", 17 | "name" : "echo-php", 18 | "script" : "echo.php", 19 | "output" : "php-app-out.log", 20 | "error" : "php-error.log", 21 | "combine_logs" : true 22 | }] 23 | } 24 | -------------------------------------------------------------------------------- /test/bash/start-consistency.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | SRC=$(cd $(dirname "$0"); pwd) 4 | source "${SRC}/include.sh" 5 | 6 | cd $file_path 7 | 8 | ############# TEST 9 | 10 | echo -e "\033[1mRunning tests:\033[0m" 11 | 12 | cd start-consistency; 13 | 14 | $pm2 start child.js 15 | 16 | LINE_NB_CLI=`$pm2 prettylist | wc -l` 17 | 18 | $pm2 delete all 19 | 20 | $pm2 start child.json 21 | 22 | LINE_NB_JSON=`$pm2 prettylist | wc -l` 23 | 24 | $pm2 prettylist | grep "vizion: true" 25 | spec "Vizion" 26 | 27 | 28 | # if [ $LINE_NB_JSON -eq $LINE_NB_CLI ] 29 | # then 30 | # success "Starting a basic JSON is consistent with CLI start" 31 | # else 32 | # fail "Starting a basic JSON is NOT consistent with CLI start" 33 | # fi 34 | -------------------------------------------------------------------------------- /test/fixtures/listen-timeout/wait-ready.js: -------------------------------------------------------------------------------- 1 | 2 | var http = require('http'); 3 | 4 | var server = http.createServer(function(req, res) { 5 | res.writeHead(200); 6 | res.end('hey'); 7 | }).listen(process.env.PORT || 8000, function() { 8 | console.log('App listening on port %d in env %s', process.env.PORT || 8000, process.env.NODE_ENV); 9 | 10 | // 1# Notify application ready 11 | setTimeout(function() { 12 | process.send('ready'); 13 | }, 2000); 14 | 15 | }); 16 | 17 | // // 2# Handle on Exit 18 | process.on('SIGINT', function() { 19 | console.log('Cleanup on exit'); 20 | 21 | server.on('close', function() { 22 | console.log('Connections closed'); 23 | process.exit(0); 24 | }); 25 | 26 | server.close(); 27 | }); 28 | -------------------------------------------------------------------------------- /test/fixtures/module-fixture/node_modules/pmx/lib/events.js: -------------------------------------------------------------------------------- 1 | 2 | var debug = require('debug')('axm:events'); 3 | var Transport = require('./utils/transport.js'); 4 | var Common = require('./common.js'); 5 | var stringify = require('json-stringify-safe'); 6 | 7 | var Events = {}; 8 | 9 | Events.emit = function(name, data) { 10 | if (!name) 11 | return console.error('[AXM] emit.name is missing'); 12 | if (!data) 13 | return console.error('[AXM] emit.data is missing'); 14 | 15 | var inflight_obj = JSON.parse(stringify(data)); 16 | 17 | inflight_obj.__name = name; 18 | 19 | Transport.send({ 20 | type : 'human:event', 21 | data : inflight_obj 22 | }, true); 23 | return false; 24 | }; 25 | 26 | module.exports = Events; 27 | -------------------------------------------------------------------------------- /examples/custom-nodejs-version/http.js: -------------------------------------------------------------------------------- 1 | 2 | var http = require('http'); 3 | 4 | console.log(process.version); 5 | 6 | var server = http.createServer(function(req, res) { 7 | res.writeHead(200); 8 | res.end('hey'); 9 | }).listen(process.env.PORT || 8000, function() { 10 | console.log('App listening on port %d in env %s', process.env.PORT || 8000, process.env.NODE_ENV); 11 | 12 | // 1# Notify application ready 13 | setTimeout(function() { 14 | process.send('ready'); 15 | }, 2000); 16 | 17 | }); 18 | 19 | // // 2# Handle on Exit 20 | process.on('SIGINT', function() { 21 | console.log('Cleanup on exit'); 22 | 23 | server.on('close', function() { 24 | console.log('Connections closed'); 25 | process.exit(0); 26 | }); 27 | 28 | server.close(); 29 | }); 30 | -------------------------------------------------------------------------------- /test/bash/gracefulReload3.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | SRC=$(cd $(dirname "$0"); pwd) 4 | source "${SRC}/include.sh" 5 | 6 | cd $file_path 7 | 8 | echo "################## GRACEFUL RELOAD 3 ###################" 9 | 10 | echo "Launching" 11 | $pm2 start graceful-exit-send.js -i 2 --name="graceful3" -o "grace3.log" -e "grace-err3.log" 12 | should 'should start processes' 'online' 2 13 | 14 | OUT_LOG=`$pm2 prettylist | grep -m 1 -E "pm_out_log_path:" | sed "s/.*'\([^']*\)',/\1/"` 15 | cat /dev/null > $OUT_LOG 16 | 17 | #### Graceful reload name 18 | $pm2 gracefulReload graceful3 19 | 20 | OUT=`grep "Finished closing connections" "$OUT_LOG" | wc -l` 21 | [ $OUT -eq 1 ] || fail "Process that sends 'online' not restarted gracefuly" 22 | success "Process that sends 'online' restarted gracefuly" 23 | -------------------------------------------------------------------------------- /examples/transpilers/http.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | /** 4 | * See the node.js TypeScript definition needed for this 5 | * example here: https://github.com/borisyankov/DefinitelyTyped 6 | */ 7 | 8 | import * as Http from "http"; 9 | 10 | class MyServer { 11 | private header:Object = {'Content-Type': 'text/plain'}; 12 | 13 | constructor() { 14 | var server:Http.Server = Http.createServer(this.onRequest); 15 | server.listen(3000, () => { 16 | console.log("Server started on port 3000"); 17 | }); 18 | } 19 | 20 | private onRequest(request:Http.ServerRequest, response:Http.ServerResponse):void { 21 | response.writeHead(200, this.header); 22 | response.end("Hello TypeScript & node.js"); 23 | } 24 | } 25 | 26 | var myServer = new MyServer(); 27 | -------------------------------------------------------------------------------- /test/fixtures/module-fixture/node_modules/pmx/test/fixtures/transpose.fixture.js: -------------------------------------------------------------------------------- 1 | 2 | var axm = require('../..'); 3 | 4 | var probe = axm.probe(); 5 | 6 | 7 | var config_example = { 8 | val : 'hey', 9 | test : { 10 | a : 'good', 11 | sign : 'healthy' 12 | } 13 | } 14 | 15 | /** 16 | * Monitor value 17 | */ 18 | 19 | // This is ompossible to do :( (refresh value by pointer): 20 | // 21 | // probe.transpose('docker_config', config_example); 22 | 23 | probe.transpose({ 24 | name : 'style_2_docker_config', 25 | data : function doSomething() { 26 | return config_example; 27 | } 28 | }); 29 | 30 | probe.transpose('style_1_docker_config', function doSomething() { 31 | return config_example; 32 | }); 33 | 34 | setTimeout(function() { 35 | config_example.val = 'new value'; 36 | }, 1100); 37 | -------------------------------------------------------------------------------- /examples/pmx/app.js: -------------------------------------------------------------------------------- 1 | 2 | const PM2 = require('../..'); 3 | 4 | var pm2 = new PM2.custom({ 5 | cwd : __dirname + '/elements' 6 | }); 7 | 8 | 9 | pm2.start([{ 10 | script : 'error.js' 11 | }, { 12 | script : 'metric.js' 13 | }, { 14 | script : 'counter.js' 15 | }, { 16 | script : 'meter.js' 17 | }, { 18 | script : 'histogram.js' 19 | }, { 20 | script : 'event.js' 21 | }, { 22 | script : 'notify.js' 23 | }, { 24 | script : 'log.js' 25 | }, { 26 | script : 'log-cluster.js', 27 | instances : 2 28 | }, { 29 | script : 'http.js' 30 | }, { 31 | script : 'cluster.js', 32 | instances : 4, 33 | env : { 34 | PORT : 9803 35 | } 36 | }, { 37 | script : 'trace.js', 38 | trace : true 39 | }], (err, procs) => { 40 | console.log(`${procs.length} test apps started`); 41 | pm2.disconnect(); 42 | }); 43 | -------------------------------------------------------------------------------- /test/fixtures/module-fixture/node_modules/pmx/test/transaction/app.mock.auto.js: -------------------------------------------------------------------------------- 1 | 2 | require('../..').init({ 3 | ignore_routes : [/\/socket\.io.*/] 4 | }); 5 | 6 | var express = require('express'); 7 | var app = express(); 8 | 9 | app.get('/', function(req, res) { 10 | res.send(202, {success:true}); 11 | }); 12 | 13 | app.get('/nothing', function(req, res) { 14 | res.send('yes'); 15 | }); 16 | 17 | 18 | app.get('/slow', function(req, res) { 19 | setTimeout(function() { 20 | res.send('yes'); 21 | }, 700); 22 | }); 23 | 24 | app.get('/socket.io/slow', function(req, res) { 25 | setTimeout(function() { 26 | res.send('yes'); 27 | }, 700); 28 | }); 29 | 30 | app.get('/nothing2', function(req, res) { 31 | setTimeout(function() { 32 | res.send('yes'); 33 | }, 1000); 34 | }); 35 | 36 | 37 | app.listen(9007); 38 | -------------------------------------------------------------------------------- /examples/v1/programmatic.js: -------------------------------------------------------------------------------- 1 | 2 | var pm2 = require('..'); 3 | 4 | pm2.connect(function() { 5 | 6 | pm2.start('echo.js', function() { 7 | 8 | setInterval(function() { 9 | pm2.restart('echo', function() { 10 | }); 11 | }, 2000); 12 | 13 | }); 14 | 15 | 16 | }); 17 | 18 | pm2.launchBus(function(err, bus) { 19 | console.log('connected', bus); 20 | 21 | bus.on('log:out', function(data) { 22 | if (data.process.name == 'echo') 23 | console.log(arguments); 24 | }); 25 | 26 | bus.on('reconnect attempt', function() { 27 | console.log('Bus reconnecting'); 28 | }); 29 | 30 | bus.on('close', function() { 31 | console.log('Bus closed'); 32 | }); 33 | 34 | }); 35 | 36 | /** 37 | * Exiting 38 | */ 39 | //pm2.disconnectBus(); // For Bus system 40 | //pm2.disconnect(); // For RPC connection 41 | -------------------------------------------------------------------------------- /lib/Interactor/internal-ip.js: -------------------------------------------------------------------------------- 1 | var os = require('os'); 2 | 3 | var type = { 4 | v4: { 5 | def: '127.0.0.1', 6 | family: 'IPv4' 7 | }, 8 | v6: { 9 | def: '::1', 10 | family: 'IPv6' 11 | } 12 | }; 13 | 14 | function internalIp(version) { 15 | var options = type[version]; 16 | var ret = options.def; 17 | var interfaces = os.networkInterfaces(); 18 | 19 | Object.keys(interfaces).forEach(function (el) { 20 | interfaces[el].forEach(function (el2) { 21 | if (!el2.internal && el2.family === options.family) { 22 | ret = el2.address; 23 | } 24 | }); 25 | }); 26 | 27 | return ret; 28 | } 29 | 30 | function v4() { 31 | return internalIp('v4'); 32 | } 33 | 34 | function v6() { 35 | return internalIp('v6'); 36 | } 37 | 38 | module.exports = v4; 39 | module.exports.v4 = v4; 40 | module.exports.v6 = v6; 41 | -------------------------------------------------------------------------------- /lib/templates/init-scripts/openrc.tpl: -------------------------------------------------------------------------------- 1 | #!/sbin/openrc-run 2 | 3 | name=pm2 4 | PM2="%PM2_PATH%" 5 | pidfile=/root/.pm2/${name}.pid 6 | user="%USER%" 7 | export PATH=/usr/bin:$PATH 8 | export PM2_HOME="/root/.pm2" 9 | 10 | if [ "${user}" != "root" ]; then 11 | pidfile="/home/${user}/.pm2/${name}.pid" 12 | export PM2_HOME="/home/${user}/.pm2" 13 | fi 14 | 15 | depend() { 16 | need net 17 | need localmount 18 | after bootmisc 19 | } 20 | 21 | start() { 22 | ebegin "Starting pm2" 23 | 24 | start-stop-daemon --start --pidfile ${pidfile} --user ${user} --exec ${PM2} -- resurrect 25 | eend $? 26 | } 27 | 28 | stop() { 29 | ebegin "Stopping pm2" 30 | 31 | $PM2 dump 32 | $PM2 delete all 33 | $PM2 kill 34 | eend $? 35 | return 0 36 | } 37 | 38 | reload() { 39 | ebegin "Reloading pm2" 40 | 41 | $PM2 reload all 42 | eend $? 43 | } 44 | -------------------------------------------------------------------------------- /test/fixtures/module-fixture/node_modules/pmx/lib/utils/transport.js: -------------------------------------------------------------------------------- 1 | 2 | var debug = require('debug')('axm:transport'); 3 | var stringify = require('json-stringify-safe'); 4 | 5 | var Transport = module.exports = {}; 6 | 7 | function ipcSend(args, print) { 8 | /** 9 | * For debug purpose 10 | */ 11 | if (process.env.MODULE_DEBUG) 12 | console.log(args); 13 | 14 | if (!process.send) { 15 | var output = args.data; 16 | delete output.__name; 17 | return false; 18 | } 19 | 20 | 21 | try { 22 | process.send(JSON.parse(stringify(args))); 23 | } catch(e) { 24 | console.error('Process disconnected from parent !'); 25 | console.error(e.stack || e); 26 | process.exit(1); 27 | } 28 | }; 29 | 30 | Transport.send = function(args, print) { 31 | if (!print) print = false; 32 | 33 | ipcSend(args, print); 34 | }; 35 | -------------------------------------------------------------------------------- /test/fixtures/module-fixture/node_modules/pmx/node_modules/json-stringify-safe/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## Unreleased 2 | - Fixes stringify to only take ancestors into account when checking 3 | circularity. 4 | It previously assumed every visited object was circular which led to [false 5 | positives][issue9]. 6 | Uses the tiny serializer I wrote for [Must.js][must] a year and a half ago. 7 | - Fixes calling the `replacer` function in the proper context (`thisArg`). 8 | - Fixes calling the `cycleReplacer` function in the proper context (`thisArg`). 9 | - Speeds serializing by a factor of 10 | Big-O(h-my-god-it-linearly-searched-every-object) it had ever seen. Searching 11 | only the ancestors for a circular references speeds up things considerably. 12 | 13 | [must]: https://github.com/moll/js-must 14 | [issue9]: https://github.com/isaacs/json-stringify-safe/issues/9 15 | -------------------------------------------------------------------------------- /test/bash/pm2-dev.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | SRC=$(cd $(dirname "$0"); pwd) 4 | source "${SRC}/include.sh" 5 | 6 | pm2dev="`type -P node` `pwd`/bin/pm2-dev" 7 | rundev="`type -P node` `pwd`/bin/rundev" 8 | 9 | export PM2_HOME=$HOME'/.pm2-dev' 10 | 11 | cd $file_path/pm2-dev 12 | 13 | # Test with js 14 | $rundev start app.js --test-mode 15 | $pm2 ls 16 | should 'should have started 1 apps' 'online' 1 17 | should 'should watch be true' 'watch: true' 1 18 | $pm2 kill 19 | 20 | # Test with json and args 21 | $rundev start app.json --test-mode 22 | $pm2 ls 23 | should 'should have started 1 apps' 'online' 1 24 | $pm2 prettylist | grep "watch: \[ 'server', 'client' \]" 25 | spec "Should application have two watch arguments" 26 | $pm2 prettylist | grep "ignore_watch: \[ 'node_modules', 'client/img' \]" 27 | spec "Should application have two ignore_watch arguments" 28 | $pm2 kill 29 | -------------------------------------------------------------------------------- /test/bash/gracefulReload2.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | SRC=$(cd $(dirname "$0"); pwd) 4 | source "${SRC}/include.sh" 5 | 6 | cd $file_path 7 | 8 | echo "################## GRACEFUL RELOAD 2 ###################" 9 | 10 | echo "Launching" 11 | $pm2 start graceful-exit-no-listen.js -i 2 --name="graceful2" -o "grace2.log" -e "grace-err2.log" 12 | should 'should start processes' 'online' 2 13 | 14 | OUT_LOG=`$pm2 prettylist | grep -m 1 -E "pm_out_log_path:" | sed "s/.*'\([^']*\)',/\1/"` 15 | cat /dev/null > $OUT_LOG 16 | 17 | #### Graceful reload name 18 | $pm2 gracefulReload graceful2 19 | 20 | echo "PATH: $OUT_LOG" 21 | 22 | TEXT=$(cat $OUT_LOG) 23 | 24 | echo "TEXT: $TEXT" 25 | 26 | OUT=`grep "Finished closing connections" "$OUT_LOG" | wc -l` 27 | [ $OUT -eq 1 ] || fail "Non-listening process not restarted gracefuly" 28 | success "Non-listening process restarted gracefuly" 29 | -------------------------------------------------------------------------------- /test/interface/filter.mocha.js: -------------------------------------------------------------------------------- 1 | 2 | var Filter = require('../../lib/Interactor/Filter.js'); 3 | var should = require('should'); 4 | var os = require('os'); 5 | 6 | describe('Filter Utility', function() { 7 | it('should .status works as expected', function() { 8 | var filtered = Filter.status([], { 9 | REVERSE_INTERACT : true, 10 | PM2_VERSION : '2.2.0' 11 | }); 12 | filtered.server.should.have.properties(['loadavg', 'total_mem', 'free_mem']); 13 | should(filtered.server.total_mem).eql(os.totalmem()); 14 | should(filtered.server.arch).eql(os.arch()); 15 | }); 16 | 17 | it('should .monitoring works as expected', function() { 18 | var filtered = Filter.monitoring([], {}); 19 | filtered.should.have.properties(['loadavg', 'total_mem', 'free_mem', 'processes']); 20 | filtered.total_mem.should.eql(os.totalmem()); 21 | }); 22 | 23 | }); 24 | -------------------------------------------------------------------------------- /test/interface/README.md: -------------------------------------------------------------------------------- 1 | 2 | ## Structure 3 | 4 | . 5 | ├── bus.fork.spec.mocha.js 6 | ├── bus.spec.mocha.js 7 | ├── custom-actions.mocha.js 8 | ├── fixtures 9 | │   ├── http_transaction.js 10 | │   ├── human_event.js 11 | │   ├── log_out.js 12 | │   └── process_exception.js 13 | ├── interactor.connect.mocha.js 14 | ├── interactor.connect.two.mocha.js 15 | ├── interactor.daemonizer.mocha.js 16 | ├── password.mocha.js 17 | ├── README.md 18 | ├── remote.mocha.js 19 | └── scoped_pm2_actions.mocha.js 20 | 21 | 22 | ### Test about pmx.notify not working 23 | 24 | - bus.fork.spec.mocha.js 25 | - bus.spec.mocha.js 26 | 27 | 28 | 29 | 30 | - bus.spec.mocha.js: event system sent (wo agent) 31 | - custom-actions.mocha.js: connect and try custom actions 32 | - interactor.daemonizer.mocha.js: basic methods testing for automatic re read of agent conf (wo agent) 33 | - interactor.connect.mocha.js: 34 | -------------------------------------------------------------------------------- /test/fixtures/module-fixture/node_modules/pmx/node_modules/json-stringify-safe/LICENSE: -------------------------------------------------------------------------------- 1 | The ISC License 2 | 3 | Copyright (c) Isaac Z. Schlueter and Contributors 4 | 5 | Permission to use, copy, modify, and/or distribute this software for any 6 | purpose with or without fee is hereby granted, provided that the above 7 | copyright notice and this permission notice appear in all copies. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR 15 | IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | -------------------------------------------------------------------------------- /test/bash/harmony.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | SRC=$(cd $(dirname "$0"); pwd) 4 | source "${SRC}/include.sh" 5 | 6 | cd $file_path 7 | 8 | echo "################ HARMONY ES6" 9 | 10 | $pm2 start harmony.js --node-args="--harmony" 11 | sleep 2 12 | $pm2 list 13 | should 'should not fail when passing node-args=harmony opts in CLUSTERMODE' 'restart_time: 0' 1 14 | $pm2 delete all 15 | 16 | echo "################ HARMONY / NODEARGS ES6 FORK MODE" 17 | 18 | $pm2 start harmony.js --node-args="--harmony" -x 19 | sleep 2 20 | $pm2 list 21 | should 'should not fail when passing node-args=harmony opts in FORKMODE' 'restart_time: 0' 1 22 | $pm2 delete all 23 | 24 | echo "################## NODE ARGS VIA JSON" 25 | 26 | $pm2 start harmony.json 27 | sleep 2 28 | $pm2 list 29 | should 'should not fail when passing harmony option to V8 via node_args in JSON files' 'restart_time: 0' 1 30 | 31 | $pm2 delete all 32 | -------------------------------------------------------------------------------- /test/fixtures/module-fixture/node_modules/pmx/node_modules/json-stringify-safe/Makefile: -------------------------------------------------------------------------------- 1 | NODE_OPTS = 2 | TEST_OPTS = 3 | 4 | love: 5 | @echo "Feel like makin' love." 6 | 7 | test: 8 | @node $(NODE_OPTS) ./node_modules/.bin/_mocha -R dot $(TEST_OPTS) 9 | 10 | spec: 11 | @node $(NODE_OPTS) ./node_modules/.bin/_mocha -R spec $(TEST_OPTS) 12 | 13 | autotest: 14 | @node $(NODE_OPTS) ./node_modules/.bin/_mocha -R dot --watch $(TEST_OPTS) 15 | 16 | autospec: 17 | @node $(NODE_OPTS) ./node_modules/.bin/_mocha -R spec --watch $(TEST_OPTS) 18 | 19 | pack: 20 | @file=$$(npm pack); echo "$$file"; tar tf "$$file" 21 | 22 | publish: 23 | npm publish 24 | 25 | tag: 26 | git tag "v$$(node -e 'console.log(require("./package").version)')" 27 | 28 | clean: 29 | rm -f *.tgz 30 | npm prune --production 31 | 32 | .PHONY: love 33 | .PHONY: test spec autotest autospec 34 | .PHONY: pack publish tag 35 | .PHONY: clean 36 | -------------------------------------------------------------------------------- /test/fixtures/source-map/models.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | var UserMessage = (function () { 3 | function UserMessage(payload) { 4 | var data = JSON.parse(payload); 5 | if (!data.name || !data.message) { 6 | throw new Error('Invalid message payload received: ' + payload); 7 | } 8 | this.data = data; 9 | } 10 | Object.defineProperty(UserMessage.prototype, "name", { 11 | get: function () { 12 | return this.data.name; 13 | }, 14 | enumerable: true, 15 | configurable: true 16 | }); 17 | Object.defineProperty(UserMessage.prototype, "message", { 18 | get: function () { 19 | return this.data.message; 20 | }, 21 | enumerable: true, 22 | configurable: true 23 | }); 24 | return UserMessage; 25 | }()); 26 | exports.UserMessage = UserMessage; 27 | //# sourceMappingURL=models.js.map -------------------------------------------------------------------------------- /test/fixtures/module-fixture/node_modules/pmx/test/fixtures/histogram.fixture.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | var axm = require('../..'); 4 | 5 | var probe = axm.probe(); 6 | 7 | var histogram = probe.histogram({ 8 | name : 'test', 9 | measurement : 'p95', 10 | agg_type: 'sum' 11 | }); 12 | 13 | var a = 0; 14 | 15 | setInterval(function() { 16 | a = Math.round(Math.random() * 100); 17 | histogram.update(a); 18 | }, 100); 19 | 20 | var h2 = probe.histogram({ 21 | name : 'mean', 22 | measurement : 'mean', 23 | unit : 'ms' 24 | }); 25 | 26 | var b = 0; 27 | 28 | setInterval(function() { 29 | b = Math.round(Math.random() * 100); 30 | h2.update(b); 31 | }, 100); 32 | 33 | 34 | var h3 = probe.histogram({ 35 | name : 'min', 36 | measurement : 'min', 37 | agg_type: 'min' 38 | }); 39 | 40 | var c = 0; 41 | 42 | setInterval(function() { 43 | c = Math.round(Math.random() * 100); 44 | h3.update(c); 45 | }, 100); 46 | -------------------------------------------------------------------------------- /test/bash/fork.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | SRC=$(cd $(dirname "$0"); pwd) 4 | source "${SRC}/include.sh" 5 | 6 | cd $file_path 7 | 8 | ########### Fork mode 9 | $pm2 start echo.js -x 10 | should 'should has forked app' 'fork_mode' 1 11 | 12 | $pm2 restart echo.js 13 | should 'should has forked app' 'restart_time: 1' 1 14 | 15 | ########### Fork mode 16 | $pm2 kill 17 | 18 | $pm2 start bashscript.sh 19 | should 'should has forked app' 'fork_mode' 1 20 | 21 | ########### Auto Detective Interpreter In Fork mode 22 | 23 | $pm2 kill 24 | 25 | $pm2 start echo.coffee 26 | should 'should has forked app' 'fork_mode' 1 27 | 28 | ### Dump resurrect should be ok 29 | $pm2 dump 30 | 31 | $pm2 kill 32 | 33 | #should 'should has forked app' 'fork' 0 34 | 35 | $pm2 resurrect 36 | should 'should has forked app' 'fork_mode' 1 37 | 38 | ## Delete 39 | 40 | $pm2 list 41 | 42 | $pm2 delete 0 43 | should 'should has delete process' 'fork_mode' 0 44 | -------------------------------------------------------------------------------- /test/fixtures/module-fixture/node_modules/pmx/node_modules/debug/Makefile: -------------------------------------------------------------------------------- 1 | 2 | # get Makefile directory name: http://stackoverflow.com/a/5982798/376773 3 | THIS_MAKEFILE_PATH:=$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)) 4 | THIS_DIR:=$(shell cd $(dir $(THIS_MAKEFILE_PATH));pwd) 5 | 6 | # BIN directory 7 | BIN := $(THIS_DIR)/node_modules/.bin 8 | 9 | # applications 10 | NODE ?= $(shell which node) 11 | NPM ?= $(NODE) $(shell which npm) 12 | BROWSERIFY ?= $(NODE) $(BIN)/browserify 13 | 14 | all: dist/debug.js 15 | 16 | install: node_modules 17 | 18 | clean: 19 | @rm -rf dist 20 | 21 | dist: 22 | @mkdir -p $@ 23 | 24 | dist/debug.js: node_modules browser.js debug.js dist 25 | @$(BROWSERIFY) \ 26 | --standalone debug \ 27 | . > $@ 28 | 29 | distclean: clean 30 | @rm -rf node_modules 31 | 32 | node_modules: package.json 33 | @NODE_ENV= $(NPM) install 34 | @touch node_modules 35 | 36 | .PHONY: all install clean distclean 37 | -------------------------------------------------------------------------------- /lib/keymetrics.bkcp: -------------------------------------------------------------------------------- 1 | 2 | ------------- 3 | 4 | Looking for a complete monitoring and management tool for PM2? 5 | _ _ _ _ 6 | | | _____ _ _ _ __ ___ ___| |_ _ __(_) ___ ___ (_) ___ 7 | | |/ / _ \ | | | '_ ` _ \ / _ \ __| '__| |/ __/ __| | |/ _ \ 8 | | < __/ |_| | | | | | | __/ |_| | | | (__\__ \_| | (_) | 9 | |_|\_\___|\__, |_| |_| |_|\___|\__|_| |_|\___|___(_)_|\___/ 10 | |___/ 11 | 12 | Features 13 | 14 | - Real Time Dashboard 15 | - CPU/Memory monitoring 16 | - HTTP monitoring 17 | - Event notification 18 | - Custom value monitoring 19 | - Real Time log display 20 | 21 | Checkout 22 | 23 | https://keymetrics.io/ 24 | 25 | ------------- 26 | -------------------------------------------------------------------------------- /examples/v1/wrap.js: -------------------------------------------------------------------------------- 1 | 2 | var debug = require('debug')('methods'); 3 | 4 | var Proxy = module.exports = { 5 | wrap : function(object, methods, hook) { 6 | var self = this; 7 | 8 | if (!Array.isArray(methods)) methods = [methods]; 9 | 10 | for (var i = 0; i < methods.length; ++i) { 11 | debug('Wrapping method:', methods[i]); 12 | var original = object[methods[i]]; 13 | if (!original) return debug('Method %s unknown', methods[i]); 14 | if (original.__axm_original) { 15 | debug('Already wrapped', methods[i]); 16 | if (methods[i] != '_load') 17 | return; 18 | } 19 | var hooked = hook(original); 20 | 21 | if (original.__axm_original) { 22 | hooked.__axm_original = original.__axm_original; 23 | } 24 | else { 25 | hooked.__axm_original = original; 26 | } 27 | object[methods[i]] = hooked; 28 | //debug('Method proxified'); 29 | } 30 | } 31 | }; 32 | -------------------------------------------------------------------------------- /test/programmatic_commands.txt: -------------------------------------------------------------------------------- 1 | mocha ./programmatic/god.mocha.js 2 | mocha ./programmatic/programmatic.js 3 | mocha ./programmatic/logs.js 4 | mocha ./programmatic/watcher.js 5 | mocha ./programmatic/max_memory_limit.js 6 | mocha ./programmatic/cluster.mocha.js 7 | mocha ./programmatic/misc_commands.js 8 | mocha ./programmatic/signals.js 9 | mocha ./programmatic/send_data_process.mocha.js 10 | mocha ./programmatic/return.mocha.js 11 | mocha ./programmatic/json_validation.mocha.js 12 | mocha ./programmatic/env_switching.js 13 | mocha ./programmatic/configuration.mocha.js 14 | mocha ./interface/interactor.connect.mocha.js 15 | mocha ./interface/interactor.daemonizer.mocha.js 16 | mocha ./interface/remote.mocha.js 17 | mocha ./interface/scoped_pm2_actions.mocha.js 18 | mocha ./interface/password.mocha.js 19 | mocha ./interface/custom-actions.mocha.js 20 | mocha ./interface/bus.spec.mocha.js 21 | mocha ./interface/bus.fork.spec.mocha.js 22 | mocha ./interface/request.mocha.js 23 | -------------------------------------------------------------------------------- /test/fixtures/module-fixture/node_modules/pmx/test/event.mocha.js: -------------------------------------------------------------------------------- 1 | 2 | var axm = require('..'); 3 | 4 | function fork() { 5 | return require('child_process').fork(__dirname + '/event.mock.js', []); 6 | } 7 | 8 | describe('Event', function() { 9 | it('should have right property', function(done) { 10 | axm.should.have.property('emit'); 11 | done(); 12 | }); 13 | 14 | describe('Event scenario', function() { 15 | var app; 16 | 17 | before(function() { 18 | app = fork(); 19 | }); 20 | 21 | after(function() { 22 | process.kill(app.pid); 23 | }); 24 | 25 | it('should send right event data when called', function(done) { 26 | app.once('message', function(data) { 27 | data.type.should.eql('human:event'); 28 | data.data.user.should.eql('toto'); 29 | data.data.__name.should.eql('test'); 30 | data.data.subobj.subobj.a.should.eql('b'); 31 | done(); 32 | }); 33 | }); 34 | }); 35 | 36 | 37 | 38 | }); 39 | -------------------------------------------------------------------------------- /test/fixtures/module-fixture/node_modules/pmx/lib/utils/probes/Meter.js: -------------------------------------------------------------------------------- 1 | 2 | // Hacked from https://github.com/felixge/node-measured 3 | 4 | var units = require('../units'); 5 | var EWMA = require('../EWMA'); 6 | 7 | function Meter(opts) { 8 | var self = this; 9 | 10 | this._tickInterval = 5 * units.SECONDS; 11 | this._samples = opts.samples || 1; 12 | this._timeframe = opts.timeframe || 60; 13 | 14 | this._rate = new EWMA(this._timeframe * units.SECONDS, this._tickInterval); 15 | 16 | if (opts.debug && opts.debug == true) 17 | return false; 18 | 19 | this._interval = setInterval(function() { 20 | self._rate.tick(); 21 | }, this._tickInterval); 22 | } 23 | 24 | Meter.RATE_UNIT = units.SECONDS; 25 | 26 | Meter.prototype.mark = function(n) { 27 | n = n || 1; 28 | 29 | this._rate.update(n); 30 | }; 31 | 32 | Meter.prototype.val = function() { 33 | return Math.round(this._rate.rate(this._samples * Meter.RATE_UNIT) * 100 ) / 100; 34 | }; 35 | 36 | module.exports = Meter; 37 | -------------------------------------------------------------------------------- /test/fixtures/git/hooks/commit-msg.sample: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # An example hook script to check the commit log message. 4 | # Called by "git commit" with one argument, the name of the file 5 | # that has the commit message. The hook should exit with non-zero 6 | # status after issuing an appropriate message if it wants to stop the 7 | # commit. The hook is allowed to edit the commit message file. 8 | # 9 | # To enable this hook, rename this file to "commit-msg". 10 | 11 | # Uncomment the below to add a Signed-off-by line to the message. 12 | # Doing this in a hook is a bad idea in general, but the prepare-commit-msg 13 | # hook is more suited to it. 14 | # 15 | # SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p') 16 | # grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1" 17 | 18 | # This example catches duplicate Signed-off-by lines. 19 | 20 | test "" = "$(grep '^Signed-off-by: ' "$1" | 21 | sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || { 22 | echo >&2 Duplicate Signed-off-by lines. 23 | exit 1 24 | } 25 | -------------------------------------------------------------------------------- /test/bash/smart-start.sh: -------------------------------------------------------------------------------- 1 | 2 | #!/usr/bin/env bash 3 | 4 | SRC=$(cd $(dirname "$0"); pwd) 5 | source "${SRC}/include.sh" 6 | 7 | cd $file_path 8 | 9 | # 10 | # Test for SMART start 11 | # 12 | 13 | $pm2 start echo.js 14 | should 'process should have been started' 'restart_time: 0' 1 15 | should 'process should have been started' 'online' 1 16 | 17 | $pm2 stop echo 18 | should 'process should have been started' 'stopped' 1 19 | 20 | $pm2 start echo 21 | should 'process should have been started' 'online' 1 22 | 23 | $pm2 start echo 24 | should 'process should have been started' 'restart_time: 1' 1 25 | should 'process should have been started' 'online' 1 26 | 27 | $pm2 start 0 28 | should 'process should have been started' 'restart_time: 2' 1 29 | should 'process should have been started' 'online' 1 30 | 31 | # $pm2 stop echo 32 | # should 'process should have been started' 'stopped' 1 33 | 34 | # $pm2 start all 35 | # should 'process should have been started' 'restart_time: 2' 1 36 | # should 'process should have been started' 'online' 1 37 | -------------------------------------------------------------------------------- /test/bash/yaml-configuration.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | SRC=$(cd $(dirname "$0"); pwd) 4 | source "${SRC}/include.sh" 5 | cd $file_path/yaml-configuration 6 | 7 | $pm2 start non-existent.yaml 8 | should 'should have started 0 processes because file unknown' 'online' 0 9 | 10 | $pm2 start malformated.yml 11 | should 'should have started 0 processes because file malformated' 'online' 0 12 | 13 | $pm2 start apps.yaml 14 | should 'should have started 6 processes' 'online' 6 15 | 16 | $pm2 restart all 17 | should 'should have restarted 6 processes' 'restart_time: 1' 6 18 | 19 | $pm2 restart apps.yaml 20 | should 'should have restarted 6 processes' 'restart_time: 2' 6 21 | 22 | $pm2 reload all 23 | should 'should have reloaded 6 processes' 'restart_time: 3' 6 24 | 25 | $pm2 reload apps.yaml 26 | should 'should have reloaded 6 processes' 'restart_time: 4' 6 27 | 28 | $pm2 stop all 29 | should 'should have reloaded 6 processes' 'stopped' 6 30 | 31 | $pm2 start apps.yaml 32 | $pm2 delete all 33 | should 'should have deleted 6 processes' 'online' 0 34 | -------------------------------------------------------------------------------- /test/bash/gracefulReload.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | SRC=$(cd $(dirname "$0"); pwd) 4 | source "${SRC}/include.sh" 5 | 6 | cd $file_path 7 | 8 | echo "################## GRACEFUL RELOAD ###################" 9 | 10 | ############### 11 | 12 | echo "Launching" 13 | $pm2 start graceful-exit.js -i 4 --name="graceful" -o "grace.log" -e "grace-err.log" 14 | should 'should start processes' 'online' 4 15 | 16 | OUT_LOG=`$pm2 prettylist | grep -m 1 -E "pm_out_log_path:" | sed "s/.*'\([^']*\)',/\1/"` 17 | cat /dev/null > $OUT_LOG 18 | 19 | #### Graceful reload all 20 | 21 | $pm2 gracefulReload all 22 | 23 | OUT=`grep "Finished closing connections" "$OUT_LOG" | wc -l` 24 | [ $OUT -eq 1 ] || fail "Process not restarted gracefuly" 25 | success "Process restarted gracefuly" 26 | 27 | 28 | cat /dev/null > $OUT_LOG 29 | 30 | #### Graceful reload name 31 | $pm2 gracefulReload graceful 32 | 33 | OUT=`grep "Finished closing connections" "$OUT_LOG" | wc -l` 34 | [ $OUT -eq 1 ] || fail "Process not restarted gracefuly" 35 | success "Process restarted gracefuly" 36 | -------------------------------------------------------------------------------- /examples/keymetrics-integration/keymetrics-load.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | var pm2 = require('../..'); 4 | 5 | pm2.connect(function() { 6 | pm2.delete('all', function() { 7 | pm2.start('examples/human_event.js', function() { 8 | pm2.start('examples/child.js', {instances:2},function() { 9 | pm2.start('examples/kill-not-so-fast.js', { 10 | instances:10, 11 | minUptime: 0, 12 | force:true, 13 | maxRestarts : 0 14 | }, function() { 15 | pm2.start('examples/auto-save.js', {execMode : 'fork', watch:true, force : true}, function() { 16 | pm2.start('examples/custom_action_with_params.js', function() { 17 | //pm2.start('examples/auto-bench.js', {instances : 'max'}, function() { 18 | pm2.start('examples/throw.js', {force:true, name:'auto-throw'}, function() { 19 | pm2.disconnect(function() { process.exit(1); }); 20 | }); 21 | }); 22 | 23 | }); 24 | }); 25 | }); 26 | 27 | }); 28 | }); 29 | }); 30 | -------------------------------------------------------------------------------- /lib/Interactor/RemoteActions/ScopedExecution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013 the PM2 project authors. All rights reserved. 3 | * Use of this source code is governed by a license that 4 | * can be found in the LICENSE file. 5 | */ 6 | 7 | var pm2 = require('../../..'); 8 | var domain = require('domain'); 9 | var Utility = require('../../Utility.js'); 10 | 11 | var d = domain.create(); 12 | 13 | d.once('error', function(err) { 14 | process.send(JSON.stringify({err: err.stack, isFinished : true})); 15 | }); 16 | 17 | d.run(function() { 18 | var params = JSON.parse(process.env.fork_params); 19 | 20 | console.log('Executing: pm2 %s %s', 21 | params.action, 22 | params.opts.args ? params.opts.args.join(' ') : ''); 23 | 24 | pm2.connect(function() { 25 | pm2.remoteV2(params.action, params.opts, function(err, dt) { 26 | process.send(JSON.stringify(Utility.clone({ 27 | err: err, 28 | dt: dt, 29 | isFinished : true 30 | }))); 31 | pm2.disconnect(process.exit); 32 | }); 33 | }); 34 | }); 35 | -------------------------------------------------------------------------------- /lib/templates/init-scripts/launchd.tpl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Label 6 | com.PM2 7 | UserName 8 | %USER% 9 | KeepAlive 10 | 11 | ProgramArguments 12 | 13 | /bin/sh 14 | -c 15 | %PM2_PATH% resurrect 16 | 17 | RunAtLoad 18 | 19 | OnDemand 20 | 21 | LaunchOnlyOnce 22 | 23 | EnvironmentVariables 24 | 25 | PATH 26 | %NODE_PATH% 27 | PM2_HOME 28 | %HOME_PATH% 29 | 30 | StandardErrorPath 31 | /tmp/com.PM2.err 32 | StandardOutPath 33 | /tmp/com.PM2.out 34 | 35 | 36 | -------------------------------------------------------------------------------- /test/fixtures/module-fixture/node_modules/pmx/node_modules/json-stringify-safe/stringify.js: -------------------------------------------------------------------------------- 1 | exports = module.exports = stringify 2 | exports.getSerialize = serializer 3 | 4 | function stringify(obj, replacer, spaces, cycleReplacer) { 5 | return JSON.stringify(obj, serializer(replacer, cycleReplacer), spaces) 6 | } 7 | 8 | function serializer(replacer, cycleReplacer) { 9 | var stack = [], keys = [] 10 | 11 | if (cycleReplacer == null) cycleReplacer = function(key, value) { 12 | if (stack[0] === value) return "[Circular ~]" 13 | return "[Circular ~." + keys.slice(0, stack.indexOf(value)).join(".") + "]" 14 | } 15 | 16 | return function(key, value) { 17 | if (stack.length > 0) { 18 | var thisPos = stack.indexOf(this) 19 | ~thisPos ? stack.splice(thisPos + 1) : stack.push(this) 20 | ~thisPos ? keys.splice(thisPos, Infinity, key) : keys.push(key) 21 | if (~stack.indexOf(value)) value = cycleReplacer.call(this, key, value) 22 | } 23 | else stack.push(value) 24 | 25 | return replacer == null ? value : replacer.call(this, key, value) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /test/programmatic/api.backward.compatibility.mocha.js: -------------------------------------------------------------------------------- 1 | 2 | process.chdir(__dirname); 3 | 4 | var PM2 = require('../..'); 5 | var should = require('should'); 6 | 7 | describe('API backward compatibility checks', function() { 8 | describe('Backward compatibility', function() { 9 | it('should start pm2 in no daemon mode', function(done) { 10 | PM2.connect(true, function(err) { 11 | should(PM2.daemon_mode).be.false(); 12 | should(PM2.Client.daemon_mode).be.false(); 13 | done(); 14 | }); 15 | }); 16 | 17 | it('should be able to start a script', function(done) { 18 | PM2.start('./../fixtures/child.js', function(err) { 19 | should(err).be.null(); 20 | done(); 21 | }); 22 | }); 23 | 24 | it('should list one process', function(done) { 25 | PM2.list(function(err, list) { 26 | should(err).be.null(); 27 | should(list.length).eql(1); 28 | done(); 29 | }); 30 | }); 31 | 32 | it('should kill PM2 in no daemon', function(done) { 33 | PM2.kill(done); 34 | }); 35 | }); 36 | }); 37 | -------------------------------------------------------------------------------- /examples/keymetrics-integration/pm2_probe.js: -------------------------------------------------------------------------------- 1 | var pmx = require('pmx'); 2 | var pm2 = require('../..'); 3 | var fs = require('fs'); 4 | var path = require('path'); 5 | 6 | var conf = pmx.initModule({ 7 | comment : 'This module monitors PM2', 8 | errors : true, 9 | latency : false, 10 | versioning : false, 11 | show_module_meta : false, 12 | module_type : 'database', 13 | pid : pmx.getPID(path.join(process.env.HOME, '.pm2', 'pm2.pid')), 14 | 15 | widget : { 16 | theme : ['#111111', '#1B2228', '#807C7C', '#807C7C'], 17 | logo : 'https://keymetrics.io/assets/images/pm2.20d3ef.png?v=0b71a506ce' 18 | } 19 | }); 20 | 21 | var probe = pmx.probe(); 22 | 23 | var pm2_procs = 0; 24 | 25 | pm2.connect(function() { 26 | 27 | setInterval(function() { 28 | pm2.list(function(err, procs) { 29 | pm2_procs = procs.length; 30 | }); 31 | }, 2000); 32 | 33 | var metric = probe.metric({ 34 | name : 'Processes', 35 | value : function() { 36 | return pm2_procs; 37 | } 38 | }); 39 | }); 40 | -------------------------------------------------------------------------------- /test/bash/log-custom.sh: -------------------------------------------------------------------------------- 1 | 2 | #!/usr/bin/env bash 3 | 4 | SRC=$(cd $(dirname "$0"); pwd) 5 | source "${SRC}/include.sh" 6 | 7 | cd $file_path 8 | 9 | CURRENT_YEAR=`date +"%Y"` 10 | 11 | # CLUSTERMODE YYYY 12 | $pm2 start echo.js --log-date-format "YYYY" -o out-rel.log --merge-logs 13 | 14 | >out-rel.log 15 | 16 | sleep 2 17 | 18 | grep $CURRENT_YEAR out-rel.log 19 | spec "Should have written year in log file according to format YYYY" 20 | 21 | rm out-rel.log 22 | 23 | $pm2 delete all 24 | 25 | # CLUSTERMODE Wrong format 26 | $pm2 start echo.js --log-date-format "YYYY asdsd asd asd sad asd " -o out-rel.log --merge-logs 27 | 28 | sleep 1 29 | should 'should has not restarted' 'restart_time: 0' 1 30 | spec "Should have not fail with random format" 31 | 32 | rm out-rel.log 33 | 34 | $pm2 delete all 35 | 36 | 37 | # CLUSTERMODE YYYY 38 | $pm2 start echo.js --log-date-format "YYYY" -o out-rel.log --merge-logs -x 39 | 40 | >out-rel.log 41 | 42 | sleep 2 43 | 44 | grep $CURRENT_YEAR out-rel.log 45 | spec "Should have written year in log file according to format YYYY" 46 | 47 | rm out-rel.log 48 | 49 | $pm2 delete all 50 | -------------------------------------------------------------------------------- /test/fixtures/module-fixture/node_modules/pmx/lib/utils/proxy.js: -------------------------------------------------------------------------------- 1 | 2 | var debug = require('debug')('axm:proxy'); 3 | 4 | // var cls = require('continuation-local-storage'); 5 | // var ns = cls.createNamespace('namespace'); 6 | 7 | var Proxy = module.exports = { 8 | wrap : function(object, methods, hook) { 9 | var self = this; 10 | 11 | if (!Array.isArray(methods)) methods = [methods]; 12 | 13 | for (var i = 0; i < methods.length; ++i) { 14 | debug('Wrapping method:', methods[i]); 15 | var original = object[methods[i]]; 16 | if (!original) return debug('Method %s unknown', methods[i]); 17 | if (original.__axm_original) { 18 | debug('Already wrapped', methods[i]); 19 | if (methods[i] != '_load') 20 | return; 21 | } 22 | var hooked = hook(original); 23 | 24 | if (original.__axm_original) { 25 | hooked.__axm_original = original.__axm_original; 26 | } 27 | else { 28 | hooked.__axm_original = original; 29 | } 30 | object[methods[i]] = hooked; 31 | //debug('Method proxified'); 32 | } 33 | } 34 | }; 35 | -------------------------------------------------------------------------------- /test/fixtures/log-json/ecosystem.json: -------------------------------------------------------------------------------- 1 | [{ 2 | "name" : "one-echo", 3 | "script" : "one-echo.js", 4 | "log_type": "json", 5 | "log_file": "output.log", 6 | "merge_logs": true, 7 | "out_file": "NULL", 8 | "error_file": "NULL", 9 | "autorestart": false 10 | }, 11 | { 12 | "name" : "one-echo-cluster", 13 | "script" : "one-echo.js", 14 | "exec_mode": "cluster_mode", 15 | "log_type": "json", 16 | "log_file": "output.log", 17 | "merge_logs": true, 18 | "out_file": "NULL", 19 | "error_file": "NULL", 20 | "autorestart": false 21 | }, 22 | { 23 | "name" : "one-echo-date", 24 | "script" : "one-echo.js", 25 | "log_type": "json", 26 | "log_file": "output.log", 27 | "log_date_format": "YYYY", 28 | "merge_logs": true, 29 | "out_file": "NULL", 30 | "error_file": "NULL", 31 | "autorestart": false 32 | }, 33 | { 34 | "name" : "one-echo-cluster-date", 35 | "script" : "one-echo.js", 36 | "exec_mode": "cluster_mode", 37 | "log_type": "json", 38 | "log_file": "output.log", 39 | "log_date_format": "YYYY", 40 | "merge_logs": true, 41 | "out_file": "NULL", 42 | "error_file": "NULL", 43 | "autorestart": false 44 | }] -------------------------------------------------------------------------------- /examples/binary/ecosystem.json: -------------------------------------------------------------------------------- 1 | { 2 | /** 3 | * Application configuration section 4 | * http://pm2.keymetrics.io/docs/usage/application-declaration/ 5 | */ 6 | apps : [ 7 | 8 | // First application 9 | { 10 | name : "LSOR", 11 | script : "http.js", 12 | "exec_interpreter" : "node@4.6.0" 13 | } 14 | ], 15 | 16 | /** 17 | * Deployment section 18 | * http://pm2.keymetrics.io/docs/usage/deployment/ 19 | */ 20 | deploy : { 21 | production : { 22 | user : "node", 23 | host : "212.83.163.1", 24 | ref : "origin/master", 25 | repo : "git@github.com:repo.git", 26 | path : "/var/www/production", 27 | "post-deploy" : "npm install && pm2 startOrRestart ecosystem.json --env production" 28 | }, 29 | dev : { 30 | user : "node", 31 | host : "212.83.163.1", 32 | ref : "origin/master", 33 | repo : "git@github.com:repo.git", 34 | path : "/var/www/development", 35 | "post-deploy" : "npm install && pm2 startOrRestart ecosystem.json --env dev", 36 | env : { 37 | NODE_ENV: "dev" 38 | } 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /test/fixtures/module-fixture/node_modules/pmx/lib/utils/EWMA.js: -------------------------------------------------------------------------------- 1 | 2 | // Hacked https://github.com/felixge/node-measured 3 | 4 | var units = require('./units'); 5 | 6 | module.exports = ExponentiallyWeightedMovingAverage; 7 | 8 | function ExponentiallyWeightedMovingAverage(timePeriod, tickInterval) { 9 | this._timePeriod = timePeriod || 1 * units.MINUTE; 10 | this._tickInterval = tickInterval || ExponentiallyWeightedMovingAverage.TICK_INTERVAL; 11 | this._alpha = 1 - Math.exp(-this._tickInterval / this._timePeriod); 12 | this._count = 0; 13 | this._rate = 0; 14 | }; 15 | 16 | ExponentiallyWeightedMovingAverage.TICK_INTERVAL = 5 * units.SECONDS; 17 | 18 | ExponentiallyWeightedMovingAverage.prototype.update = function(n) { 19 | this._count += n; 20 | }; 21 | 22 | ExponentiallyWeightedMovingAverage.prototype.tick = function() { 23 | var instantRate = this._count / this._tickInterval; 24 | this._count = 0; 25 | 26 | this._rate += (this._alpha * (instantRate - this._rate)); 27 | }; 28 | 29 | ExponentiallyWeightedMovingAverage.prototype.rate = function(timeUnit) { 30 | return (this._rate || 0) * timeUnit; 31 | }; 32 | -------------------------------------------------------------------------------- /test/fixtures/module-fixture/node_modules/pmx/node_modules/debug/node_modules/ms/README.md: -------------------------------------------------------------------------------- 1 | # ms.js: miliseconds conversion utility 2 | 3 | ```js 4 | ms('2 days') // 172800000 5 | ms('1d') // 86400000 6 | ms('10h') // 36000000 7 | ms('2.5 hrs') // 9000000 8 | ms('2h') // 7200000 9 | ms('1m') // 60000 10 | ms('5s') // 5000 11 | ms('100') // 100 12 | ``` 13 | 14 | ```js 15 | ms(60000) // "1m" 16 | ms(2 * 60000) // "2m" 17 | ms(ms('10 hours')) // "10h" 18 | ``` 19 | 20 | ```js 21 | ms(60000, { long: true }) // "1 minute" 22 | ms(2 * 60000, { long: true }) // "2 minutes" 23 | ms(ms('10 hours'), { long: true }) // "10 hours" 24 | ``` 25 | 26 | - Node/Browser compatible. Published as [`ms`](https://www.npmjs.org/package/ms) in [NPM](http://nodejs.org/download). 27 | - If a number is supplied to `ms`, a string with a unit is returned. 28 | - If a string that contains the number is supplied, it returns it as 29 | a number (e.g: it returns `100` for `'100'`). 30 | - If you pass a string with a number and a valid unit, the number of 31 | equivalent ms is returned. 32 | 33 | ## License 34 | 35 | MIT 36 | -------------------------------------------------------------------------------- /test/bash/homogen-json-action.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | SRC=$(cd $(dirname "$0"); pwd) 4 | source "${SRC}/include.sh" 5 | 6 | echo -e "\033[1mRunning tests:\033[0m" 7 | 8 | cd $file_path 9 | 10 | $pm2 kill 11 | 12 | cd homogen-json-action 13 | 14 | $pm2 start all.json 15 | should 'should start process' 'online' 6 16 | should 'should all script been restarted 0 time' 'restart_time: 0' 6 17 | 18 | $pm2 start all.json 19 | should 'should smart restart processes' 'online' 6 20 | should 'should all script been restarted one time' 'restart_time: 1' 6 21 | 22 | $pm2 restart all.json 23 | should 'should all script been restarted one time' 'restart_time: 2' 6 24 | 25 | $pm2 reload all.json 26 | should 'should all script been restarted one time' 'restart_time: 3' 6 27 | 28 | # With restart should equal a start 29 | $pm2 delete all 30 | 31 | $pm2 restart all.json 32 | should 'should start process' 'online' 6 33 | should 'should all script been restarted 0 time' 'restart_time: 0' 6 34 | 35 | # With reload should equal a start 36 | $pm2 delete all 37 | 38 | $pm2 reload all.json 39 | should 'should start process' 'online' 6 40 | should 'should all script been restarted 0 time' 'restart_time: 0' 6 41 | -------------------------------------------------------------------------------- /test/bash/signal.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | SRC=$(cd $(dirname "$0"); pwd) 4 | source "${SRC}/include.sh" 5 | 6 | cd $file_path 7 | 8 | echo -e "\033[1mRunning tests:\033[0m" 9 | 10 | # 11 | # Signal feature 12 | # 13 | $pm2 start signal.js -i 2 14 | # get the log file and the id. 15 | OUT_LOG=`$pm2 prettylist | grep -m 1 -E "pm_out_log_path:" | sed "s/.*'\([^']*\)',/\1/"` 16 | cat /dev/null > $OUT_LOG 17 | 18 | $pm2 sendSignal SIGUSR2 signal.js 19 | sleep 1 20 | 21 | OUT=`grep "SIGUSR2" "$OUT_LOG" | wc -l` 22 | [ $OUT -eq 1 ] || fail "Signal not received by the process name" 23 | success "Processes sucessfully receives the signal" 24 | 25 | $pm2 stop signal.js 26 | 27 | # Send a process by id 28 | $pm2 start signal.js 29 | 30 | sleep 1 31 | # get the log file and the id. 32 | OUT_LOG=`$pm2 prettylist | grep -m 1 -E "pm_out_log_path:" | sed "s/.*'\([^']*\)',/\1/"` 33 | ID=`$pm2 prettylist | grep -E "pm_id:" | sed "s/.*pm_id: \([^,]*\),/\1/"` 34 | 35 | cat /dev/null > $OUT_LOG 36 | 37 | $pm2 sendSignal SIGUSR2 $ID 38 | 39 | OUT=`grep "SIGUSR2" "$OUT_LOG" | wc -l` 40 | [ $OUT -eq 1 ] || fail "Signal not received by the process name" 41 | success "Processes sucessfully receives the signal" 42 | -------------------------------------------------------------------------------- /examples/keymetrics-integration/keymetrics-test.js: -------------------------------------------------------------------------------- 1 | 2 | var pm2 = require('../..'); 3 | 4 | pm2.connect(function() { 5 | console.log('Connected to PM2'); 6 | pm2.delete('all', function() { 7 | console.log('All processes deleted'); 8 | pm2.start('./pm2_probe.js', function(err) { 9 | if (err) console.error(err); 10 | pm2.start('./event.js', {force:true}, function() { 11 | pm2.start('./http_app.js', {force:true, instances:4},function() { 12 | pm2.start('./probes.js',function() { 13 | pm2.start('./custom_action.js', {force:true}, function() { 14 | pm2.start('./custom_action_with_params.js', {force:true, name : 'custom'} , function() { 15 | pm2.start('./http_transaction.js', {name:'trace', force:true}, function() { 16 | pm2.start('./throw.js', {name:'auto-throw', execMode : 'cluster_mode', force:true}, function() { 17 | console.log('All applications have been started'); 18 | pm2.disconnect(function() { }); 19 | }); 20 | }); 21 | }); 22 | }); 23 | }); 24 | }); 25 | }); 26 | }); 27 | }); 28 | }); 29 | -------------------------------------------------------------------------------- /test/bash/binary.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | SRC=$(cd $(dirname "$0"); pwd) 4 | source "${SRC}/include.sh" 5 | 6 | echo -e "\033[1mRunning tests:\033[0m" 7 | 8 | cd $file_path 9 | 10 | function getInterpreter() { 11 | echo `$pm2 prettylist | grep "exec_interpreter:" | awk -F"'" '{print $2}'` 12 | } 13 | 14 | # 15 | # Testing pm2 execution of binary files 16 | # 17 | $pm2 start `type -p watch` -- ls 18 | 19 | OUT=$(getInterpreter) 20 | 21 | [ $OUT = "none" ] || fail "$1" 22 | success "$1" 23 | 24 | $pm2 kill 25 | $pm2 start binary-js-file 26 | 27 | OUT=$(getInterpreter) 28 | echo $OUT 29 | 30 | [ $OUT="node" ] || fail "$1" 31 | success "$1" 32 | 33 | $pm2 kill 34 | $pm2 start binary-js-file.js 35 | 36 | OUT=$(getInterpreter) 37 | [ $OUT="node" ] || fail "$1" 38 | success "$1" 39 | 40 | $pm2 kill 41 | $pm2 start binary-py-file.py 42 | 43 | OUT=$(getInterpreter) 44 | [ $OUT="python" ] || fail "$1" 45 | success "$1" 46 | 47 | $pm2 kill 48 | 49 | # 50 | # Should execute command in $PATH 51 | # 52 | $pm2 start ls 53 | spec "Should script started" 54 | 55 | OUT=$(getInterpreter) 56 | [ $OUT="none" ] || fail "$1" 57 | success "Right interpreter" 58 | 59 | should 'Have the right relative path' '/bin/ls' 1 60 | -------------------------------------------------------------------------------- /test/bash/file-descriptor.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # 4 | # LSOF check 5 | # 6 | 7 | SRC=$(cd $(dirname "$0"); pwd) 8 | source "${SRC}/include.sh" 9 | 10 | cd $file_path 11 | 12 | echo "################## RELOAD ###################" 13 | 14 | lsof -c PM2 > /tmp/no_pm2_out.dat 15 | 16 | $pm2 list 17 | 18 | sleep 3 19 | lsof -c PM2 > /tmp/empty_pm2_out.dat 20 | 21 | $pm2 start echo.js -i 3 22 | $pm2 start killtoofast.js -i 3 23 | $pm2 delete all 24 | 25 | sleep 3 26 | lsof -c PM2 > /tmp/empty_pm2_out2.dat 27 | 28 | OUT1=`cat /tmp/empty_pm2_out.dat | wc -l` 29 | OUT2=`cat /tmp/empty_pm2_out2.dat | wc -l` 30 | 31 | if [ $OUT1 -eq $OUT2 ]; then 32 | success "All file descriptors have been closed" 33 | else 34 | fail "Some file descriptors are still open" 35 | fi 36 | 37 | $pm2 start killtoofast.js -i 6 38 | $pm2 kill 39 | 40 | sleep 3 41 | lsof -c PM2 > /tmp/no_pm2_out2.dat 42 | diff /tmp/no_pm2_out.dat /tmp/no_pm2_out2.dat 43 | 44 | if [ $? == "0" ]; then 45 | success "All file descriptors have been closed" 46 | else 47 | fail "Some file descriptors are still open" 48 | fi 49 | 50 | rm /tmp/no_pm2_out.dat 51 | rm /tmp/no_pm2_out2.dat 52 | rm /tmp/empty_pm2_out.dat 53 | rm /tmp/empty_pm2_out2.dat 54 | -------------------------------------------------------------------------------- /lib/keymetrics: -------------------------------------------------------------------------------- 1 | 2 | ------------- 3 | 4 | PM2 process manager 5 | 6 | __/\\\\\\\\\\\\\____/\\\\____________/\\\\____/\\\\\\\\\_____ 7 | _\/\\\/////////\\\_\/\\\\\\________/\\\\\\__/\\\///////\\\___ 8 | _\/\\\_______\/\\\_\/\\\//\\\____/\\\//\\\_\///______\//\\\__ 9 | _\/\\\\\\\\\\\\\/__\/\\\\///\\\/\\\/_\/\\\___________/\\\/___ 10 | _\/\\\/////////____\/\\\__\///\\\/___\/\\\________/\\\//_____ 11 | _\/\\\_____________\/\\\____\///_____\/\\\_____/\\\//________ 12 | _\/\\\_____________\/\\\_____________\/\\\___/\\\/___________ 13 | _\/\\\_____________\/\\\_____________\/\\\__/\\\\\\\\\\\\\\\_ 14 | _\///______________\///______________\///__\///////////////__ 15 | 16 | 17 | Getting started 18 | 19 | Documentation 20 | http://pm2.io/ 21 | 22 | Start PM2 at boot 23 | $ pm2 startup 24 | 25 | Daemonize Application 26 | $ pm2 start 27 | 28 | Monitoring/APM solution 29 | https://app.keymetrics.io/ 30 | 31 | ------------- 32 | -------------------------------------------------------------------------------- /test/bash/log-reload.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | SRC=$(cd $(dirname "$0"); pwd) 4 | source "${SRC}/include.sh" 5 | 6 | cd $file_path 7 | 8 | echo -e "\033[1mRunning tests:\033[0m" 9 | 10 | >out-rel.log 11 | 12 | $pm2 start echo.js -o out-rel.log --merge-logs -i 1 13 | 14 | $pm2 reloadLogs 15 | 16 | sleep 1 17 | 18 | grep "Reloading log..." out-rel.log 19 | 20 | spec "Should have started the reloading action" 21 | 22 | rm out-rel.log 23 | 24 | ## FORK MODE 25 | 26 | $pm2 kill 27 | 28 | $pm2 start echo.js -o out-rel.log -e err-rel.log -x --merge-logs 29 | 30 | sleep 2 31 | 32 | grep "echo.js" out-rel.log 33 | spec "Should have written te right stuff in out log in fork mode" 34 | 35 | grep "echo.js-error" err-rel.log 36 | spec "Should have written te right stuff in err log in fork mode" 37 | 38 | rm out-rel.log 39 | rm err-rel.log 40 | 41 | $pm2 reloadLogs 42 | spec "Should have reloaded logs via CLI" 43 | 44 | sleep 1 45 | 46 | grep "echo.js" out-rel.log 47 | spec "(RELOADED) Should have written the right stuff in out log in fork mode" 48 | 49 | grep "echo.js-error" err-rel.log 50 | spec "(RELOADED) Should have written the right stuff in err log in fork mode" 51 | 52 | rm out-rel.log 53 | rm err-rel.log 54 | -------------------------------------------------------------------------------- /examples/pmx/elements/trace.js: -------------------------------------------------------------------------------- 1 | 2 | var http = require('http'); 3 | 4 | http.createServer(function(req, res) { 5 | res.writeHead(200); 6 | setTimeout(function() { 7 | res.end('transaction'); 8 | }, 10); 9 | }).listen(9016); 10 | 11 | setInterval(function() { 12 | request(['/user', '/bla', '/user/lol/delete', '/POST/POST'][Math.floor((Math.random() * 4))]); 13 | }, 140); 14 | 15 | function makeid() 16 | { 17 | var text = ""; 18 | var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; 19 | 20 | for( var i=0; i < 5; i++ ) 21 | text += possible.charAt(Math.floor(Math.random() * possible.length)); 22 | 23 | return text; 24 | } 25 | 26 | function request(path) { 27 | var options = { 28 | hostname: '127.0.0.1' 29 | ,port: 9016 30 | ,path: path || '/users' 31 | ,method: 'GET' 32 | ,headers: { 'Content-Type': 'application/json' } 33 | }; 34 | 35 | var req = http.request(options, function(res) { 36 | res.setEncoding('utf8'); 37 | res.on('data', function (data) { 38 | //console.log(data); 39 | }); 40 | }); 41 | req.on('error', function(e) { 42 | console.log('problem with request: ' + e.message); 43 | }); 44 | req.end(); 45 | 46 | } 47 | -------------------------------------------------------------------------------- /test/bash/reset.sh: -------------------------------------------------------------------------------- 1 | 2 | #!/usr/bin/env bash 3 | 4 | SRC=$(cd $(dirname "$0"); pwd) 5 | source "${SRC}/include.sh" 6 | 7 | cd $file_path 8 | 9 | echo "################## RESET ###################" 10 | 11 | # 12 | # BY ID 13 | # 14 | $pm2 start echo.js 15 | should 'should restarted be one for all' 'restart_time: 0' 1 16 | 17 | $pm2 restart 0 18 | should 'should process restarted' 'restart_time: 1' 1 19 | 20 | $pm2 reset 0 21 | should 'should process reseted' 'restart_time: 0' 1 22 | 23 | # 24 | # BY NAME 25 | # 26 | $pm2 start echo.js -i 4 -f 27 | should 'should restarted be one for all' 'restart_time: 0' 5 28 | 29 | $pm2 restart echo 30 | should 'should process restarted' 'restart_time: 1' 5 31 | 32 | $pm2 reset echo 33 | should 'should process reseted' 'restart_time: 0' 5 34 | 35 | 36 | # 37 | # ALL 38 | # 39 | $pm2 restart all 40 | $pm2 restart all 41 | $pm2 restart all 42 | should 'should process restarted' 'restart_time: 3' 5 43 | 44 | $pm2 reset all 45 | should 'should process reseted' 'restart_time: 0' 5 46 | 47 | # 48 | # Restart delay test 49 | # 50 | 51 | $pm2 delete all 52 | $pm2 start killtoofast.js --restart-delay 5000 53 | should 'should process not have been restarted yet' 'restart_time: 0' 1 54 | 55 | $pm2 kill 56 | -------------------------------------------------------------------------------- /examples/pmx/elements/cluster.js: -------------------------------------------------------------------------------- 1 | 2 | var http = require('http'); 3 | 4 | http.createServer(function(req, res) { 5 | res.writeHead(200); 6 | setTimeout(function() { 7 | res.end('transaction'); 8 | }, 10); 9 | }).listen(process.env.PORT || 9010); 10 | 11 | setInterval(function() { 12 | request(['/user', '/bla', '/user/lol/delete', '/POST/POST'][Math.floor((Math.random() * 4))]); 13 | }, 140); 14 | 15 | function makeid() 16 | { 17 | var text = ""; 18 | var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; 19 | 20 | for( var i=0; i < 5; i++ ) 21 | text += possible.charAt(Math.floor(Math.random() * possible.length)); 22 | 23 | return text; 24 | } 25 | 26 | function request(path) { 27 | var options = { 28 | hostname: '127.0.0.1' 29 | ,port: 9010 30 | ,path: path || '/users' 31 | ,method: 'GET' 32 | ,headers: { 'Content-Type': 'application/json' } 33 | }; 34 | 35 | var req = http.request(options, function(res) { 36 | res.setEncoding('utf8'); 37 | res.on('data', function (data) { 38 | //console.log(data); 39 | }); 40 | }); 41 | req.on('error', function(e) { 42 | console.log('problem with request: ' + e.message); 43 | }); 44 | req.end(); 45 | 46 | } 47 | -------------------------------------------------------------------------------- /examples/pmx/elements/http.js: -------------------------------------------------------------------------------- 1 | 2 | var http = require('http'); 3 | 4 | http.createServer(function(req, res) { 5 | res.writeHead(200); 6 | setTimeout(function() { 7 | res.end('transaction'); 8 | }, 10); 9 | }).listen(process.env.PORT || 9010); 10 | 11 | setInterval(function() { 12 | request(['/user', '/bla', '/user/lol/delete', '/POST/POST'][Math.floor((Math.random() * 4))]); 13 | }, 140); 14 | 15 | function makeid() 16 | { 17 | var text = ""; 18 | var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; 19 | 20 | for( var i=0; i < 5; i++ ) 21 | text += possible.charAt(Math.floor(Math.random() * possible.length)); 22 | 23 | return text; 24 | } 25 | 26 | function request(path) { 27 | var options = { 28 | hostname: '127.0.0.1' 29 | ,port: 9010 30 | ,path: path || '/users' 31 | ,method: 'GET' 32 | ,headers: { 'Content-Type': 'application/json' } 33 | }; 34 | 35 | var req = http.request(options, function(res) { 36 | res.setEncoding('utf8'); 37 | res.on('data', function (data) { 38 | //console.log(data); 39 | }); 40 | }); 41 | req.on('error', function(e) { 42 | console.log('problem with request: ' + e.message); 43 | }); 44 | req.end(); 45 | 46 | } 47 | -------------------------------------------------------------------------------- /test/README.md: -------------------------------------------------------------------------------- 1 | 2 | # Installing development version 3 | 4 | ```bash 5 | $ npm install git://github.com/Unitech/pm2.git#development -g 6 | ``` 7 | 8 | # Redhat 9 | 10 | ``` 11 | $ sudo yum install git wget emacs 12 | $ sudo yum groupinstall "Development Tools" 13 | $ wget -qO- https://raw.github.com/creationix/nvm/master/install.sh | sh 14 | $ # put .bash_profile content to .bashrc 15 | $ source .bashrc 16 | $ nvm install v0.11.10 17 | $ nvm alias default 0.11.10 18 | $ npm install pm2 -g 19 | $ # OR 20 | $ npm install git://github.com/Unitech/pm2.git#development -g 21 | ``` 22 | 23 | # CentOS 24 | 25 | ``` 26 | $ yum install git wget emacs 27 | $ wget -qO- https://raw.github.com/creationix/nvm/master/install.sh | sh 28 | $ 29 | ``` 30 | 31 | ## Remove init script 32 | 33 | sudo update-rc.d -f pm2-init.sh remove 34 | ``` 35 | $ chkconfig --del pm2-init.sh 36 | $ chkconfig --add pm2-init.sh 37 | ``` 38 | 39 | gyp WARN EACCES user "root" does not have permission to create dev dir : 40 | https://github.com/TooTallNate/node-gyp/issues/126 41 | -> add --unsafe-perm 42 | 43 | # .pm2 44 | 45 | Doesnt work 46 | 47 | ``` 48 | $ sudo sh -c 'echo "export PM2_HOME=/var/" >> /etc/profile' 49 | $ sudo mkdir /var/.pm2; chown -R tknew:tknew /var/.pm2 50 | ``` 51 | -------------------------------------------------------------------------------- /test/fixtures/module-fixture/node_modules/pmx/node_modules/debug/node_modules/ms/LICENSE: -------------------------------------------------------------------------------- 1 | (The MIT License) 2 | 3 | Copyright (c) 2014 Guillermo Rauch 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /examples/keymetrics-integration/actions-fibonacci.js: -------------------------------------------------------------------------------- 1 | 2 | var stop = false; 3 | 4 | /** 5 | * Description 6 | * @method add 7 | * @param {} a 8 | * @param {} b 9 | * @return sum 10 | */ 11 | function add(a, b) { 12 | while (a.length < b.length) a.unshift(0); 13 | while (a.length > b.length) b.unshift(0); 14 | var carry = 0, sum = [] 15 | for (var i = a.length - 1; i >= 0; i--) { 16 | var s = a[i] + b[i] + carry; 17 | if (s >= 10) { 18 | s = s - 10; 19 | carry = 1; 20 | } else { 21 | carry = 0; 22 | } 23 | sum.unshift(s); 24 | } 25 | if (carry) 26 | sum.unshift(carry); 27 | return sum; 28 | } 29 | 30 | /** 31 | * Description 32 | * @method fib 33 | * @param {} n 34 | * @return CallExpression 35 | */ 36 | function fib(n) { 37 | var f1 = [0]; 38 | var f2 = [1]; 39 | 40 | while (n--) { 41 | var f3 = add(f1, f2) 42 | if (stop) return false; 43 | f1 = f2; 44 | f2 = f3; 45 | } 46 | return f1.join(""); 47 | } 48 | 49 | 50 | var axm = require('pmx'); 51 | 52 | axm.action('load:start', function(reply) { 53 | fib(50000); 54 | reply({success : true}); 55 | }); 56 | 57 | 58 | axm.action('load:stop', function(reply) { 59 | stop = true; 60 | reply({success : true}); 61 | }); 62 | --------------------------------------------------------------------------------