├── .editorconfig ├── .gitattributes ├── .github ├── CONTRIBUTING.md ├── ISSUE_TEMPLATE.md ├── PULL_REQUEST_TEMPLATE.md └── stale.yml ├── .gitignore ├── .mocharc.js ├── .npmignore ├── .travis.yml ├── CHANGELOG.md ├── CONTRIBUTING.md ├── GNU-AGPL-3.0.txt ├── LICENSE ├── README.md ├── bin ├── pm2 ├── pm2-dev ├── pm2-docker └── pm2-runtime ├── constants.js ├── examples ├── api-pm2 │ ├── README.md │ ├── api.js │ └── http.js ├── c-compile │ └── hello.c ├── cluster-http │ ├── README.md │ ├── ecosystem.config.js │ ├── http-no-exit.js │ └── http.js ├── cluster-tcp │ ├── README.md │ ├── http.js │ ├── process.config.js │ └── tcp.js ├── custom-nodejs-version │ ├── ecosystem.config.js │ └── http.js ├── docker-pm2 │ ├── Dockerfile │ ├── README.md │ └── app │ │ ├── app.js │ │ ├── package.json │ │ └── process.config.js ├── echo │ ├── log.js │ └── stdout.js ├── ecosystem-file │ ├── README.md │ ├── apps │ │ ├── connection_check.sh │ │ ├── http.js │ │ └── worker.js │ ├── process.config.js │ ├── process.json │ └── process.yml ├── esm │ ├── addTwo.js │ ├── app.js │ └── package.json ├── exception │ ├── fast.js │ └── slow.js ├── expose-custom-metrics │ ├── README.md │ ├── process-metrics.js │ └── process.config.js ├── expose-triggerable-functions │ ├── index.js │ ├── process.yml │ ├── trigger-param.js │ └── trigger-ping.js ├── import │ ├── circle.js │ ├── index.js │ └── package.json ├── interact-via-stdin │ ├── README.md │ └── stdin.js ├── misc-examples │ ├── 001-test.js │ ├── apps │ │ ├── all-pm2.json │ │ ├── args.json │ │ ├── auto-kill-echo.json │ │ ├── cluster-pm2.json │ │ ├── cron-pm2.json │ │ ├── default-path-echo.json │ │ ├── echo-pm2.json │ │ ├── env-pm2.json │ │ ├── killfast.json │ │ ├── multi-pm2.json │ │ └── no-name-echo.json │ ├── args.js │ ├── auto-restart-all.js │ ├── auto-restart-threshold.js │ ├── auto-save.js │ ├── beforeExit.js │ ├── child-echo.json │ ├── child-env.js │ ├── child-pm2.json │ ├── child.js │ ├── child.js-pm2.json │ ├── child2.js │ ├── client.js │ ├── cwd.js │ ├── echo.coffee │ ├── echo.js │ ├── echokill.js │ ├── env.js │ ├── env_args.js │ ├── exec_watch.json │ ├── exit.js │ ├── expose_method.js │ ├── graceful-exit.js │ ├── harmony.js │ ├── http.js │ ├── infinite-recurse.js │ ├── inside.js │ ├── inside.json │ ├── interact.js │ ├── json.js │ ├── kill-not-so-fast.js │ ├── kill-slow.js │ ├── killfast.js │ ├── killslow.js │ ├── killtoofast.js │ ├── leak.js │ ├── malformated.json │ ├── modulechild.js │ ├── moduleparent.js │ ├── null.js │ ├── package.json │ ├── process.json │ ├── programmatic.js │ ├── require.js │ ├── sendmsg.js │ ├── sigint.js │ ├── start-args.js │ ├── stop-after5.js │ ├── string-crash.js │ ├── throw.js │ ├── tree.js │ ├── udp.js │ └── wrap.js ├── module-extra-meta │ ├── index.js │ └── package.json ├── module-test │ ├── README.md │ ├── app.js │ └── package.json ├── npm-start │ ├── http.js │ └── package.json ├── pmx-test-all │ ├── elements │ │ ├── cluster.js │ │ ├── counter.js │ │ ├── error.js │ │ ├── event.js │ │ ├── histogram.js │ │ ├── http.js │ │ ├── log-cluster.js │ │ ├── log.js │ │ ├── meter.js │ │ ├── metric.js │ │ ├── notify.js │ │ └── trace.js │ └── process.config.js ├── run-php-python-ruby-bash │ ├── bashscript.sh │ ├── echo.php │ ├── echo.py │ ├── echo.rb │ └── process.yml ├── send-msg │ ├── pm2-app.js │ ├── pm2-msg.js │ └── t2.js ├── signal-catching │ └── graceful-http.js ├── sourcemap-auto-resolve │ ├── API.js │ ├── API.min.js │ ├── API.min.js.map │ ├── README.md │ └── process.config.js ├── start-a-binary │ ├── ls │ └── ls.yml ├── test-all-keymetrics-features │ ├── README.md │ ├── actions-fibonacci.js │ ├── custom_action.js │ ├── custom_action_with_params.js │ ├── event.js │ ├── http_app.js │ ├── http_transaction.js │ ├── pm2_probe.js │ ├── probes.js │ ├── process-load.config.js │ ├── process-transpose.js │ ├── process.config.js │ ├── scoped-actions.js │ ├── test-threshold.js │ └── throw.js ├── treekill │ ├── app.js │ └── process.json ├── udp │ ├── client.js │ └── server.js ├── using-pm2-and-transpilers │ ├── README.md │ ├── echo.coffee │ ├── echo.ls │ ├── echo.ts │ ├── http.ts │ └── node.d.ts └── wait-ready │ ├── app.js │ ├── ecosystem.json │ └── http-simple.js ├── index.js ├── lib ├── API.js ├── API │ ├── Configuration.js │ ├── Containerizer.js │ ├── Dashboard.js │ ├── Deploy.js │ ├── Extra.js │ ├── ExtraMgmt │ │ └── Docker.js │ ├── Log.js │ ├── LogManagement.js │ ├── Modules │ │ ├── LOCAL.js │ │ ├── Modularizer.js │ │ ├── NPM.js │ │ ├── TAR.js │ │ ├── flagExt.js │ │ └── index.js │ ├── Monit.js │ ├── Serve.js │ ├── Startup.js │ ├── UX │ │ ├── helpers.js │ │ ├── index.js │ │ ├── pm2-describe.js │ │ ├── pm2-ls-minimal.js │ │ └── pm2-ls.js │ ├── Version.js │ ├── interpreter.json │ ├── pm2-plus │ │ ├── PM2IO.js │ │ ├── auth-strategies │ │ │ ├── CliAuth.js │ │ │ └── WebAuth.js │ │ ├── helpers.js │ │ ├── link.js │ │ ├── pres │ │ │ ├── motd │ │ │ ├── motd.update │ │ │ └── welcome │ │ └── process-selector.js │ └── schema.json ├── Client.js ├── Common.js ├── Configuration.js ├── Daemon.js ├── Event.js ├── God.js ├── God │ ├── ActionMethods.js │ ├── ClusterMode.js │ ├── ForkMode.js │ ├── Methods.js │ └── Reload.js ├── HttpInterface.js ├── ProcessContainer.js ├── ProcessContainerFork.js ├── ProcessUtils.js ├── TreeKill.js ├── Utility.js ├── VersionCheck.js ├── Watcher.js ├── Worker.js ├── binaries │ ├── CLI.js │ ├── DevCLI.js │ ├── Runtime.js │ └── Runtime4Docker.js ├── completion.js ├── completion.sh ├── motd ├── templates │ ├── Dockerfiles │ │ ├── Dockerfile-java.tpl │ │ ├── Dockerfile-nodejs.tpl │ │ └── Dockerfile-ruby.tpl │ ├── ecosystem-simple.tpl │ ├── ecosystem.tpl │ ├── init-scripts │ │ ├── launchd.tpl │ │ ├── openrc.tpl │ │ ├── pm2-init-amazon.sh │ │ ├── rcd-openbsd.tpl │ │ ├── rcd.tpl │ │ ├── smf.tpl │ │ ├── systemd-online.tpl │ │ ├── systemd.tpl │ │ └── upstart.tpl │ ├── logrotate.d │ │ └── pm2 │ └── sample-apps │ │ ├── http-server │ │ ├── README.md │ │ ├── api.js │ │ ├── ecosystem.config.js │ │ └── package.json │ │ ├── pm2-plus-metrics-actions │ │ ├── README.md │ │ ├── custom-metrics.js │ │ ├── ecosystem.config.js │ │ └── package.json │ │ └── python-app │ │ ├── README.md │ │ ├── echo.py │ │ ├── ecosystem.config.js │ │ └── package.json └── tools │ ├── Config.js │ ├── IsAbsolute.js │ ├── copydirSync.js │ ├── deleteFolderRecursive.js │ ├── find-package-json.js │ ├── fmt.js │ ├── isbinaryfile.js │ ├── json5.js │ ├── open.js │ ├── passwd.js │ ├── promise.min.js │ ├── sexec.js │ ├── treeify.js │ ├── which.js │ └── xdg-open ├── package.json ├── packager ├── alpine │ ├── pm2 │ │ └── APKBUILD │ └── pm2_io.rsa.pub ├── build-deb-rpm.sh ├── build-dist.sh ├── debian │ ├── control │ ├── copyright │ ├── description │ ├── lintian-overrides │ ├── postinst │ ├── postrm │ └── prerm ├── publish_deb_rpm.sh ├── rhel │ ├── postinst │ ├── postrm │ └── prerm ├── setup.deb.sh └── setup.rpm.sh ├── paths.js ├── pm2 ├── pres ├── TMP.md ├── bttn.png ├── cluster-support.png ├── cluster.png ├── legacy-logo.png ├── pm2-dev.png ├── pm2-list.png ├── pm2-ls-multi.png ├── pm2-ls-v2.png ├── pm2-monit.png ├── pm2-plus_black.png ├── pm2-v2.png ├── pm2-v3.png ├── pm2-v4.png ├── pm2-versioning-metadata.png ├── pm2.20d3ef.png ├── schema.png └── vitals.png ├── test ├── Dockerfile ├── README.md ├── benchmarks │ ├── monit-daemon.sh │ ├── monit.sh │ └── result.monit ├── docker_parallel_test.sh ├── e2e.sh ├── e2e │ ├── binaries │ │ ├── pm2-dev.sh │ │ └── pm2-runtime.sh │ ├── cli │ │ ├── app-configuration.sh │ │ ├── args.sh │ │ ├── attach.sh │ │ ├── binary.sh │ │ ├── cli-actions-1.sh │ │ ├── cli-actions-2.sh │ │ ├── dump.sh │ │ ├── ecosystem.e2e.sh │ │ ├── env-refresh.sh │ │ ├── extra-lang.sh │ │ ├── fork.sh │ │ ├── interpreter.sh │ │ ├── mjs.sh │ │ ├── monit.sh │ │ ├── multiparam.sh │ │ ├── operate-regex.sh │ │ ├── piped-config.sh │ │ ├── plus.sh │ │ ├── python-support.sh │ │ ├── reload.sh │ │ ├── reset.sh │ │ ├── resurrect.sh │ │ ├── right-exit-code.sh │ │ ├── serve.sh │ │ ├── smart-start.sh │ │ ├── sort.sh │ │ ├── start-app.sh │ │ ├── startOrX.sh │ │ └── watch.sh │ ├── docker.sh │ ├── esmodule.sh │ ├── file-descriptor.sh │ ├── include.sh │ ├── internals │ │ ├── daemon-paths-override.sh │ │ ├── increment-var.sh │ │ ├── infinite-loop.sh │ │ ├── listen-timeout.sh │ │ ├── options-via-env.sh │ │ ├── promise.sh │ │ ├── signal.sh │ │ ├── source_map.sh │ │ ├── start-consistency.sh │ │ ├── wait-ready-event.sh │ │ └── wrapped-fork.sh │ ├── logs │ │ ├── log-create-not-exist-dir.sh │ │ ├── log-custom.sh │ │ ├── log-entire.sh │ │ ├── log-json.sh │ │ ├── log-null.sh │ │ ├── log-reload.sh │ │ └── log-timestamp.sh │ ├── misc │ │ ├── cron-system.sh │ │ ├── inside-pm2.sh │ │ ├── instance-number.sh │ │ ├── misc.sh │ │ ├── nvm-node-version.sh │ │ ├── port-release.sh │ │ ├── startup.sh │ │ ├── versioning-cmd.sh │ │ └── vizion.sh │ ├── modules │ │ ├── get-set.sh │ │ ├── module-safeguard.sh │ │ └── module.sh │ ├── process-file │ │ ├── app-config-update.sh │ │ ├── append-env-to-name.sh │ │ ├── homogen-json-action.sh │ │ ├── js-configuration.sh │ │ ├── json-file.sh │ │ ├── json-reload.sh │ │ └── yaml-configuration.sh │ └── pull.sh ├── fixtures │ ├── 001-test.js │ ├── all.json │ ├── all2.json │ ├── app-config-update │ │ ├── args1.json │ │ ├── args2.json │ │ └── echo.js │ ├── append-env-to-name.json │ ├── args.js │ ├── args │ │ ├── echo.js │ │ └── params_check.js │ ├── bashscript.sh │ ├── big-array-es6.js │ ├── big-array-listen.js │ ├── big-array.js │ ├── binary-js-file │ ├── binary-js-file.js │ ├── binary-py-file.py │ ├── c-compile │ │ └── hello.c │ ├── change_cwd.json │ ├── child.js │ ├── child_no_http.js │ ├── cluster-alias.json │ ├── cluster-pm2.json │ ├── cluster │ │ └── sigint_catcher.js │ ├── conf.json │ ├── configuration.js │ ├── configuration.json │ ├── containerizer │ │ ├── Dockerfile.dev │ │ └── Dockerfile.prod │ ├── cron-stop.js │ ├── cron.js │ ├── cron_no_autorestart.js │ ├── custom_actions │ │ └── index.js │ ├── delayed_exit.js │ ├── docker │ │ └── expressor │ │ │ ├── Dockerfile.bak │ │ │ ├── app.js │ │ │ ├── package.json │ │ │ ├── process.json │ │ │ └── worker.js │ ├── echo-env.js │ ├── echo-pm2.json │ ├── echo-post.json │ ├── echo-to-pm2.json │ ├── echo.coffee │ ├── echo.js │ ├── echo2.js │ ├── echo3.js │ ├── echoto-pm2.json │ ├── ecosystem.config.js │ ├── ecosystem.json │ ├── ecosystem.json5 │ ├── ecosystem │ │ └── ecosystem.config.js │ ├── empty.js │ ├── env-ecosystem.json │ ├── env-refreshed.json │ ├── env-switching │ │ ├── app.json │ │ └── child.js │ ├── env.js │ ├── env.json │ ├── esmodules │ │ ├── mjs │ │ │ ├── circle.mjs │ │ │ └── index.mjs │ │ └── packagemodule │ │ │ ├── circle.js │ │ │ ├── index.js │ │ │ └── package.json │ ├── events │ │ ├── custom_action.js │ │ ├── custom_action_with_params.js │ │ └── own_event.js │ ├── extra-lang │ │ ├── app-python.config.js │ │ ├── apps.json │ │ ├── echo.php │ │ └── echo.py │ ├── git │ │ ├── COMMIT_EDITMSG │ │ ├── HEAD │ │ ├── config │ │ ├── description │ │ ├── hooks │ │ │ ├── applypatch-msg.sample │ │ │ ├── commit-msg.sample │ │ │ ├── post-update.sample │ │ │ ├── pre-applypatch.sample │ │ │ ├── pre-commit.sample │ │ │ ├── pre-push.sample │ │ │ ├── pre-rebase.sample │ │ │ ├── prepare-commit-msg.sample │ │ │ └── update.sample │ │ ├── index │ │ ├── info │ │ │ └── exclude │ │ ├── logs │ │ │ ├── HEAD │ │ │ └── refs │ │ │ │ ├── heads │ │ │ │ └── master │ │ │ │ └── remotes │ │ │ │ └── origin │ │ │ │ └── master │ │ ├── objects │ │ │ ├── 5d │ │ │ │ └── a45b6659e5cba8f444616f4e18529ad5dde72f │ │ │ ├── 7a │ │ │ │ └── e6d7c64d39da2167c33993e1f4f0233e8eb6f0 │ │ │ └── e6 │ │ │ │ └── 9de29bb2d1d6434b8b29ae775ad8c2e48c5391 │ │ └── refs │ │ │ ├── heads │ │ │ └── master │ │ │ └── remotes │ │ │ └── origin │ │ │ └── master │ ├── graceful-exit-no-listen.js │ ├── graceful-exit-send.js │ ├── graceful-exit.js │ ├── homogen-json-action │ │ ├── all.json │ │ └── http.js │ ├── http.js │ ├── increment-var │ │ ├── ecosystem.json │ │ └── sample.js │ ├── inside │ │ ├── echo.js │ │ ├── inner_restart.sh │ │ ├── reload_inside.js │ │ ├── restart_inside.js │ │ └── start_inside.js │ ├── insidePm2Process.js │ ├── interface │ │ ├── child.js │ │ ├── http_transaction.js │ │ ├── human_event.js │ │ ├── log_out.js │ │ ├── process_exception.js │ │ ├── process_exception_with_logs.js │ │ └── promise_rejection.js │ ├── interpreter │ │ ├── echo.coffee │ │ ├── echo.ls │ │ └── echo.ts │ ├── js-configuration │ │ ├── app.js │ │ └── ecosystem.config.js │ ├── json-reload │ │ ├── big-array.js │ │ ├── echo-env.js │ │ ├── echo-post.json │ │ ├── echo-pre.json │ │ ├── max-mem-0.json │ │ └── max-mem.json │ ├── killnotsofast.js │ ├── killtoofast.js │ ├── listen-timeout │ │ └── wait-ready.js │ ├── local_require.js │ ├── log-create-not-exist-dir │ │ └── echo.js │ ├── log-json │ │ ├── ecosystem.json │ │ └── one-echo.js │ ├── mjs │ │ ├── ecosystem.config.js │ │ ├── index.mjs │ │ ├── package.json │ │ └── test.mjs │ ├── module-fixture │ │ ├── package.json │ │ └── scoped-action.js │ ├── multi-echo.json │ ├── network.js │ ├── no-restart.json │ ├── no-vizion.json │ ├── no_cwd_change.json │ ├── nvm-node-version │ │ ├── ecosystem-change.json │ │ ├── ecosystem.json │ │ └── http.js │ ├── path-check.js │ ├── path-resolution │ │ ├── echo.js │ │ ├── ecosystem.config.js │ │ ├── ecosystem2.config.js │ │ └── ecosystem3.config.js │ ├── path1 │ │ ├── iminpath1.js │ │ └── path2 │ │ │ └── iminpath2.js │ ├── pm2-dev │ │ ├── app.js │ │ ├── app.json │ │ └── exited_app.js │ ├── pm2-ecosystem.json │ ├── probes.js │ ├── process.json │ ├── promise │ │ ├── empty-rejection.js │ │ └── rejection.js │ ├── push.json │ ├── python-script.py │ ├── quit.js │ ├── send-data-process │ │ └── return-data.js │ ├── serve │ │ ├── 404.html │ │ ├── ecosystem-serve.json │ │ ├── ecosystem.json │ │ ├── index.html │ │ └── other.html │ ├── server.js │ ├── signal-send.js │ ├── signal.js │ ├── signals │ │ ├── delayed_send.js │ │ └── delayed_sigint.js │ ├── sort │ │ ├── http.js │ │ └── other.js │ ├── source-map │ │ ├── main.js │ │ ├── main.js.map │ │ ├── models.js │ │ └── models.js.map │ ├── start-app │ │ ├── ecosystem.config.js │ │ └── http.js │ ├── start-consistency │ │ ├── child.js │ │ └── child.json │ ├── startProcessInsidePm2.js │ ├── startProcessInsidePm2.json │ ├── stdin │ │ └── stdin.js │ ├── stdout-stderr.js │ ├── throw-later.js │ ├── throw-later.json │ ├── throw-later1.json │ ├── throw-string.js │ ├── throw.js │ ├── toto.js │ ├── wait_ready_event │ │ ├── http-wait-start.js │ │ └── http-wait-start_nocb.js │ ├── watch │ │ ├── app-watch-rename.json │ │ ├── app-watch.json │ │ ├── app.json │ │ └── http.js │ ├── watcher │ │ ├── donotwatchme.dir │ │ │ └── .gitkeep │ │ ├── server-watch.bak.js │ │ ├── server-watch.json │ │ └── watchme.sym │ └── yaml-configuration │ │ ├── apps.yaml │ │ ├── apps.yml │ │ ├── child.js │ │ ├── echo.js │ │ ├── echo.py │ │ └── malformated.yml ├── helpers │ ├── apps.js │ └── plan.js ├── interface │ ├── README.md │ ├── bus.fork.spec.mocha.js │ ├── bus.spec.mocha.js │ ├── mocha.opts │ └── utility.mocha.js ├── parallel.js ├── pm2_check_dependencies.sh ├── programmatic │ ├── api.backward.compatibility.mocha.js │ ├── api.mocha.js │ ├── auto_restart.mocha.js │ ├── client.mocha.js │ ├── cluster.mocha.js │ ├── conf_update.mocha.js │ ├── configuration.mocha.js │ ├── containerizer.mocha.js │ ├── custom_action.mocha.js │ ├── dump.mocha.js │ ├── env_switching.js │ ├── exp_backoff_restart_delay.mocha.js │ ├── filter_env.mocha.js │ ├── fixtures │ │ ├── auto-restart │ │ │ └── throw.js │ │ ├── exp-backoff │ │ │ ├── throw-stable.js │ │ │ └── throw.js │ │ ├── instances │ │ │ ├── echo.js │ │ │ └── http.js │ │ ├── json-env-passing │ │ │ ├── echo.js │ │ │ └── ecosystem.config.js │ │ ├── tar-module │ │ │ ├── mono-app-module │ │ │ │ ├── README.md │ │ │ │ ├── ecosystem.config.js │ │ │ │ ├── http.js │ │ │ │ └── package.json │ │ │ └── multi-app-module │ │ │ │ ├── README.md │ │ │ │ ├── ecosystem.config.js │ │ │ │ ├── http.js │ │ │ │ └── package.json │ │ └── version-test │ │ │ ├── index.js │ │ │ └── package.json │ ├── flagExt.mocha.js │ ├── flush.mocha.js │ ├── god.mocha.js │ ├── graceful.mocha.js │ ├── id.mocha.js │ ├── inside.mocha.js │ ├── instances.mocha.js │ ├── internal_config.mocha.js │ ├── issues │ │ └── json_env_passing_4080.mocha.js │ ├── json_validation.mocha.js │ ├── lazy_api.mocha.js │ ├── logs.js │ ├── max_memory_limit.js │ ├── misc_commands.js │ ├── module_configuration.mocha.js │ ├── module_tar.mocha.js │ ├── modules.mocha.js │ ├── namespace.mocha.js │ ├── path_resolution.mocha.js │ ├── programmatic.js │ ├── reload-locker.mocha.js │ ├── resurect_state.mocha.js │ ├── send_data_process.mocha.js │ ├── signals.js │ ├── sys_infos.mocha.js │ ├── user_management.mocha.js │ ├── version.mocha.js │ └── watcher.js └── unit.sh └── types ├── index.d.ts └── tsconfig.json /.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 | # Makefile 14 | [Makefile] 15 | indent_style = tab 16 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | *.sh eol=lf 3 | bin/** eol=lf 4 | test/fixtures/** eol=lf 5 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 5 | 6 | ## What's going wrong? 7 | 8 | ## How could we reproduce this issue? 9 | 10 | ## Supporting information 11 | 12 | 15 | ``` 16 | $ pm2 report 17 | ``` 18 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 4 | | Q | A 5 | | ------------- | --- 6 | | Bug fix? | yes/no 7 | | New feature? | yes/no 8 | | BC breaks? | no 9 | | Deprecations? | no 10 | | Tests pass? | yes 11 | | Fixed tickets | #1234, #5678 12 | | License | MIT 13 | | Doc PR | https://github.com/pm2-hive/pm2-hive.github.io/pulls 14 | -------------------------------------------------------------------------------- /.github/stale.yml: -------------------------------------------------------------------------------- 1 | # Number of days of inactivity before an issue becomes stale 2 | daysUntilStale: 30 3 | # Number of days of inactivity before a stale issue is closed 4 | daysUntilClose: 14 5 | # Issues with these labels will never be considered stale 6 | exemptLabels: 7 | - Inspecting 8 | - security 9 | - "P3: Medium" 10 | - "T: Bug" 11 | - "S: Open for PR" 12 | - "T: Enhancement" 13 | - "T: Feature" 14 | - "S: In Progress" 15 | - "S: Pending Release" 16 | 17 | # Label to use when marking an issue as stale 18 | staleLabel: stale 19 | # Comment to post when marking an issue as stale. Set to `false` to disable 20 | markComment: > 21 | This issue has been automatically marked as stale because it has not had 22 | recent activity. It will be closed if no further activity occurs. Thank you 23 | for your contributions. 24 | # Comment to post when closing a stale issue. Set to `false` to disable 25 | closeComment: false 26 | limitPerRun: 30 27 | only: issues 28 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | *.log 3 | *.pid 4 | test/child 5 | *.iml 6 | .idea/** 7 | *.heapsnapshot 8 | *.cpuprofile 9 | .cache-require-paths.json 10 | dist/ 11 | *.deb 12 | *.rpm 13 | package-lock.json 14 | .DS_Store 15 | *.swp 16 | *.swo 17 | currentTagChangelog.md 18 | joblog-X 19 | test/fixtures/path-check*.txt 20 | yarn.lock 21 | *.tar.gz 22 | e2e_time 23 | unit_time 24 | *.heapprofile 25 | a.out 26 | -------------------------------------------------------------------------------- /.mocharc.js: -------------------------------------------------------------------------------- 1 | 2 | module.exports = { 3 | 'allow-uncaught' : false, 4 | 'async-only': false, 5 | bail: true, 6 | color: true, 7 | delay: false, 8 | diff: true, 9 | exit: true, 10 | timeout: 10000, 11 | 'trace-warnings': true, 12 | ui: 'bdd', 13 | retries: 2 14 | } 15 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | dist: focal 3 | node_js: 4 | - "19" 5 | - "18" 6 | - "16" 7 | - "14" 8 | - "12" 9 | git: 10 | depth: 2 11 | os: 12 | - linux 13 | arch: 14 | - amd64 15 | before_install: 16 | - sudo apt-get -qq update 17 | - sudo apt-get install python3 18 | - sudo apt-get install php-cli 19 | - if [[ $(uname -m) == 's390x' ]]; then 20 | sudo apt-get install bc; 21 | fi 22 | services: 23 | - docker 24 | install: 25 | - npm install 26 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU-AGPL-3.0.txt 2 | -------------------------------------------------------------------------------- /bin/pm2: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | require('../lib/binaries/CLI.js'); 4 | -------------------------------------------------------------------------------- /bin/pm2-dev: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | require('../lib/binaries/DevCLI.js'); 4 | -------------------------------------------------------------------------------- /bin/pm2-docker: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | require('../lib/binaries/Runtime4Docker.js'); 4 | -------------------------------------------------------------------------------- /bin/pm2-runtime: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | require('../lib/binaries/Runtime4Docker.js'); 4 | -------------------------------------------------------------------------------- /examples/api-pm2/README.md: -------------------------------------------------------------------------------- 1 | 2 | # PM2 API 3 | 4 | Here is an example of the PM2 API: 5 | 6 | ``` 7 | $ node api.js 8 | ``` 9 | 10 | Will delete all apps, will start http.js, and restart http 11 | 12 | Then you will see that the listing shows http app, restarted one time: 13 | 14 | ``` 15 | $ pm2 list 16 | ┌──────────┬────┬──────┬──────┬────────┬─────────┬────────┬─────┬───────────┬─────────┬──────────┐ 17 | │ App name │ id │ mode │ pid │ status │ restart │ uptime │ cpu │ mem │ user │ watching │ 18 | ├──────────┼────┼──────┼──────┼────────┼─────────┼────────┼─────┼───────────┼─────────┼──────────┤ 19 | │ http │ 0 │ fork │ 7668 │ online │ 1 │ 2s │ 0% │ 34.2 MB │ unitech │ disabled │ 20 | └──────────┴────┴──────┴──────┴────────┴─────────┴────────┴─────┴───────────┴─────────┴──────────┘ 21 | Use `pm2 show ` to get more details about an app 22 | ``` 23 | -------------------------------------------------------------------------------- /examples/api-pm2/api.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | var pm2 = require('../..'); 4 | 5 | pm2.delete('all', function(err) { 6 | if (err) { 7 | console.error(err); 8 | return pm2.disconnect(); 9 | } 10 | 11 | pm2.start('http.js', function(err, app) { 12 | if (err) { 13 | console.error(err); 14 | return pm2.disconnect(); 15 | } 16 | 17 | console.log('Process HTTP has been started'); 18 | 19 | pm2.restart('http', function(err, app) { 20 | if (err) { 21 | console.error(err); 22 | return pm2.disconnect(); 23 | } 24 | 25 | console.log('Process Restarted'); 26 | return pm2.disconnect(); 27 | }); 28 | }); 29 | }); 30 | -------------------------------------------------------------------------------- /examples/api-pm2/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', server.address().port); 9 | }); 10 | -------------------------------------------------------------------------------- /examples/c-compile/hello.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | // printf() displays the string inside quotation 5 | printf("Hello, Wss asdsad!\n"); 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /examples/cluster-http/README.md: -------------------------------------------------------------------------------- 1 | 2 | To start http application in cluster mode: 3 | 4 | ```bash 5 | $ pm2 start ecosystem.config.js 6 | # OR 7 | $ pm2 start http.js -i max 8 | ``` 9 | -------------------------------------------------------------------------------- /examples/cluster-http/ecosystem.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | apps : [{ 3 | name : 'clustered_http', 4 | script : './http.js', 5 | instances : 'max', 6 | exec_mode : 'cluster', 7 | env : { 8 | PORT : 8002 9 | } 10 | }, { 11 | name : 'forked_app', 12 | script : './http.js', 13 | env : { 14 | PORT : 8001 15 | } 16 | }] 17 | } 18 | -------------------------------------------------------------------------------- /examples/cluster-http/http-no-exit.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 || 8089, '0.0.0.0', function() { 8 | console.log('App listening on port %d', server.address().port); 9 | }); 10 | 11 | process.on('SIGINT', () => { 12 | }) 13 | -------------------------------------------------------------------------------- /examples/cluster-http/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 || 8089, '0.0.0.0', function() { 8 | console.log('App listening on port %d', server.address().port); 9 | }); 10 | -------------------------------------------------------------------------------- /examples/cluster-tcp/README.md: -------------------------------------------------------------------------------- 1 | 2 | To start tcp application in cluster mode: 3 | 4 | ```bash 5 | $ pm2 start ecosystem.config.js 6 | # OR 7 | $ pm2 start tcp.js -i max 8 | ``` 9 | -------------------------------------------------------------------------------- /examples/cluster-tcp/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', server.address().port); 9 | }); 10 | -------------------------------------------------------------------------------- /examples/cluster-tcp/process.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | apps : [{ 3 | name : 'clustered_tcp', 4 | script : './tcp.js', 5 | instances : 'max', 6 | exec_mode : 'cluster', 7 | env : { 8 | PORT : 8002 9 | } 10 | }, { 11 | name : 'forked_tcp', 12 | script : './tcp.js', 13 | env : { 14 | PORT : 8001 15 | } 16 | }] 17 | } 18 | -------------------------------------------------------------------------------- /examples/cluster-tcp/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(process.env.PORT || 8888, function() { 6 | console.log('Listening on port %s', server.address().port); 7 | }); 8 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /examples/docker-pm2/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM keymetrics/pm2:latest-alpine 2 | 3 | # Bundle APP files 4 | COPY ./app /app 5 | WORKDIR /app 6 | 7 | # Install app dependencies 8 | ENV NPM_CONFIG_LOGLEVEL warn 9 | RUN npm install --production 10 | 11 | ENV KEYMETRICS_SECRET xxxx 12 | ENV KEYMETRICS_PUBLIC yyyy 13 | 14 | CMD [ "pm2-runtime", "process.config.js" ] 15 | -------------------------------------------------------------------------------- /examples/docker-pm2/README.md: -------------------------------------------------------------------------------- 1 | 2 | Here is an example on using pm2 inside container with the official image and pm2-runtime. 3 | 4 | To build & run it: 5 | 6 | ```bash 7 | # build image 8 | $ docker build -t docker-pm2-test . 9 | # list images 10 | $ docker images 11 | # run image 12 | $ docker run docker-pm2-test 13 | ``` 14 | 15 | There is also KEYMETRICS integration via KEYMETRICS_SECRET and KEYMETRICS_PUBLIC keys 16 | -------------------------------------------------------------------------------- /examples/docker-pm2/app/app.js: -------------------------------------------------------------------------------- 1 | const express = require('express') 2 | const app = express() 3 | 4 | app.get('/', (req, res) => res.send('Hello World!')) 5 | 6 | app.listen(3000, () => console.log('Example app listening on port 3000!')) 7 | -------------------------------------------------------------------------------- /examples/docker-pm2/app/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "app", 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.16.2" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /examples/docker-pm2/app/process.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | apps : [{ 3 | name : "express-app", 4 | script : "./app.js" 5 | }] 6 | } 7 | -------------------------------------------------------------------------------- /examples/echo/log.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | setInterval(function() { 4 | console.log('out'); 5 | }, 1000); 6 | 7 | setInterval(function() { 8 | console.error('err'); 9 | }, 1000); 10 | -------------------------------------------------------------------------------- /examples/echo/stdout.js: -------------------------------------------------------------------------------- 1 | 2 | setInterval(function() { 3 | process.stdout.write('ooo') 4 | }, 100) 5 | -------------------------------------------------------------------------------- /examples/ecosystem-file/README.md: -------------------------------------------------------------------------------- 1 | 2 | Here we have 3 applications (apps folder) that we can start with process file. 3 | These process file can be of different format, javascript, json or yaml: 4 | 5 | ``` 6 | . 7 | ├── apps 8 | │   ├── connection_check.sh 9 | │   ├── http.js 10 | │   └── worker.js 11 | ├── process.config.js 12 | ├── process.json 13 | └── process.yml 14 | ``` 15 | 16 | To start them: 17 | 18 | ```bash 19 | $ pm2 start process.config.js 20 | $ pm2 delete all 21 | $ pm2 start process.json 22 | $ pm2 delete all 23 | $ pm2 start process.yml 24 | ``` 25 | -------------------------------------------------------------------------------- /examples/ecosystem-file/apps/connection_check.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | foo() { 4 | echo "Hello Bash!" 5 | } 6 | 7 | while true; do foo; sleep 2; done 8 | -------------------------------------------------------------------------------- /examples/ecosystem-file/apps/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/ecosystem-file/apps/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/ecosystem-file/process.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | apps : [{ 3 | name : 'HTTP-API', 4 | script : 'apps/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 : 'apps/worker.js', 19 | err_file : 'toto-err.log' 20 | }, { 21 | name : 'Checks', 22 | script : 'apps/connection_check.sh' 23 | }] 24 | } 25 | -------------------------------------------------------------------------------- /examples/ecosystem-file/process.json: -------------------------------------------------------------------------------- 1 | { 2 | apps : [{ 3 | name : 'HTTP-API', 4 | script : 'apps/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 : 'apps/worker.js' 20 | }, { 21 | name : 'Checks', 22 | script : 'apps/connection_check.sh' 23 | }] 24 | } 25 | -------------------------------------------------------------------------------- /examples/ecosystem-file/process.yml: -------------------------------------------------------------------------------- 1 | apps: 2 | - name : 'HTTP-API' 3 | script: 'apps/http.js' 4 | instances: 'max' 5 | max_memory_restart: '260M' 6 | watch : true 7 | ignore_watch : ['node_modules'] 8 | env: 9 | NODE_ENV : 'development' 10 | env_production: 11 | NODE_ENV : 'production' 12 | - name : 'Worker' 13 | script: 'apps/worker.js' 14 | - name : 'Checks' 15 | script : 'apps/connection_check.sh' 16 | -------------------------------------------------------------------------------- /examples/esm/addTwo.js: -------------------------------------------------------------------------------- 1 | // addTwo.mjs 2 | function addTwo(num) { 3 | return num + 2; 4 | } 5 | 6 | export { addTwo }; 7 | -------------------------------------------------------------------------------- /examples/esm/app.js: -------------------------------------------------------------------------------- 1 | 2 | // app.mjs 3 | import { addTwo } from './addTwo.js'; 4 | 5 | // Prints: 6 6 | console.log(addTwo(4)); 7 | -------------------------------------------------------------------------------- /examples/esm/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "esm", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "addTwo.js", 6 | "type": "module", 7 | "scripts": { 8 | "test": "echo \"Error: no test specified\" && exit 1" 9 | }, 10 | "author": "", 11 | "license": "ISC" 12 | } 13 | -------------------------------------------------------------------------------- /examples/exception/fast.js: -------------------------------------------------------------------------------- 1 | setTimeout(() => { 2 | throw new Error('err') 3 | }, 100) 4 | -------------------------------------------------------------------------------- /examples/exception/slow.js: -------------------------------------------------------------------------------- 1 | setTimeout(() => { 2 | throw new Error('err') 3 | }, 1500) 4 | -------------------------------------------------------------------------------- /examples/expose-custom-metrics/README.md: -------------------------------------------------------------------------------- 1 | 2 | To expose custom metrics from your code and monitor it from CLI: 3 | 4 | ```bash 5 | $ pm2 start process.config.js 6 | ``` 7 | 8 | Then to monitor metrics: 9 | 10 | ```bash 11 | $ pm2 monit 12 | ``` 13 | 14 | Or 15 | 16 | ```bash 17 | $ pm2 show 0 18 | ``` 19 | -------------------------------------------------------------------------------- /examples/expose-custom-metrics/process-metrics.js: -------------------------------------------------------------------------------- 1 | 2 | var Probe = require('pmx').probe(); 3 | 4 | var i = 0; 5 | 6 | var metric = Probe.metric({ 7 | name : 'Metric', 8 | value : function() { 9 | return i; 10 | } 11 | }); 12 | 13 | setInterval(function() { 14 | i++; 15 | }, 100); 16 | 17 | 18 | var meter = Probe.meter({ 19 | name : 'Meter' 20 | }); 21 | 22 | setInterval(function() { 23 | meter.mark() 24 | }, 200); 25 | 26 | var histo = Probe.histogram({ 27 | name : 'Histogram' 28 | }); 29 | 30 | var latency; 31 | 32 | setInterval(function() { 33 | latency = Math.round(Math.random() * 100); 34 | histo.update(latency); 35 | }, 100); 36 | 37 | var counter = Probe.counter({ 38 | name : 'Counter' 39 | }); 40 | 41 | setInterval(function() { 42 | counter.inc() 43 | }, 500); 44 | -------------------------------------------------------------------------------- /examples/expose-custom-metrics/process.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | apps : [{ 3 | script : 'process-metrics.js' 4 | }] 5 | } 6 | -------------------------------------------------------------------------------- /examples/expose-triggerable-functions/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/expose-triggerable-functions/process.yml: -------------------------------------------------------------------------------- 1 | - script : './index.js' 2 | name : 'custom-actions' 3 | -------------------------------------------------------------------------------- /examples/expose-triggerable-functions/trigger-param.js: -------------------------------------------------------------------------------- 1 | var pm2 = require('../..'); 2 | 3 | pm2.trigger('0', 'param', { some : 'data' }, function(err, res) { 4 | var rep_1 = res[0]; 5 | console.log(`Got result from ${rep_1.process.name}`); 6 | console.log(rep_1.data); 7 | 8 | pm2.disconnect(); 9 | }); 10 | -------------------------------------------------------------------------------- /examples/expose-triggerable-functions/trigger-ping.js: -------------------------------------------------------------------------------- 1 | var pm2 = require('../..'); 2 | 3 | pm2.trigger('0', 'ping', function(err, res) { 4 | var rep_1 = res[0]; 5 | console.log(`Got result from ${rep_1.process.name}`); 6 | console.log(rep_1.data); 7 | 8 | pm2.disconnect(); 9 | }); 10 | -------------------------------------------------------------------------------- /examples/import/circle.js: -------------------------------------------------------------------------------- 1 | const PI = 3.14159265359; 2 | 3 | export function area(radius) { 4 | return (radius ** 2) * PI; 5 | } 6 | 7 | export function circumference(radius) { 8 | return 2 * radius * PI; 9 | } 10 | -------------------------------------------------------------------------------- /examples/import/index.js: -------------------------------------------------------------------------------- 1 | import { area, circumference } from './circle.js'; 2 | 3 | const r = 3; 4 | 5 | console.log(`Circle with radius ${r} has 6 | area: ${area(r)}; 7 | circunference: ${circumference(r)}`); 8 | -------------------------------------------------------------------------------- /examples/import/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "import", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "type":"module", 7 | "scripts": { 8 | "test": "echo \"Error: no test specified\" && exit 1" 9 | }, 10 | "author": "", 11 | "license": "ISC" 12 | } 13 | -------------------------------------------------------------------------------- /examples/interact-via-stdin/README.md: -------------------------------------------------------------------------------- 1 | 2 | To interact with an app readin on stdin: 3 | 4 | 5 | ``` 6 | $ pm2 start stdin.js 7 | ``` 8 | 9 | Then to attach to it: 10 | 11 | ``` 12 | $ pm2 attach 0 13 | ``` 14 | -------------------------------------------------------------------------------- /examples/interact-via-stdin/stdin.js: -------------------------------------------------------------------------------- 1 | 2 | const readline = require('readline'); 3 | 4 | const rl = readline.createInterface({ 5 | input: process.stdin, 6 | output: process.stdout 7 | }); 8 | 9 | rl.prompt(); 10 | 11 | rl.on('line', (data) =>{ 12 | console.log('Received data'); 13 | console.log(data); 14 | }); 15 | 16 | setInterval(() => { 17 | //console.log('Yes'); 18 | }, 2000); 19 | -------------------------------------------------------------------------------- /examples/misc-examples/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/misc-examples/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 | -------------------------------------------------------------------------------- /examples/misc-examples/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 | -------------------------------------------------------------------------------- /examples/misc-examples/apps/auto-kill-echo.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "auto-kill", 3 | "script" : "./examples/echokill.js", 4 | "max" : "10" 5 | } 6 | -------------------------------------------------------------------------------- /examples/misc-examples/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 | -------------------------------------------------------------------------------- /examples/misc-examples/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/misc-examples/apps/default-path-echo.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "echo-default", 3 | "script" : "examples/echo.js", 4 | "max" : "1" 5 | } 6 | -------------------------------------------------------------------------------- /examples/misc-examples/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 | -------------------------------------------------------------------------------- /examples/misc-examples/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/misc-examples/apps/killfast.json: -------------------------------------------------------------------------------- 1 | { 2 | "min_uptime" : "100", 3 | "max_restarts" : "400", 4 | "name" : "auto-kill", 5 | "script" : "./examples/killfast.js" 6 | } 7 | -------------------------------------------------------------------------------- /examples/misc-examples/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/misc-examples/apps/no-name-echo.json: -------------------------------------------------------------------------------- 1 | { 2 | "script" : "examples/echo.js", 3 | "max" : "1" 4 | } 5 | -------------------------------------------------------------------------------- /examples/misc-examples/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 | -------------------------------------------------------------------------------- /examples/misc-examples/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 | -------------------------------------------------------------------------------- /examples/misc-examples/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/misc-examples/auto-save.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/socketio/pm2/311c53298448fc4575fc689c4943692a664373ad/examples/misc-examples/auto-save.js -------------------------------------------------------------------------------- /examples/misc-examples/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/misc-examples/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 | -------------------------------------------------------------------------------- /examples/misc-examples/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 | -------------------------------------------------------------------------------- /examples/misc-examples/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/misc-examples/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/misc-examples/child.js-pm2.json: -------------------------------------------------------------------------------- 1 | { 2 | "script":"examples/child.js", 3 | "name":"child.js" 4 | } 5 | -------------------------------------------------------------------------------- /examples/misc-examples/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/misc-examples/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 | -------------------------------------------------------------------------------- /examples/misc-examples/echo.coffee: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env coffee 2 | 3 | setInterval (-> console.log 'ok'), 500 -------------------------------------------------------------------------------- /examples/misc-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 | -------------------------------------------------------------------------------- /examples/misc-examples/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/misc-examples/env.js: -------------------------------------------------------------------------------- 1 | setInterval(function() { 2 | console.log('env NODE_ENV = ', process.env.NODE_ENV); 3 | }, 1000); 4 | -------------------------------------------------------------------------------- /examples/misc-examples/env_args.js: -------------------------------------------------------------------------------- 1 | 2 | console.log(process.env.PASSED_VARIABLE); 3 | -------------------------------------------------------------------------------- /examples/misc-examples/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/misc-examples/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 | -------------------------------------------------------------------------------- /examples/misc-examples/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 | -------------------------------------------------------------------------------- /examples/misc-examples/graceful-exit.js: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Example of graceful exit 4 | * 5 | * $ pm2 reload 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 | -------------------------------------------------------------------------------- /examples/misc-examples/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 | -------------------------------------------------------------------------------- /examples/misc-examples/infinite-recurse.js: -------------------------------------------------------------------------------- 1 | function x() { 2 | x(); 3 | } 4 | x(); 5 | -------------------------------------------------------------------------------- /examples/misc-examples/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 | -------------------------------------------------------------------------------- /examples/misc-examples/inside.json: -------------------------------------------------------------------------------- 1 | 2 | [{ 3 | "name" : "inside", 4 | "script":"examples/inside.js" 5 | },{ 6 | "name" : "echo", 7 | "script":"examples/echo.js" 8 | }] 9 | -------------------------------------------------------------------------------- /examples/misc-examples/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 | -------------------------------------------------------------------------------- /examples/misc-examples/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 | -------------------------------------------------------------------------------- /examples/misc-examples/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 | -------------------------------------------------------------------------------- /examples/misc-examples/kill-slow.js: -------------------------------------------------------------------------------- 1 | 2 | setTimeout(function() { 3 | console.log('exit'); 4 | process.exit(1); 5 | }, 1000); 6 | -------------------------------------------------------------------------------- /examples/misc-examples/killfast.js: -------------------------------------------------------------------------------- 1 | 2 | process.exit(1); 3 | -------------------------------------------------------------------------------- /examples/misc-examples/killslow.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | setTimeout(function() { 4 | throw new Error('ok'); 5 | }, 1100); 6 | -------------------------------------------------------------------------------- /examples/misc-examples/killtoofast.js: -------------------------------------------------------------------------------- 1 | 2 | console.log('im a kamikazy'); 3 | 4 | setInterval(function() { 5 | console.log('BOUM'); 6 | process.exit(1); 7 | }, 30); 8 | -------------------------------------------------------------------------------- /examples/misc-examples/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 | -------------------------------------------------------------------------------- /examples/misc-examples/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 | -------------------------------------------------------------------------------- /examples/misc-examples/modulechild.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | console.log(module.parent); 4 | -------------------------------------------------------------------------------- /examples/misc-examples/moduleparent.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | var a =require('./modulechild.js'); 4 | console.log(module.children); 5 | -------------------------------------------------------------------------------- /examples/misc-examples/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 | -------------------------------------------------------------------------------- /examples/misc-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 | -------------------------------------------------------------------------------- /examples/misc-examples/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 | -------------------------------------------------------------------------------- /examples/misc-examples/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 | -------------------------------------------------------------------------------- /examples/misc-examples/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 | -------------------------------------------------------------------------------- /examples/misc-examples/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/misc-examples/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 | -------------------------------------------------------------------------------- /examples/misc-examples/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 | -------------------------------------------------------------------------------- /examples/misc-examples/stop-after5.js: -------------------------------------------------------------------------------- 1 | 2 | setTimeout(function() { 3 | process.exit(0); 4 | }, 5000); 5 | -------------------------------------------------------------------------------- /examples/misc-examples/string-crash.js: -------------------------------------------------------------------------------- 1 | 2 | function crash() { 3 | throw 'crashed'; 4 | } 5 | 6 | crash(); 7 | -------------------------------------------------------------------------------- /examples/misc-examples/throw.js: -------------------------------------------------------------------------------- 1 | 2 | setTimeout(function() { 3 | throw new Error('New error thrown automatically'); 4 | }, 1200); 5 | -------------------------------------------------------------------------------- /examples/misc-examples/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 | -------------------------------------------------------------------------------- /examples/misc-examples/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 | -------------------------------------------------------------------------------- /examples/misc-examples/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 | -------------------------------------------------------------------------------- /examples/module-extra-meta/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 | -------------------------------------------------------------------------------- /examples/module-extra-meta/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 | -------------------------------------------------------------------------------- /examples/module-test/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "module-test", 3 | "version": "1.0.0", 4 | "description": "PM2 Sample Module", 5 | "main": "app.js", 6 | "dependencies": { 7 | "pmx": "beta" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/keymetrics/pmx.git" 12 | }, 13 | "config": { 14 | "conf_var_1": true, 15 | "conf_var_2": "myvalue" 16 | }, 17 | "apps": [ 18 | { 19 | "merge_logs": true, 20 | "max_memory_restart": "200M", 21 | "script": "app.js" 22 | } 23 | ], 24 | "author": "Keymetrics Inc.", 25 | "license": "MIT" 26 | } 27 | -------------------------------------------------------------------------------- /examples/npm-start/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', server.address().port); 9 | }); 10 | -------------------------------------------------------------------------------- /examples/npm-start/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "npm-start", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1", 8 | "start": "node http.js" 9 | }, 10 | "author": "", 11 | "license": "ISC" 12 | } 13 | -------------------------------------------------------------------------------- /examples/pmx-test-all/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/pmx-test-all/elements/error.js: -------------------------------------------------------------------------------- 1 | 2 | setInterval(function() { 3 | new Error('toto'); 4 | }, 10); 5 | -------------------------------------------------------------------------------- /examples/pmx-test-all/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/pmx-test-all/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/pmx-test-all/elements/log-cluster.js: -------------------------------------------------------------------------------- 1 | setInterval(function() { 2 | console.log('log'); 3 | console.error('log'); 4 | }, 200); 5 | -------------------------------------------------------------------------------- /examples/pmx-test-all/elements/log.js: -------------------------------------------------------------------------------- 1 | 2 | setInterval(function() { 3 | console.log('log'); 4 | console.error('log'); 5 | }, 200); 6 | -------------------------------------------------------------------------------- /examples/pmx-test-all/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 | -------------------------------------------------------------------------------- /examples/pmx-test-all/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/pmx-test-all/elements/notify.js: -------------------------------------------------------------------------------- 1 | 2 | const pmx = require('pmx'); 3 | 4 | setInterval(function() { 5 | pmx.notify({ success : false }); 6 | }, 200); 7 | -------------------------------------------------------------------------------- /examples/pmx-test-all/process.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | pm2 : [{ 3 | script : './elements/error.js' 4 | }, { 5 | script : './elements/metric.js' 6 | }, { 7 | script : './elements/counter.js' 8 | }, { 9 | script : './elements/meter.js' 10 | }, { 11 | script : './elements/histogram.js' 12 | }, { 13 | script : './elements/event.js' 14 | }, { 15 | script : './elements/notify.js' 16 | }, { 17 | script : './elements/log.js' 18 | }, { 19 | script : './elements/log-cluster.js', 20 | instances : 2 21 | }, { 22 | script : './elements/http.js' 23 | }, { 24 | script : './elements/cluster.js', 25 | instances : 4, 26 | env : { 27 | PORT : 9803 28 | } 29 | }, { 30 | script : './elements/trace.js', 31 | trace : true 32 | }] 33 | } 34 | -------------------------------------------------------------------------------- /examples/run-php-python-ruby-bash/bashscript.sh: -------------------------------------------------------------------------------- 1 | while true; do 2 | ls -l 3 | sleep 5 4 | done 5 | 6 | -------------------------------------------------------------------------------- /examples/run-php-python-ruby-bash/echo.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/run-php-python-ruby-bash/echo.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | import time 3 | 4 | while 1: 5 | print("Start : %s" % time.ctime()) 6 | print("second line") 7 | time.sleep(1) 8 | -------------------------------------------------------------------------------- /examples/run-php-python-ruby-bash/echo.rb: -------------------------------------------------------------------------------- 1 | 2 | while 1 do 3 | puts "lol" 4 | sleep 1 5 | end 6 | -------------------------------------------------------------------------------- /examples/run-php-python-ruby-bash/process.yml: -------------------------------------------------------------------------------- 1 | apps: 2 | - script : './bashscript.sh' 3 | name : 'bash-script' 4 | - script : './echo.php' 5 | name : 'php-script' 6 | - script : './echo.rb' 7 | name : 'ruby-script' 8 | - script : './echo.py' 9 | name : 'python-script' 10 | -------------------------------------------------------------------------------- /examples/send-msg/pm2-app.js: -------------------------------------------------------------------------------- 1 | 2 | process.on('message', function(packet) { 3 | process.send({ 4 | type : 'process:msg', 5 | data : { 6 | success : true 7 | } 8 | }); 9 | }); 10 | -------------------------------------------------------------------------------- /examples/send-msg/pm2-msg.js: -------------------------------------------------------------------------------- 1 | 2 | const pm2 = require('../..') 3 | 4 | console.log(pm2) 5 | 6 | pm2.connect(function() { 7 | pm2.sendDataToProcessId({ 8 | // id of procces from "pm2 list" command or from pm2.list(errback) method 9 | id : '1', 10 | 11 | // process:msg will be send as 'message' on target process 12 | type : 'process:msg', 13 | 14 | // Data to be sent 15 | data : { 16 | some : 'data' 17 | }, 18 | 19 | topic: true 20 | }, function(err, res) { 21 | }) 22 | }) 23 | 24 | // Listen to messages from application 25 | pm2.launchBus(function(err, pm2_bus) { 26 | pm2_bus.on('process:msg', function(packet) { 27 | console.log(packet) 28 | }) 29 | }) 30 | -------------------------------------------------------------------------------- /examples/send-msg/t2.js: -------------------------------------------------------------------------------- 1 | 2 | var tx2 = require('tx2') 3 | var http = require('http') 4 | 5 | var meter = tx2.meter({ 6 | name : 'req/sec', 7 | samples : 1, 8 | timeframe : 60 9 | }) 10 | 11 | http.createServer(function (req, res) { 12 | meter.mark() 13 | res.writeHead(200, {'Content-Type': 'text/plain'}) 14 | res.write('Hello World!') 15 | res.end() 16 | }).listen(6001) 17 | -------------------------------------------------------------------------------- /examples/signal-catching/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 | -------------------------------------------------------------------------------- /examples/sourcemap-auto-resolve/process.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | apps : [{ 3 | name : "API-minified", 4 | script : "API.min.js" 5 | }] 6 | } 7 | -------------------------------------------------------------------------------- /examples/start-a-binary/ls.yml: -------------------------------------------------------------------------------- 1 | apps: 2 | - script : './ls' 3 | -------------------------------------------------------------------------------- /examples/test-all-keymetrics-features/README.md: -------------------------------------------------------------------------------- 1 | 2 | Try all features of Keymetrics: 3 | 4 | ```bash 5 | # Make sure you've created keymetrics account 6 | $ pm2 register 7 | # Start all applications 8 | $ pm2 start process.config.js 9 | # Open Dashboard 10 | $ pm2 open 11 | ``` 12 | -------------------------------------------------------------------------------- /examples/test-all-keymetrics-features/custom_action.js: -------------------------------------------------------------------------------- 1 | 2 | var axm = require('@pm2/io'); 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 | -------------------------------------------------------------------------------- /examples/test-all-keymetrics-features/custom_action_with_params.js: -------------------------------------------------------------------------------- 1 | 2 | var axm = require('@pm2/io'); 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/test-all-keymetrics-features/event.js: -------------------------------------------------------------------------------- 1 | 2 | var axm = require('@pm2/io'); 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/test-all-keymetrics-features/pm2_probe.js: -------------------------------------------------------------------------------- 1 | var io = require('@pm2/io'); 2 | var pm2 = require('../..'); 3 | var fs = require('fs'); 4 | var path = require('path'); 5 | 6 | var conf = io.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 | 14 | widget : { 15 | theme : ['#111111', '#1B2228', '#807C7C', '#807C7C'], 16 | logo : 'https://keymetrics.io/assets/images/pm2.20d3ef.png?v=0b71a506ce' 17 | } 18 | }); 19 | 20 | var probe = io.probe(); 21 | 22 | var pm2_procs = 0; 23 | 24 | pm2.connect(function() { 25 | 26 | setInterval(function() { 27 | pm2.list(function(err, procs) { 28 | pm2_procs = procs.length; 29 | }); 30 | }, 2000); 31 | 32 | var metric = probe.metric({ 33 | name : 'Processes', 34 | value : function() { 35 | return pm2_procs; 36 | } 37 | }); 38 | }); 39 | -------------------------------------------------------------------------------- /examples/test-all-keymetrics-features/process-load.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | pm2 : [{ 3 | script : "http_app.js", 4 | instances : 10 5 | }, { 6 | script : "throw.js", 7 | instances : 10 8 | }] 9 | } 10 | -------------------------------------------------------------------------------- /examples/test-all-keymetrics-features/process-transpose.js: -------------------------------------------------------------------------------- 1 | 2 | var Probe = require('@pm2/io').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 | -------------------------------------------------------------------------------- /examples/test-all-keymetrics-features/process.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | "pm2" : [{ 3 | "script" : "pm2_probe.js" 4 | }, { 5 | "script" : "event.js" 6 | }, { 7 | "script" : "http_app.js", 8 | "instances" : 4 9 | }, { 10 | "script" : "probes.js" 11 | }, { 12 | "script" : "http_transaction.js" 13 | }, { 14 | "script" : "process-transpose.js" 15 | }, { 16 | "script" : "scoped-actions.js" 17 | }, { 18 | "script" : "custom_action.js" 19 | }, { 20 | "script" : "custom_action_with_params.js" 21 | }, { 22 | "script" : "http_transaction.js" 23 | }, { 24 | "script" : "throw.js" 25 | }] 26 | } 27 | -------------------------------------------------------------------------------- /examples/test-all-keymetrics-features/scoped-actions.js: -------------------------------------------------------------------------------- 1 | 2 | var io = require('@pm2/io'); 3 | 4 | io.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 | io.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 | -------------------------------------------------------------------------------- /examples/test-all-keymetrics-features/throw.js: -------------------------------------------------------------------------------- 1 | 2 | var axm = require('@pm2/io'); 3 | 4 | setTimeout(function() { 5 | console.log('log message from echo auto kill'); 6 | throw new Error('Exitasdsadasdsda unacepted 222222 !!'); 7 | }, 2000); 8 | -------------------------------------------------------------------------------- /examples/treekill/app.js: -------------------------------------------------------------------------------- 1 | 2 | const spawn = require('child_process').spawn 3 | var fs = require('fs'); 4 | 5 | setTimeout(function() { 6 | daemonize('pm2 ls --watch'); 7 | // setTimeout(function() { 8 | // process.exit(0); 9 | // }, 300); 10 | 11 | setInterval(function() {}, 1000); 12 | }, 3000); 13 | 14 | var daemonize = function exec (cmd, cb) { 15 | const args = cmd.split(' ') 16 | const bin = args.shift() 17 | 18 | var logFile = '/tmp/test.log'; 19 | const fdOut = fs.openSync(logFile, 'a+') 20 | const fdErr = fs.openSync(logFile, 'a+') 21 | 22 | console.log(`Spawning command ${cmd}`) 23 | console.log(`Log file: ${logFile}`) 24 | 25 | const installInstance = spawn(bin, args, { 26 | env: process.env, 27 | detached: true, 28 | stdio: ['ignore', fdOut, fdErr] 29 | }) 30 | 31 | installInstance.unref() 32 | if (typeof cb === 'function') { 33 | cb() 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /examples/treekill/process.json: -------------------------------------------------------------------------------- 1 | { 2 | "apps" : { 3 | "treekill" : false, 4 | "script" : "app.js" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /examples/udp/client.js: -------------------------------------------------------------------------------- 1 | var udp = require('dgram'); 2 | 3 | // -------------------- udp client ---------------- 4 | 5 | var buffer = require('buffer'); 6 | 7 | // creating a client socket 8 | var client = udp.createSocket('udp4'); 9 | 10 | //buffer msg 11 | var data = Buffer.from('siddheshrane'); 12 | 13 | client.on('message',function(msg,info){ 14 | console.log('Data received from server : ' + msg.toString()); 15 | console.log('Received %d bytes from %s:%d\n',msg.length, info.address, info.port); 16 | }); 17 | 18 | setInterval(() => { 19 | //sending msg 20 | client.send(data,2222,'localhost',function(error){ 21 | if(error){ 22 | client.close(); 23 | }else{ 24 | console.log('Data sent !!!'); 25 | } 26 | }); 27 | }, 10) 28 | 29 | var data1 = Buffer.from('hello'); 30 | var data2 = Buffer.from('world'); 31 | 32 | //sending multiple msg 33 | client.send([data1,data2],2222,'localhost',function(error){ 34 | if(error){ 35 | client.close(); 36 | }else{ 37 | console.log('Data sent !!!'); 38 | } 39 | }); 40 | -------------------------------------------------------------------------------- /examples/using-pm2-and-transpilers/README.md: -------------------------------------------------------------------------------- 1 | 2 | ## Coffee Script 3 | 4 | ``` 5 | $ pm2 install coffee-script 6 | $ pm2 start echo.coffee 7 | ``` 8 | 9 | ## Typescript 10 | 11 | ``` 12 | $ pm2 install typescript 13 | $ pm2 start http.ts 14 | ``` 15 | 16 | ## Livescript 17 | 18 | 19 | ``` 20 | $ pm2 install livescript 21 | $ pm2 start echo.ls 22 | ``` 23 | -------------------------------------------------------------------------------- /examples/using-pm2-and-transpilers/echo.coffee: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env coffee 2 | 3 | setInterval (-> console.log 'ok'), 500 -------------------------------------------------------------------------------- /examples/using-pm2-and-transpilers/echo.ls: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env lsc 2 | 3 | setInterval (-> console.log 'ok'), 500 -------------------------------------------------------------------------------- /examples/using-pm2-and-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/using-pm2-and-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 | -------------------------------------------------------------------------------- /examples/wait-ready/app.js: -------------------------------------------------------------------------------- 1 | const http = require('http'); 2 | 3 | process.on('SIGINT', (msg) => { 4 | console.log('Just got SIGINTed, but I dont care'); 5 | process.exit(0); 6 | }); 7 | 8 | const port = 3000; 9 | 10 | const app = http.createServer((_, res) => { 11 | res.writeHead(200); 12 | res.end('Hello!'); 13 | }); 14 | 15 | setTimeout(() => { 16 | app.listen(port, () => { 17 | console.log(`Listening on ${port}`); 18 | if (process.send) { 19 | process.send('ready'); 20 | } 21 | }); 22 | }, 10000); 23 | -------------------------------------------------------------------------------- /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 | "kill_timeout" : 2000, 9 | "listen_timeout": 1000 10 | }] 11 | } 12 | -------------------------------------------------------------------------------- /examples/wait-ready/http-simple.js: -------------------------------------------------------------------------------- 1 | var http = require('http'); 2 | 3 | var server = http.createServer(function(req, res) { 4 | res.writeHead(200); 5 | res.end('hey'); 6 | }).listen(process.env.PORT || 8000, function() { 7 | console.log('App listening on port %d in env %s', process.env.PORT || 8000, process.env.NODE_ENV); 8 | 9 | // 1# Notify application ready 10 | setTimeout(function() { 11 | process.send('ready'); 12 | }, 2000); 13 | 14 | }); 15 | 16 | // // 2# Handle on Exit 17 | process.on('SIGINT', function() { 18 | console.log('Cleanup on exit'); 19 | 20 | server.on('close', function() { 21 | console.log('Connections closed'); 22 | process.exit(0); 23 | }); 24 | 25 | server.close(); 26 | }); 27 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2022 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 | -------------------------------------------------------------------------------- /lib/API/ExtraMgmt/Docker.js: -------------------------------------------------------------------------------- 1 | 2 | const util = require('util') 3 | const spawn = require('child_process').spawn 4 | const DockerMgmt = {} 5 | 6 | module.exports = DockerMgmt 7 | 8 | function execDocker(cmd, cb) { 9 | var i = spawn('docker', cmd, { 10 | stdio : 'inherit', 11 | env: process.env, 12 | shell : true 13 | }) 14 | 15 | i.on('close', cb) 16 | } 17 | 18 | DockerMgmt.processCommand = function(PM2, start_id, select_id, action, cb) { 19 | PM2.Client.executeRemote('getSystemData', {}, (err, sys_infos) => { 20 | if (sys_infos.containers && sys_infos.containers.length == 0) 21 | return cb(new Error(`Process ${select_id} not found`)) 22 | var container = sys_infos.containers[select_id - start_id - 1] 23 | if (action == 'stopProcessId') 24 | execDocker(['stop', container.id], cb) 25 | if (action == 'deleteProcessId') 26 | execDocker(['rm', container.id], cb) 27 | if (action == 'restartProcessId') 28 | execDocker(['restart', container.id], cb) 29 | }) 30 | } 31 | -------------------------------------------------------------------------------- /lib/API/UX/index.js: -------------------------------------------------------------------------------- 1 | 2 | const UX = { 3 | helpers: require('./helpers.js'), 4 | describe: require('./pm2-describe.js'), 5 | list: require('./pm2-ls.js'), 6 | list_min: require('./pm2-ls-minimal.js') 7 | } 8 | 9 | module.exports = UX 10 | -------------------------------------------------------------------------------- /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 | ".tsx" : "ts-node" 12 | } 13 | -------------------------------------------------------------------------------- /lib/API/pm2-plus/pres/motd: -------------------------------------------------------------------------------- 1 | 2 | ██████╗ ███╗ ███╗██████╗ ██╗ ██╗ ██████╗ 3 | ██╔══██╗████╗ ████║╚════██╗ ██║ ██╔╝██╔═══██╗ 4 | ██████╔╝██╔████╔██║ █████╔╝ ██║ ██╔╝ ██║ ██║ 5 | ██╔═══╝ ██║╚██╔╝██║██╔═══╝ ██║ ██╔╝ ██║ ██║ 6 | ██║ ██║ ╚═╝ ██║███████╗ ██║██╔╝ ╚██████╔╝ 7 | ╚═╝ ╚═╝ ╚═╝╚══════╝ ╚═╝╚═╝ ╚═════╝ 8 | 9 | https://pm2.io/ 10 | 11 | Harden your Node.js Production Environment 12 | 13 | - Real-time Monitoring Web Interface 14 | - Pro Active Alerting System 15 | - Production Profiling for Memory and CPU 16 | - PM2 Runtime High Availability Fallback 17 | -------------------------------------------------------------------------------- /lib/API/pm2-plus/pres/motd.update: -------------------------------------------------------------------------------- 1 | 2 | ------------- 3 | 4 | 5 | ██████╗ ███╗ ███╗██████╗ ██╗ ██╗ ██████╗ 6 | ██╔══██╗████╗ ████║╚════██╗ ██║ ██╔╝██╔═══██╗ 7 | ██████╔╝██╔████╔██║ █████╔╝ ██║ ██╔╝ ██║ ██║ 8 | ██╔═══╝ ██║╚██╔╝██║██╔═══╝ ██║ ██╔╝ ██║ ██║ 9 | ██║ ██║ ╚═╝ ██║███████╗ ██║██╔╝ ╚██████╔╝ 10 | ╚═╝ ╚═╝ ╚═╝╚══════╝ ╚═╝╚═╝ ╚═════╝ 11 | 12 | https://pm2.io/ 13 | 14 | Harden your Node.js Production Environment 15 | 16 | - Real-time Monitoring Web Interface 17 | - Pro Active Alerting System 18 | - Production Profiling for Memory and CPU 19 | - PM2 Runtime High Availability Fallback 20 | 21 | 22 | Start using it by typing: 23 | 24 | $ pm2 plus 25 | 26 | ------------- 27 | -------------------------------------------------------------------------------- /lib/API/pm2-plus/pres/welcome: -------------------------------------------------------------------------------- 1 | 2 | ------------- 3 | 4 | PM2 Plus Edition 5 | 6 | 7 | PM2 Plus is a monitoring dashboard 8 | specialized for Node.js Apps. 9 | 10 | Create an account: 11 | $ pm2 plus register 12 | 13 | Connect your local PM2 to the PM2 Plus servers: 14 | $ pm2 plus connect 15 | 16 | See our UI with your own realtime dashboard: 17 | $ pm2 plus web 18 | 19 | More details available there: 20 | http://pm2.io/plus 21 | 22 | ------------- 23 | 24 | Having complex or specific needs? 25 | You can also checkout our enterprise offer at: 26 | http://pm2.io/enterprise 27 | 28 | ------------- 29 | -------------------------------------------------------------------------------- /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-nodejs.tpl: -------------------------------------------------------------------------------- 1 | FROM keymetrics/pm2:latest 2 | 3 | RUN mkdir -p /var/app 4 | 5 | WORKDIR /var/app 6 | 7 | COPY ./package.json /var/app 8 | RUN npm install 9 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /lib/templates/ecosystem-simple.tpl: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | apps : [{ 3 | name : "app1", 4 | script : "./app.js" 5 | }] 6 | } 7 | -------------------------------------------------------------------------------- /lib/templates/ecosystem.tpl: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | apps : [{ 3 | script: 'index.js', 4 | watch: '.' 5 | }, { 6 | script: './service-worker/', 7 | watch: ['./service-worker'] 8 | }], 9 | 10 | deploy : { 11 | production : { 12 | user : 'SSH_USERNAME', 13 | host : 'SSH_HOSTMACHINE', 14 | ref : 'origin/master', 15 | repo : 'GIT_REPOSITORY', 16 | path : 'DESTINATION_PATH', 17 | 'pre-deploy-local': '', 18 | 'post-deploy' : 'npm install && pm2 reload ecosystem.config.js --env production', 19 | 'pre-setup': '' 20 | } 21 | } 22 | }; 23 | -------------------------------------------------------------------------------- /lib/templates/init-scripts/rcd-openbsd.tpl: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # from /usr/ports/infrastructure/templates/rc.template 4 | 5 | daemon="/usr/local/bin/pm2" 6 | #daemon_flags= 7 | #daemon_rtable=0 8 | #daemon_timeout="30" 9 | daemon_user="%USER%" 10 | 11 | . /etc/rc.d/rc.subr 12 | 13 | pexp="node: PM2.*God Daemon.*" 14 | #rc_bg= # (undefined) 15 | #rc_reload= # (undefined) 16 | #rc_usercheck=YES 17 | 18 | #rc_pre() { 19 | #} 20 | 21 | rc_start() { 22 | ${rcexec} "${daemon} ${daemon_flags} resurrect" 23 | } 24 | 25 | #rc_check() { 26 | # pgrep -T "${daemon_rtable}" -q -xf "${pexp}" 27 | #} 28 | 29 | rc_reload() { 30 | ${rcexec} "${daemon} reload all" 31 | #pkill -HUP -T "${daemon_rtable}" -xf "${pexp}" 32 | } 33 | 34 | #rc_stop() { 35 | # pkill -T "${daemon_rtable}" -xf "${pexp}" 36 | #} 37 | 38 | #rc_post() { 39 | #} 40 | 41 | rc_cmd $1 42 | -------------------------------------------------------------------------------- /lib/templates/init-scripts/rcd.tpl: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # PROVIDE: pm2 4 | # REQUIRE: LOGIN 5 | # KEYWORD: shutdown 6 | 7 | . /etc/rc.subr 8 | 9 | name="%SERVICE_NAME%" 10 | rcvar="%SERVICE_NAME%_enable" 11 | 12 | start_cmd="pm2_start" 13 | stop_cmd="pm2_stop" 14 | reload_cmd="pm2_reload" 15 | status_cmd="pm2_status" 16 | extra_commands="reload status" 17 | 18 | pm2() 19 | { 20 | env PATH="$PATH:%NODE_PATH%" PM2_HOME="%HOME_PATH%" su -m "%USER%" -c "%PM2_PATH% $*" 21 | } 22 | 23 | pm2_start() 24 | { 25 | pm2 resurrect 26 | } 27 | 28 | pm2_stop() 29 | { 30 | pm2 kill 31 | } 32 | 33 | pm2_reload() 34 | { 35 | pm2 reload all 36 | } 37 | 38 | pm2_status() 39 | { 40 | pm2 list 41 | } 42 | 43 | load_rc_config $name 44 | run_rc_command "$1" 45 | -------------------------------------------------------------------------------- /lib/templates/init-scripts/systemd-online.tpl: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=PM2 process manager 3 | Documentation=https://pm2.keymetrics.io/ 4 | After=network-online.target 5 | Restart=on-failure 6 | 7 | [Service] 8 | Type=forking 9 | User=%USER% 10 | LimitNOFILE=infinity 11 | LimitNPROC=infinity 12 | LimitCORE=infinity 13 | Environment=PATH=%NODE_PATH%:/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin 14 | Environment=PM2_HOME=%HOME_PATH% 15 | PIDFile=%HOME_PATH%/pm2.pid 16 | 17 | ExecStart=%PM2_PATH% resurrect 18 | ExecReload=%PM2_PATH% reload all 19 | ExecStop=%PM2_PATH% kill 20 | 21 | [Install] 22 | WantedBy=network-online.target 23 | -------------------------------------------------------------------------------- /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 | Restart=on-failure 16 | 17 | ExecStart=%PM2_PATH% resurrect 18 | ExecReload=%PM2_PATH% reload all 19 | ExecStop=%PM2_PATH% kill 20 | 21 | [Install] 22 | WantedBy=multi-user.target 23 | -------------------------------------------------------------------------------- /lib/templates/logrotate.d/pm2: -------------------------------------------------------------------------------- 1 | %HOME_PATH%/pm2.log %HOME_PATH%/logs/*.log { 2 | rotate 12 3 | weekly 4 | missingok 5 | notifempty 6 | compress 7 | delaycompress 8 | copytruncate 9 | create 0640 %USER% %USER% 10 | } 11 | -------------------------------------------------------------------------------- /lib/templates/sample-apps/http-server/README.md: -------------------------------------------------------------------------------- 1 | 2 | # Basic HTTP Server and Cluster mode 3 | 4 | In this boilerplate it will start an http server in cluster mode. 5 | 6 | You can check the content of the ecosystem.config.js on how to start mutliple instances of the same HTTP application in order to get the most from your working system. 7 | 8 | ## Via CLI 9 | 10 | Via CLI you can start any HTTP/TCP application in cluster mode with: 11 | 12 | ```bash 13 | $ pm2 start api.js -i max 14 | ``` 15 | -------------------------------------------------------------------------------- /lib/templates/sample-apps/http-server/api.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', server.address().port); 9 | }); 10 | -------------------------------------------------------------------------------- /lib/templates/sample-apps/http-server/ecosystem.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | apps : [{ 3 | name: 'API', 4 | script: 'api.js', 5 | instances: 4, 6 | max_memory_restart: '1G', 7 | env: { 8 | NODE_ENV: 'development' 9 | }, 10 | env_production: { 11 | NODE_ENV: 'production' 12 | } 13 | }] 14 | }; 15 | -------------------------------------------------------------------------------- /lib/templates/sample-apps/http-server/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "simple-http-server", 3 | "version": "1.0.0", 4 | "description": "Simple HTTP server that can be used in cluster mode", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC" 11 | } 12 | -------------------------------------------------------------------------------- /lib/templates/sample-apps/pm2-plus-metrics-actions/ecosystem.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | apps : [{ 3 | name: 'Custom Metrics', 4 | script: 'custom-metrics.js', 5 | env: { 6 | NODE_ENV: 'development' 7 | }, 8 | env_production: { 9 | NODE_ENV: 'production' 10 | } 11 | }] 12 | }; 13 | -------------------------------------------------------------------------------- /lib/templates/sample-apps/pm2-plus-metrics-actions/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "pm2-plus-custom-metrics", 3 | "version": "1.0.0", 4 | "description": "Example that shows how to use pm2+ custom metrics", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC" 11 | } 12 | -------------------------------------------------------------------------------- /lib/templates/sample-apps/python-app/README.md: -------------------------------------------------------------------------------- 1 | 2 | # Managing a Python Application 3 | 4 | On this boilerlate you will see how you can start a Python application with PM2. 5 | -------------------------------------------------------------------------------- /lib/templates/sample-apps/python-app/echo.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | import time 3 | 4 | while 1: 5 | print("Start : %s" % time.ctime()) 6 | print("second line") 7 | time.sleep(1) 8 | -------------------------------------------------------------------------------- /lib/templates/sample-apps/python-app/ecosystem.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | apps : [{ 3 | name: 'API', 4 | script: 'echo.py', 5 | env: { 6 | NODE_ENV: 'development' 7 | }, 8 | env_production: { 9 | NODE_ENV: 'production' 10 | } 11 | }] 12 | }; 13 | -------------------------------------------------------------------------------- /lib/templates/sample-apps/python-app/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "python-app", 3 | "version": "1.0.0", 4 | "description": "Example on how to manage a Python application with PM2", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC" 11 | } 12 | -------------------------------------------------------------------------------- /lib/tools/IsAbsolute.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | function posix(path) { 4 | return path.charAt(0) === '/'; 5 | } 6 | 7 | function win32(path) { 8 | // https://github.com/nodejs/node/blob/b3fcc245fb25539909ef1d5eaa01dbf92e168633/lib/path.js#L56 9 | var splitDeviceRe = /^([a-zA-Z]:|[\\/]{2}[^\\/]+[\\/]+[^\\/]+)?([\\/])?([\s\S]*?)$/; 10 | var result = splitDeviceRe.exec(path); 11 | var device = result[1] || ''; 12 | var isUnc = Boolean(device && device.charAt(1) !== ':'); 13 | 14 | // UNC paths are always absolute 15 | return Boolean(result[2] || isUnc); 16 | } 17 | 18 | module.exports = process.platform === 'win32' ? win32 : posix; 19 | module.exports.posix = posix; 20 | module.exports.win32 = win32; 21 | -------------------------------------------------------------------------------- /lib/tools/deleteFolderRecursive.js: -------------------------------------------------------------------------------- 1 | 2 | const fs = require('fs'); 3 | const Path = require('path'); 4 | 5 | const deleteFolderRecursive = function(path) { 6 | if (fs.existsSync(path)) { 7 | fs.readdirSync(path).forEach((file, index) => { 8 | const curPath = Path.join(path, file); 9 | if (fs.lstatSync(curPath).isDirectory()) { // recurse 10 | deleteFolderRecursive(curPath); 11 | } else { // delete file 12 | fs.unlinkSync(curPath); 13 | } 14 | }); 15 | fs.rmdirSync(path); 16 | } 17 | }; 18 | 19 | module.exports = deleteFolderRecursive 20 | -------------------------------------------------------------------------------- /packager/alpine/pm2_io.rsa.pub: -------------------------------------------------------------------------------- 1 | -----BEGIN PUBLIC KEY----- 2 | MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAugt3OP2U2VjgY1VvlxyC 3 | qP33UT96MMulFzjthMJD57VU4yBzjoboIDjc1AIVjEiCXDktxNezFiqG/MHMh/nl 4 | DVB/zvNI8CpNte250+iwSwADZZGh+Fy9V1vFARVOXZhHB7V/QXsuHoT0QXTyY4Ss 5 | 9RiS5AMHJzK1CRAZrfivAiGN7j6+G6dz2vnDIK6Q3OVpS5ssV3+44Hx7itBKXCls 6 | cvhjI4GGcZGf3K26oHfNwh1WjVT4L0Yjox5B8kN4tzif9fhKSCinnynfUZbyeSBA 7 | 4gU1cE4twQneXdc1NtPPrSOHz5THNmmQXqNNQ7sEv88LBRutcnph7IuuHEes1J/Q 8 | AwIDAQAB 9 | -----END PUBLIC KEY----- 10 | -------------------------------------------------------------------------------- /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 | # First run that print a banner 18 | node dist/bin/pm2 --version 19 | 20 | # cleanup 21 | find -name "*~" -delete 22 | 23 | # fix chmod 24 | chmod 755 `find -name LICENSE` 25 | chmod a+x `find -name "*.sh"` 26 | 27 | tar -cvzf dist/pm2-v`node dist/bin/pm2 --version`.tar.gz dist/* 28 | shasum -a 256 dist/pm2-*.tar.gz 29 | -------------------------------------------------------------------------------- /packager/debian/control: -------------------------------------------------------------------------------- 1 | Package: pm2 2 | Version: __VERSION__ 3 | Depends: nodejs (>= 6.12.2) 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: PM2 - Process Manager for Node.js. 12 | 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. 13 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /packager/debian/postinst: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | adduser --quiet --system \ 6 | --group --home /etc/pm2 \ 7 | --gecos "PM2 Process Manager" pm2 8 | 9 | if hash systemctl 2> /dev/null; then 10 | { 11 | systemctl enable "pm2.service" && \ 12 | systemctl start "pm2.service" 13 | } || echo "pm2 could not be registered or started" 14 | elif hash service 2> /dev/null; then 15 | service "pm2" start || echo "pm2 could not be registered or started" 16 | else 17 | echo 'Ingnoring pm2 auto-startup.' 18 | echo 'You can run `pm2 startup` as root to do it manually.' 19 | fi 20 | -------------------------------------------------------------------------------- /packager/debian/postrm: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | deluser --quiet pm2 || true 4 | -------------------------------------------------------------------------------- /packager/debian/prerm: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if hash systemctl 2> /dev/null; then 4 | systemctl disable "pm2.service" && \ 5 | systemctl stop "pm2.service" || \ 6 | echo "pm2 wasn't even running!" 7 | elif hash service 2> /dev/null; then 8 | service "pm2" stop || echo "pm2 wasn't even running!" 9 | else 10 | echo "Your system does not appear to use upstart, systemd or sysv, so pm2 could not be stopped" 11 | echo 'Unless these systems were removed since install, no processes have been left running' 12 | fi 13 | -------------------------------------------------------------------------------- /packager/publish_deb_rpm.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | REPOSITORY_NAME="keymetrics/pm2" 4 | 5 | for OSDIST in 'ubuntu/trusty' 'ubuntu/xenial' 'ubuntu/yakkety' 'ubuntu/zesty' 'ubuntu/artful' 'debian/wheezy' 'debian/jessie' 'debian/stretch' 'debian/buster' 'raspbian/wheezy' 'raspbian/jessie' 'raspbian/stretch' 'raspbian/buster' 6 | do 7 | package_cloud push $REPOSITORY_NAME/$OSDIST `find -name "*.deb"` 8 | done 9 | 10 | for OSDIST in 'el/5' 'el/6' 'el/7' 'poky/jethro' 'poky/krogoth' 11 | do 12 | package_cloud push $REPOSITORY_NAME/$OSDIST `find -name "*.rpm"` 13 | done 14 | 15 | -------------------------------------------------------------------------------- /packager/rhel/postinst: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | mkdir -p /etc/pm2 6 | 7 | adduser --system \ 8 | --home-dir /etc/pm2 \ 9 | --comment "PM2 Process Manager" pm2 10 | 11 | chown -R pm2:pm2 /etc/pm2 12 | 13 | if hash systemctl 2> /dev/null; then 14 | { 15 | systemctl enable "pm2.service" && \ 16 | systemctl start "pm2.service" 17 | } || echo "pm2 could not be registered or started" 18 | elif hash service 2> /dev/null; then 19 | service "pm2" start || echo "pm2 could not be registered or started" 20 | else 21 | echo 'Ingnoring pm2 auto-startup.' 22 | echo 'You can run `pm2 startup` as root to do it manually.' 23 | fi 24 | -------------------------------------------------------------------------------- /packager/rhel/postrm: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | userdel pm2 || true 4 | groupdel pm2 || true 5 | -------------------------------------------------------------------------------- /packager/rhel/prerm: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if hash systemctl 2> /dev/null; then 4 | systemctl disable "pm2.service" && \ 5 | systemctl stop "pm2.service" || \ 6 | echo "pm2 wasn't even running!" 7 | elif hash service 2> /dev/null; then 8 | service "pm2" stop || echo "pm2 wasn't even running!" 9 | else 10 | echo "Your system does not appear to use upstart, systemd or sysv, so pm2 could not be stopped" 11 | echo 'Unless these systems were removed since install, no processes have been left running' 12 | fi 13 | -------------------------------------------------------------------------------- /pm2: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | DIR="$(dirname "$(readlink -f "$0")")" 4 | $DIR/node/bin/node $DIR/bin/pm2 $@ 5 | -------------------------------------------------------------------------------- /pres/bttn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/socketio/pm2/311c53298448fc4575fc689c4943692a664373ad/pres/bttn.png -------------------------------------------------------------------------------- /pres/cluster-support.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/socketio/pm2/311c53298448fc4575fc689c4943692a664373ad/pres/cluster-support.png -------------------------------------------------------------------------------- /pres/cluster.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/socketio/pm2/311c53298448fc4575fc689c4943692a664373ad/pres/cluster.png -------------------------------------------------------------------------------- /pres/legacy-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/socketio/pm2/311c53298448fc4575fc689c4943692a664373ad/pres/legacy-logo.png -------------------------------------------------------------------------------- /pres/pm2-dev.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/socketio/pm2/311c53298448fc4575fc689c4943692a664373ad/pres/pm2-dev.png -------------------------------------------------------------------------------- /pres/pm2-list.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/socketio/pm2/311c53298448fc4575fc689c4943692a664373ad/pres/pm2-list.png -------------------------------------------------------------------------------- /pres/pm2-ls-multi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/socketio/pm2/311c53298448fc4575fc689c4943692a664373ad/pres/pm2-ls-multi.png -------------------------------------------------------------------------------- /pres/pm2-ls-v2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/socketio/pm2/311c53298448fc4575fc689c4943692a664373ad/pres/pm2-ls-v2.png -------------------------------------------------------------------------------- /pres/pm2-monit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/socketio/pm2/311c53298448fc4575fc689c4943692a664373ad/pres/pm2-monit.png -------------------------------------------------------------------------------- /pres/pm2-plus_black.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/socketio/pm2/311c53298448fc4575fc689c4943692a664373ad/pres/pm2-plus_black.png -------------------------------------------------------------------------------- /pres/pm2-v2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/socketio/pm2/311c53298448fc4575fc689c4943692a664373ad/pres/pm2-v2.png -------------------------------------------------------------------------------- /pres/pm2-v3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/socketio/pm2/311c53298448fc4575fc689c4943692a664373ad/pres/pm2-v3.png -------------------------------------------------------------------------------- /pres/pm2-v4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/socketio/pm2/311c53298448fc4575fc689c4943692a664373ad/pres/pm2-v4.png -------------------------------------------------------------------------------- /pres/pm2-versioning-metadata.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/socketio/pm2/311c53298448fc4575fc689c4943692a664373ad/pres/pm2-versioning-metadata.png -------------------------------------------------------------------------------- /pres/pm2.20d3ef.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/socketio/pm2/311c53298448fc4575fc689c4943692a664373ad/pres/pm2.20d3ef.png -------------------------------------------------------------------------------- /pres/schema.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/socketio/pm2/311c53298448fc4575fc689c4943692a664373ad/pres/schema.png -------------------------------------------------------------------------------- /pres/vitals.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/socketio/pm2/311c53298448fc4575fc689c4943692a664373ad/pres/vitals.png -------------------------------------------------------------------------------- /test/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:alpine 2 | 3 | RUN mkdir -p /var/pm2 4 | 5 | WORKDIR /var/pm2 6 | 7 | ENV NODE_ENV test 8 | ENV PM2_DISCRETE_MODE true 9 | 10 | RUN apk update && apk add bash git curl python python3 php5 && rm -rf /var/cache/apk/* 11 | RUN ln -s /usr/bin/php5 /usr/bin/php 12 | RUN npm install -g mocha@3.5 13 | 14 | CMD ["mocha", "./test/programmatic/api.mocha.js"] 15 | -------------------------------------------------------------------------------- /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/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/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/docker_parallel_test.sh: -------------------------------------------------------------------------------- 1 | set -e 2 | 3 | docker build -t pm2-test -f test/Dockerfile . 4 | 5 | JOBS=2 6 | OPTS="--jobs $JOBS --joblog joblog-X docker run -v `pwd`:/var/pm2 pm2-test" 7 | 8 | ls test/e2e/cli/* | parallel $OPTS bash 9 | 10 | #ls test/e2e/binaries/* test/e2e/modules/* test/e2e/internal/* test/e2e/process-file/* test/e2e/cli/* test/e2e/logs/* | parallel $OPTS bash 11 | -------------------------------------------------------------------------------- /test/e2e/cli/attach.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | SRC=$(cd $(dirname "$0"); pwd) 4 | source "${SRC}/../include.sh" 5 | 6 | cd $file_path/stdin 7 | 8 | $pm2 start stdin.js -o out-rel.log --merge-logs 9 | >out-rel.log 10 | 11 | # Send LINE\n to stdin application 12 | $pm2 send 0 "LINE" 13 | 14 | cat out-rel.log 15 | grep "LINE" out-rel.log 16 | spec "Should have reveived line" 17 | 18 | $pm2 delete all 19 | -------------------------------------------------------------------------------- /test/e2e/cli/dump.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 | should 'should have 4 apps started' 'online' 4 10 | 11 | rm -f ~/.pm2/dump.pm2 ~/.pm2/dump.pm2.bak 12 | $pm2 save 13 | spec "should save process list" 14 | ls ~/.pm2/dump.pm2 15 | spec "dump file should exist" 16 | ls ~/.pm2/dump.pm2.bak 17 | ispec "dump backup file should not exist" 18 | 19 | $pm2 save 20 | spec "should save and backup process list" 21 | ls ~/.pm2/dump.pm2 22 | spec "dump file should exist" 23 | ls ~/.pm2/dump.pm2.bak 24 | spec "dump backup file should exist" 25 | -------------------------------------------------------------------------------- /test/e2e/cli/ecosystem.e2e.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | SRC=$(cd $(dirname "$0"); pwd) 4 | source "${SRC}/../include.sh" 5 | 6 | cd $file_path/ecosystem 7 | 8 | $pm2 start ecosystem.config.js 9 | -------------------------------------------------------------------------------- /test/e2e/cli/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 start app in fork mode' 'fork_mode' 1 11 | 12 | $pm2 restart echo.js 13 | should 'should has restarted app' 'restart_time: 1' 1 14 | 15 | ########### Fork mode 16 | $pm2 kill 17 | 18 | $pm2 start bashscript.sh 19 | should 'should start app in fork mode' '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/e2e/cli/mjs.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | SRC=$(cd $(dirname "$0"); pwd) 4 | source "${SRC}/../include.sh" 5 | 6 | cd $file_path/mjs 7 | 8 | # Activate test only for Node > 9.0.0 9 | node -e "require('semver').gte(process.versions.node, '9.0.0') ? process.exit(0) : process.exit(1)" 10 | [ $? -eq 0 ] || exit 0 11 | 12 | $pm2 start --node-args="--experimental-modules" index.mjs -o outech.log -e errech.log 13 | >outech.log 14 | >errech.log 15 | sleep 1 16 | should 'should app be online in fork mode with MJS support' 'online' 1 17 | 18 | $pm2 delete all 19 | 20 | $pm2 start --node-args="--experimental-modules" -i 2 index.mjs 21 | sleep 1 22 | should 'should app be online in cluster mode with MJS support' 'online' 2 23 | -------------------------------------------------------------------------------- /test/e2e/cli/monit.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 link xxx aaa 9 | 10 | $pm2 start http.js -i 4 11 | spec "should start 4 processes" 12 | 13 | $pm2 monitor 0 14 | should 'should monitoring flag enabled (id)' '_km_monitored: true' 1 15 | 16 | $pm2 unmonitor 0 17 | should 'should monitoring flag disabled (id)' '_km_monitored: false' 1 18 | 19 | $pm2 monitor http 20 | should 'should monitoring flag enabled (name)' '_km_monitored: true' 4 21 | 22 | $pm2 unmonitor http 23 | should 'should monitoring flag disabled (name)' '_km_monitored: false' 4 24 | 25 | $pm2 monitor all 26 | should 'should monitoring flag enabled ' '_km_monitored: true' 4 27 | 28 | $pm2 unmonitor all 29 | should 'should monitoring flag disabled (name)' '_km_monitored: false' 4 30 | -------------------------------------------------------------------------------- /test/e2e/cli/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 | ## Start 9 | $pm2 start child.js echo.js server.js 10 | should 'should app be online' 'online' 3 11 | 12 | ## Restart 13 | $pm2 restart child echo server 14 | should 'should app be online' 'online' 3 15 | should 'should all script been restarted one time' 'restart_time: 1' 3 16 | 17 | ## Stop 18 | $pm2 stop child echo server 19 | should 'should app be stopped' 'stopped' 3 20 | 21 | ## Delete 22 | $pm2 delete child echo server 23 | shouldnot 'should app be deleted' 'stopped' 3 24 | -------------------------------------------------------------------------------- /test/e2e/cli/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 | -------------------------------------------------------------------------------- /test/e2e/cli/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 | cat all.json | $pm2 start - 12 | should 'should start processes' 'online' 6 13 | 14 | cat all.json | $pm2 delete - 15 | should 'should delete all processes' 'name' 0 16 | -------------------------------------------------------------------------------- /test/e2e/cli/plus.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 9 | $pm2 prettylist | grep "km_link: false" 10 | spec "should km_link not be enabled" 11 | 12 | $pm2 plus alcz82ewyhy2va6 litfrsovr52celr --install-all 13 | 14 | should 'have started 3 apps' 'online' 3 15 | should 'all application be monitored' 'km_link: true' 3 16 | 17 | $pm2 plus delete 18 | 19 | should 'have started 1 apps' 'online' 1 20 | $pm2 prettylist | grep "km_link: false" 21 | spec "should km_link be disabled" 22 | -------------------------------------------------------------------------------- /test/e2e/cli/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 | should 'should have 4 apps started' 'online' 4 10 | 11 | $pm2 save 12 | $pm2 resurrect 13 | spec "should resurrect from dump" 14 | should 'should have still 4 apps started' 'online' 4 15 | 16 | $pm2 save 17 | $pm2 delete all 18 | echo "[{" > ~/.pm2/dump.pm2 19 | $pm2 resurrect 20 | spec "should resurrect from backup if dump is broken" 21 | ls ~/.pm2/dump.pm2 22 | ispec "should delete broken dump" 23 | should 'should have still 4 apps started' 'online' 4 24 | 25 | $pm2 delete all 26 | $pm2 resurrect 27 | spec "should resurrect from backup if dump is missing" 28 | should 'should have still 4 apps started' 'online' 4 29 | -------------------------------------------------------------------------------- /test/e2e/cli/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 | $pm2 kill 9 | 10 | $pm2 restart BULLSHIT 11 | ispec "Unknown process = error exit" 12 | 13 | $pm2 restart 666 14 | ispec "Unknown process = error exit" 15 | 16 | $pm2 restart all 17 | ispec "No process = error exit" 18 | 19 | $pm2 stop all 20 | ispec "No process = error exit" 21 | 22 | $pm2 delete 10 23 | ispec "No process = error exit" 24 | 25 | $pm2 delete toto 26 | ispec "No process = error exit" 27 | -------------------------------------------------------------------------------- /test/e2e/cli/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/e2e/cli/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/e2e/internals/daemon-paths-override.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | SRC=$(cd $(dirname "$0"); pwd) 4 | source "${SRC}/../include.sh" 5 | 6 | $pm2 kill 7 | rm /tmp/.toto.pid 8 | 9 | ########### Override PM2 pid path 10 | PM2_PID_FILE_PATH=/tmp/.toto.pid $pm2 ls 11 | 12 | sleep 2 13 | test -f /tmp/.toto.pid 14 | 15 | spec 'should have picked the pm2 pid path' 16 | -------------------------------------------------------------------------------- /test/e2e/internals/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 | $pm2 reload all & 14 | sleep 2 15 | should 'should have started 1 clustered app' 'online' 1 16 | should 'should restart processes with new name' 'restart_time: 1' 1 17 | -------------------------------------------------------------------------------- /test/e2e/internals/options-via-env.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 | # With start 10 | $pm2 start echo.js 11 | should 'should deep_monitoring' 'deep_monitoring' 0 12 | 13 | $pm2 delete all 14 | 15 | PM2_DEEP_MONITORING=true $pm2 start echo.js 16 | should 'should deep_monitoring' 'deep_monitoring' 1 17 | 18 | $pm2 delete all 19 | 20 | # With restart 21 | $pm2 start echo.js 22 | should 'should deep_monitoring' 'deep_monitoring' 0 23 | PM2_DEEP_MONITORING=true $pm2 restart echo 24 | should 'should deep_monitoring' 'deep_monitoring' 1 25 | -------------------------------------------------------------------------------- /test/e2e/internals/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 | cd start-consistency; 11 | 12 | $pm2 start child.js 13 | 14 | LINE_NB_CLI=`$pm2 prettylist | wc -l` 15 | 16 | $pm2 delete all 17 | 18 | $pm2 start child.json 19 | 20 | LINE_NB_JSON=`$pm2 prettylist | wc -l` 21 | 22 | $pm2 prettylist | grep "vizion: true" 23 | spec "Vizion" 24 | 25 | 26 | # if [ $LINE_NB_JSON -eq $LINE_NB_CLI ] 27 | # then 28 | # success "Starting a basic JSON is consistent with CLI start" 29 | # else 30 | # fail "Starting a basic JSON is NOT consistent with CLI start" 31 | # fi 32 | -------------------------------------------------------------------------------- /test/e2e/internals/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/e2e/logs/log-create-not-exist-dir.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | SRC=$( 4 | cd $(dirname "$0") 5 | pwd 6 | ) 7 | source "${SRC}/../include.sh" 8 | 9 | cd $file_path/log-create-not-exist-dir/ 10 | 11 | LOG_PATH_PREFIX="${SRC}/__log-create-not-exist-dir__" 12 | 13 | # a long path directory, to make sure that creating the directory is using synchronous mode 14 | # if using asynchronous mode, creating the long path directory would fail. 15 | LOG_FILE="${LOG_PATH_PREFIX}/a-deep/path/which/should/cost/lots/of/time/to/create/the/directory/out-rel.log" 16 | rm -rf "${LOG_PATH_PREFIX}" 17 | $pm2 start echo.js -o ${LOG_FILE} 18 | 19 | spec "Should have the exit code 0"; 20 | 21 | sleep 2 22 | 23 | grep "start" ${LOG_FILE} 24 | 25 | spec "Should have 'start' in the log file" 26 | 27 | cd ${SRC} 28 | rm -rf "${LOG_PATH_PREFIX}" 29 | $pm2 delete all 30 | -------------------------------------------------------------------------------- /test/e2e/logs/log-reload.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | SRC=$(cd $(dirname "$0"); pwd) 3 | source "${SRC}/../include.sh" 4 | 5 | cd $file_path 6 | 7 | ## FORK MODE 8 | 9 | $pm2 kill 10 | 11 | $pm2 start echo.js -o out-rel.log -e err-rel.log -x --merge-logs 12 | 13 | sleep 2 14 | 15 | grep "echo.js" out-rel.log 16 | spec "Should have written te right stuff in out log in fork mode" 17 | 18 | grep "echo.js-error" err-rel.log 19 | spec "Should have written te right stuff in err log in fork mode" 20 | 21 | rm out-rel.log 22 | rm err-rel.log 23 | 24 | $pm2 reloadLogs 25 | spec "Should have reloaded logs via CLI" 26 | 27 | sleep 1 28 | 29 | grep "echo.js" out-rel.log 30 | spec "(RELOADED) Should have written the right stuff in out log in fork mode" 31 | 32 | grep "echo.js-error" err-rel.log 33 | spec "(RELOADED) Should have written the right stuff in err log in fork mode" 34 | 35 | rm out-rel.log 36 | rm err-rel.log 37 | -------------------------------------------------------------------------------- /test/e2e/misc/instance-number.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 server.js -i -100 8 | should 'should have started 1 processes' 'online' 1 9 | 10 | $pm2 delete all 11 | -------------------------------------------------------------------------------- /test/e2e/misc/port-release.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 cluster-pm2.json 8 | should 'should have started 4 processes' 'online' 4 9 | 10 | $pm2 reload cluster-pm2.json 11 | should 'should have started 4 processes' 'online' 4 12 | -------------------------------------------------------------------------------- /test/e2e/misc/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 | $pm2 startup upstart -u $USER --hp $HOME --service-name abcdef 14 | spec "should startup command generation exited succesfully with custom service-name" 15 | test -e /etc/init.d/abcdef 16 | spec "should have generated upstart file with custom service-name" 17 | $pm2 unstartup upstart --service-name abcdef 18 | spec "should have disabled startup with custom service-name" 19 | ! test -e /etc/init.d/abcdef 20 | spec "should have deleted upstart file with custom service-name" 21 | 22 | $pm2 startup upstart -u $USER --hp $HOME 23 | spec "should startup command generation exited succesfully" 24 | test -e /etc/init.d/pm2-$USER 25 | spec "should have generated upstart file" 26 | $pm2 unstartup upstart 27 | spec "should have disabled startup" 28 | ! test -e /etc/init.d/pm2-$USER 29 | spec "should have deleted upstart file" 30 | -------------------------------------------------------------------------------- /test/e2e/misc/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 | -------------------------------------------------------------------------------- /test/e2e/modules/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 get 15 | 16 | $pm2 set key1 val1 17 | cat ~/.pm2/module_conf.json | grep "key1" 18 | spec "Should key exists" 19 | 20 | $pm2 unset key1 21 | cat ~/.pm2/module_conf.json | grep "key1" 22 | ispec "Should key does not exist" 23 | 24 | rm -rf ~/.pm2 25 | -------------------------------------------------------------------------------- /test/e2e/process-file/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 15 | -------------------------------------------------------------------------------- /test/e2e/process-file/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 9 | -------------------------------------------------------------------------------- /test/fixtures/001-test.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | setInterval(function() { 5 | console.log('log message from echo.js'); 6 | console.error('err msg from echo.js'); 7 | }, 50); 8 | -------------------------------------------------------------------------------- /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/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/app-config-update/args1.json: -------------------------------------------------------------------------------- 1 | { 2 | "script" : "echo.js", 3 | "node_args" : "" 4 | } 5 | -------------------------------------------------------------------------------- /test/fixtures/app-config-update/args2.json: -------------------------------------------------------------------------------- 1 | { 2 | "script" : "echo.js", 3 | "node_args" : "--harmony" 4 | } 5 | -------------------------------------------------------------------------------- /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/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/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/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/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/bashscript.sh: -------------------------------------------------------------------------------- 1 | while true; do 2 | ls -l 3 | sleep 5 4 | done 5 | 6 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /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/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/binary-py-file.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | while True: 4 | print 'hello' 5 | time.sleep(1) 6 | -------------------------------------------------------------------------------- /test/fixtures/c-compile/hello.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | // printf() displays the string inside quotation 5 | printf("Hello World\n"); 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /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/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/child_no_http.js: -------------------------------------------------------------------------------- 1 | var pmx = require('@pm2/io').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/cluster-alias.json: -------------------------------------------------------------------------------- 1 | { 2 | "apps": [{ 3 | "name" : "serv-clust", 4 | "script" : "server.js", 5 | "instances" : "4", 6 | "exec_mode" : "cluster", 7 | "env_test" : { 8 | "NODE_ENV" : "TEST" 9 | } 10 | }] 11 | } 12 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /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/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/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/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", "index.js"] 15 | -------------------------------------------------------------------------------- /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", "index.js"] 16 | -------------------------------------------------------------------------------- /test/fixtures/cron-stop.js: -------------------------------------------------------------------------------- 1 | setTimeout(() => { 2 | process.exit(0) 3 | }, 1000) 4 | -------------------------------------------------------------------------------- /test/fixtures/cron.js: -------------------------------------------------------------------------------- 1 | 2 | setInterval(function() { 3 | console.log('ok'); 4 | }, 500); 5 | -------------------------------------------------------------------------------- /test/fixtures/cron_no_autorestart.js: -------------------------------------------------------------------------------- 1 | console.log('ok') 2 | -------------------------------------------------------------------------------- /test/fixtures/custom_actions/index.js: -------------------------------------------------------------------------------- 1 | 2 | var pmx = require('@pm2/io'); 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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /test/fixtures/docker/expressor/Dockerfile.bak: -------------------------------------------------------------------------------- 1 | FROM keymetrics/pm2:latest 2 | 3 | RUN mkdir -p /var/app 4 | 5 | WORKDIR /var/app 6 | 7 | COPY ./package.json /var/app 8 | RUN npm install 9 | ## DEVELOPMENT MODE 10 | ENV NODE_ENV=development 11 | CMD ["pm2-dev", "process.json", "--env", "development"] -------------------------------------------------------------------------------- /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/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/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/docker/expressor/worker.js: -------------------------------------------------------------------------------- 1 | 2 | setInterval(function() { 3 | console.log('Worker finished his job'); 4 | }, 1000); 5 | -------------------------------------------------------------------------------- /test/fixtures/echo-env.js: -------------------------------------------------------------------------------- 1 | 2 | setInterval(function() { 3 | console.log(process.env.ECHO_MSG || 'ok'); 4 | }, 100); 5 | -------------------------------------------------------------------------------- /test/fixtures/echo-pm2.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "echo", 3 | "script" : "echo.js", 4 | "options": [""] 5 | } 6 | -------------------------------------------------------------------------------- /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/echo-to-pm2.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "echo-to", 3 | "script" : "echo-to.js", 4 | "options": [""] 5 | } 6 | -------------------------------------------------------------------------------- /test/fixtures/echo.coffee: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env coffee 2 | 3 | setInterval (-> console.log 'ok'), 500 -------------------------------------------------------------------------------- /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/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/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/echoto-pm2.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "echoto", 3 | "script" : "echoto.js", 4 | "options": [""] 5 | } 6 | -------------------------------------------------------------------------------- /test/fixtures/ecosystem.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | apps : [{ 3 | script: 'index.js', 4 | watch: '.' 5 | }, { 6 | script: './service-worker/', 7 | watch: ['./service-worker'] 8 | }], 9 | 10 | deploy : { 11 | production : { 12 | user : 'SSH_USERNAME', 13 | host : 'SSH_HOSTMACHINE', 14 | ref : 'origin/master', 15 | repo : 'GIT_REPOSITORY', 16 | path : 'DESTINATION_PATH', 17 | 'pre-deploy-local': '', 18 | 'post-deploy' : 'npm install && pm2 reload ecosystem.config.js --env production', 19 | 'pre-setup': '' 20 | } 21 | } 22 | }; 23 | -------------------------------------------------------------------------------- /test/fixtures/ecosystem/ecosystem.config.js: -------------------------------------------------------------------------------- 1 | 2 | module.exports = { 3 | script: 'unknown.js' 4 | } 5 | -------------------------------------------------------------------------------- /test/fixtures/empty.js: -------------------------------------------------------------------------------- 1 | setInterval(function () {}, 1000); 2 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /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/env-switching/child.js: -------------------------------------------------------------------------------- 1 | 2 | setInterval(function() { 3 | console.log(process.env.NODE_ENV); 4 | }, 1000); 5 | -------------------------------------------------------------------------------- /test/fixtures/env.js: -------------------------------------------------------------------------------- 1 | setInterval(function() { 2 | console.log(process.env.TEST_VARIABLE); 3 | }, 100); 4 | -------------------------------------------------------------------------------- /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/esmodules/mjs/circle.mjs: -------------------------------------------------------------------------------- 1 | const PI = 3.14159265359; 2 | 3 | export function area(radius) { 4 | return (radius ** 2) * PI; 5 | } 6 | 7 | export function circumference(radius) { 8 | return 2 * radius * PI; 9 | } 10 | -------------------------------------------------------------------------------- /test/fixtures/esmodules/mjs/index.mjs: -------------------------------------------------------------------------------- 1 | import { area, circumference } from './circle.mjs'; 2 | 3 | const r = 3; 4 | 5 | console.log(`Circle with radius ${r} has 6 | area: ${area(r)}; 7 | circunference: ${circumference(r)}`); 8 | 9 | setInterval(() => { 10 | }, 1000) 11 | -------------------------------------------------------------------------------- /test/fixtures/esmodules/packagemodule/circle.js: -------------------------------------------------------------------------------- 1 | const PI = 3.14159265359; 2 | 3 | export function area(radius) { 4 | return (radius ** 2) * PI; 5 | } 6 | 7 | export function circumference(radius) { 8 | return 2 * radius * PI; 9 | } 10 | -------------------------------------------------------------------------------- /test/fixtures/esmodules/packagemodule/index.js: -------------------------------------------------------------------------------- 1 | import { area, circumference } from './circle.js'; 2 | 3 | const r = 3; 4 | 5 | console.log(`Circle with radius ${r} has 6 | area: ${area(r)}; 7 | circunference: ${circumference(r)}`); 8 | 9 | setInterval(() => { 10 | }, 1000) 11 | -------------------------------------------------------------------------------- /test/fixtures/esmodules/packagemodule/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "import", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "type":"module", 7 | "scripts": { 8 | "test": "echo \"Error: no test specified\" && exit 1" 9 | }, 10 | "author": "", 11 | "license": "ISC" 12 | } 13 | -------------------------------------------------------------------------------- /test/fixtures/events/custom_action.js: -------------------------------------------------------------------------------- 1 | 2 | var axm = require('@pm2/io'); 3 | 4 | axm.action('refresh:db', function(reply) { 5 | console.log('Refreshing'); 6 | reply({success : true, subobj : { a : 'b'}}); 7 | }); 8 | -------------------------------------------------------------------------------- /test/fixtures/events/custom_action_with_params.js: -------------------------------------------------------------------------------- 1 | 2 | var axm = require('@pm2/io'); 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/events/own_event.js: -------------------------------------------------------------------------------- 1 | 2 | var axm = require('@pm2/io'); 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/extra-lang/app-python.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | apps : [{ 3 | name: 'echo-python-1', 4 | cmd: 'echo.py', 5 | max_memory_restart: '1G', 6 | env: { 7 | NODE_ENV: 'development' 8 | }, 9 | env_production : { 10 | NODE_ENV: 'production' 11 | } 12 | },{ 13 | name: 'echo-python-max', 14 | cmd: 'echo.py', 15 | instances: 4, 16 | env: { 17 | NODE_ENV: 'development' 18 | }, 19 | env_production : { 20 | NODE_ENV: 'production' 21 | } 22 | }] 23 | }; 24 | -------------------------------------------------------------------------------- /test/fixtures/extra-lang/apps.json: -------------------------------------------------------------------------------- 1 | { 2 | apps: [{ 3 | "interpreter" : "/usr/bin/python3", 4 | "name" : "echo-python", 5 | "script" : "echo.py", 6 | "log" : "python-app.log", 7 | "combine_logs" : true, 8 | "env" : { 9 | DEFAULT_STR : "Python" 10 | }, 11 | "env_production" : { 12 | DEFAULT_STR : "PythonProduction" 13 | } 14 | }, { 15 | "exec_interpreter" : "/usr/bin/php", 16 | "name" : "echo-php", 17 | "script" : "echo.php", 18 | "output" : "php-app-out.log", 19 | "error" : "php-error.log", 20 | "combine_logs" : true 21 | }] 22 | } 23 | -------------------------------------------------------------------------------- /test/fixtures/extra-lang/echo.php: -------------------------------------------------------------------------------- 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/git/COMMIT_EDITMSG: -------------------------------------------------------------------------------- 1 | first commit 2 | -------------------------------------------------------------------------------- /test/fixtures/git/HEAD: -------------------------------------------------------------------------------- 1 | ref: refs/heads/master 2 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /test/fixtures/git/description: -------------------------------------------------------------------------------- 1 | Unnamed repository; edit this file 'description' to name the repository. 2 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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/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/git/index: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/socketio/pm2/311c53298448fc4575fc689c4943692a664373ad/test/fixtures/git/index -------------------------------------------------------------------------------- /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/git/logs/HEAD: -------------------------------------------------------------------------------- 1 | 0000000000000000000000000000000000000000 7ae6d7c64d39da2167c33993e1f4f0233e8eb6f0 jshkurti 1429209718 +0200 commit (initial): first commit 2 | -------------------------------------------------------------------------------- /test/fixtures/git/logs/refs/heads/master: -------------------------------------------------------------------------------- 1 | 0000000000000000000000000000000000000000 7ae6d7c64d39da2167c33993e1f4f0233e8eb6f0 jshkurti 1429209718 +0200 commit (initial): first commit 2 | -------------------------------------------------------------------------------- /test/fixtures/git/logs/refs/remotes/origin/master: -------------------------------------------------------------------------------- 1 | 0000000000000000000000000000000000000000 7ae6d7c64d39da2167c33993e1f4f0233e8eb6f0 jshkurti 1429209819 +0200 update by push 2 | -------------------------------------------------------------------------------- /test/fixtures/git/objects/5d/a45b6659e5cba8f444616f4e18529ad5dde72f: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/socketio/pm2/311c53298448fc4575fc689c4943692a664373ad/test/fixtures/git/objects/5d/a45b6659e5cba8f444616f4e18529ad5dde72f -------------------------------------------------------------------------------- /test/fixtures/git/objects/7a/e6d7c64d39da2167c33993e1f4f0233e8eb6f0: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/socketio/pm2/311c53298448fc4575fc689c4943692a664373ad/test/fixtures/git/objects/7a/e6d7c64d39da2167c33993e1f4f0233e8eb6f0 -------------------------------------------------------------------------------- /test/fixtures/git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/socketio/pm2/311c53298448fc4575fc689c4943692a664373ad/test/fixtures/git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 -------------------------------------------------------------------------------- /test/fixtures/git/refs/heads/master: -------------------------------------------------------------------------------- 1 | 7ae6d7c64d39da2167c33993e1f4f0233e8eb6f0 2 | -------------------------------------------------------------------------------- /test/fixtures/git/refs/remotes/origin/master: -------------------------------------------------------------------------------- 1 | 7ae6d7c64d39da2167c33993e1f4f0233e8eb6f0 2 | -------------------------------------------------------------------------------- /test/fixtures/graceful-exit-no-listen.js: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Example of graceful exit that does not listen 4 | * 5 | * $ pm2 reload 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/graceful-exit-send.js: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Example of graceful exit that does not listen but sends 'online' 4 | * 5 | * $ pm2 reload 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 reload 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/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/homogen-json-action/http.js: -------------------------------------------------------------------------------- 1 | var pmx = require('@pm2/io').init({ 2 | http : true 3 | }); 4 | 5 | var http = require('http'); 6 | 7 | var server = http.createServer(function(req, res) { 8 | res.writeHead(200); 9 | res.end('hey'); 10 | }).listen(8000, function() { 11 | console.log('App listening on port 8000'); 12 | }); 13 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /test/fixtures/increment-var/sample.js: -------------------------------------------------------------------------------- 1 | 2 | setInterval(function () {}, 1000); 3 | -------------------------------------------------------------------------------- /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/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/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 | -------------------------------------------------------------------------------- /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/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/insidePm2Process.js: -------------------------------------------------------------------------------- 1 | setInterval(function(){ 2 | console.log(process.env.TEST_VARIABLE); 3 | }, 500); -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /test/fixtures/interface/human_event.js: -------------------------------------------------------------------------------- 1 | 2 | var axm = require('@pm2/io'); 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/interface/log_out.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | console.log('outmsg'); 4 | 5 | console.error('errmsg'); 6 | 7 | setInterval(function() {}, 100); 8 | -------------------------------------------------------------------------------- /test/fixtures/interface/process_exception.js: -------------------------------------------------------------------------------- 1 | 2 | var axm = require('@pm2/io'); 3 | 4 | axm.catchAll(); 5 | 6 | setTimeout(function() { 7 | throw new Error('Exit'); 8 | }, 200); 9 | -------------------------------------------------------------------------------- /test/fixtures/interface/process_exception_with_logs.js: -------------------------------------------------------------------------------- 1 | 2 | var pmx = require('@pm2/io'); 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/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/interpreter/echo.coffee: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env coffee 2 | 3 | setInterval (-> console.log 'ok'), 500 -------------------------------------------------------------------------------- /test/fixtures/interpreter/echo.ls: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env lsc 2 | 3 | setInterval (-> console.log 'Hello Livescript!'), 500 4 | -------------------------------------------------------------------------------- /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/js-configuration/app.js: -------------------------------------------------------------------------------- 1 | 2 | setInterval(function() { 3 | console.log('ok'); 4 | }, 1000); 5 | -------------------------------------------------------------------------------- /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/json-reload/echo-env.js: -------------------------------------------------------------------------------- 1 | 2 | setInterval(function() { 3 | console.log(process.env.ECHO_MSG || 'ok'); 4 | }, 100); 5 | -------------------------------------------------------------------------------- /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/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/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 | -------------------------------------------------------------------------------- /test/fixtures/killnotsofast.js: -------------------------------------------------------------------------------- 1 | setInterval(function() { 2 | console.log('ALIVE'); 3 | }, 500); 4 | -------------------------------------------------------------------------------- /test/fixtures/killtoofast.js: -------------------------------------------------------------------------------- 1 | 2 | setInterval(function() { 3 | console.log('BOUM'); 4 | process.exit(1); 5 | }, 30); 6 | -------------------------------------------------------------------------------- /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 | }, 1000); 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/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/log-create-not-exist-dir/echo.js: -------------------------------------------------------------------------------- 1 | console.log("start"); 2 | setInterval(function () { 3 | console.log("tick"); 4 | }, 50); 5 | -------------------------------------------------------------------------------- /test/fixtures/log-json/one-echo.js: -------------------------------------------------------------------------------- 1 | console.log('echo') -------------------------------------------------------------------------------- /test/fixtures/mjs/ecosystem.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | 3 | apps : [ 4 | 5 | 6 | { 7 | name : 'Test es6 modules', 8 | script : 'index.mjs', 9 | node_args : '--experimental-modules' 10 | } 11 | ], 12 | 13 | 14 | }; 15 | -------------------------------------------------------------------------------- /test/fixtures/mjs/index.mjs: -------------------------------------------------------------------------------- 1 | import {test} from './test' 2 | 3 | test(); 4 | -------------------------------------------------------------------------------- /test/fixtures/mjs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "test-es6-pm2", 3 | "version": "1.0.0", 4 | "description": "A simple project to test pm2 es6-modules pm2 support", 5 | "main": "index.mjs", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1", 8 | "start": "node --experimental-modules index.mjs" 9 | }, 10 | "keywords": [ 11 | "es6-modules", 12 | "import", 13 | "export", 14 | "pm2" 15 | ], 16 | "author": "vpotseluyko", 17 | "license": "ISC" 18 | } 19 | -------------------------------------------------------------------------------- /test/fixtures/mjs/test.mjs: -------------------------------------------------------------------------------- 1 | export function test() { 2 | setInterval(() => console.log(`Hello es6 from pm2`), 1000); 3 | } 4 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /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/fixtures/no-restart.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name" : "no_restart_app", 4 | "script" : "./killtoofast.js", 5 | "autorestart" : false 6 | } 7 | ] 8 | -------------------------------------------------------------------------------- /test/fixtures/no-vizion.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name" : "no_vizion", 4 | "script" : "./echo.js", 5 | "vizion" : false 6 | } 7 | ] 8 | -------------------------------------------------------------------------------- /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/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/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /test/fixtures/path-resolution/ecosystem3.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-cluster", 9 | script : "./echo.js", 10 | out_file : 'echo-out.log', 11 | error_file : 'echo-err.log', 12 | instances: 4 13 | } 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /test/fixtures/path1/iminpath1.js: -------------------------------------------------------------------------------- 1 | 2 | console.log(process.cwd()); 3 | -------------------------------------------------------------------------------- /test/fixtures/path1/path2/iminpath2.js: -------------------------------------------------------------------------------- 1 | 2 | console.log(process.cwd()); 3 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/pm2-dev/exited_app.js: -------------------------------------------------------------------------------- 1 | 2 | throw new Error('exit') 3 | -------------------------------------------------------------------------------- /test/fixtures/pm2-ecosystem.json: -------------------------------------------------------------------------------- 1 | { 2 | "pm2" : [{ 3 | "name" : "echo", 4 | "script" : "./echo.js" 5 | },{ 6 | "name" : "child", 7 | "script" : "./child.js", 8 | "instances" : "4", 9 | "error_file" : "./child-err.log", 10 | "out_file" : "./child-out.log" 11 | },{ 12 | "name" : "api-2", 13 | "script" : "./server.js" 14 | }] 15 | } 16 | -------------------------------------------------------------------------------- /test/fixtures/process.json: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /test/fixtures/promise/empty-rejection.js: -------------------------------------------------------------------------------- 1 | 2 | setTimeout(function() { 3 | Promise.reject(); 4 | }, 1000); 5 | 6 | setInterval(function() { 7 | }, 1000); 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 | -------------------------------------------------------------------------------- /test/fixtures/push.json: -------------------------------------------------------------------------------- 1 | [{ 2 | "name" : "push", 3 | "script" : "echo.js", 4 | "max" : "1" 5 | }] 6 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /test/fixtures/quit.js: -------------------------------------------------------------------------------- 1 | 2 | console.log('HEY!'); 3 | 4 | setTimeout(function() { 5 | process.exit(1); 6 | }, 3000); 7 | -------------------------------------------------------------------------------- /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/serve/404.html: -------------------------------------------------------------------------------- 1 | your file doesnt exist believe me -------------------------------------------------------------------------------- /test/fixtures/serve/ecosystem-serve.json: -------------------------------------------------------------------------------- 1 | { 2 | "static": [ 3 | { 4 | "path": ".", 5 | "spa": true, 6 | "basic_auth": { 7 | "username": "user", 8 | "password": "pass" 9 | }, 10 | "port": 8081 11 | } 12 | ] 13 | } -------------------------------------------------------------------------------- /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/serve/index.html: -------------------------------------------------------------------------------- 1 | good shit right there -------------------------------------------------------------------------------- /test/fixtures/serve/other.html: -------------------------------------------------------------------------------- 1 | iam another file 2 | with 2 lines 3 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /test/fixtures/signal-send.js: -------------------------------------------------------------------------------- 1 | 2 | setInterval(function() { 3 | }, 1000); 4 | 5 | process.on('message', function (msg) { 6 | console.log(msg); 7 | }); 8 | -------------------------------------------------------------------------------- /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/signals/delayed_send.js: -------------------------------------------------------------------------------- 1 | 2 | setInterval(function() { 3 | // Do nothing to keep process alive 4 | }, 1000); 5 | 6 | process.on('message', function (msg) { 7 | if (msg === 'shutdown') { 8 | console.log('shutdown message received but forbid exit'); 9 | } 10 | }); 11 | -------------------------------------------------------------------------------- /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 but forbid exit'); 8 | }); 9 | -------------------------------------------------------------------------------- /test/fixtures/sort/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 | -------------------------------------------------------------------------------- /test/fixtures/sort/other.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 | -------------------------------------------------------------------------------- /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 | }, 1000); 7 | //# sourceMappingURL=main.js.map 8 | -------------------------------------------------------------------------------- /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"} -------------------------------------------------------------------------------- /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/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"} -------------------------------------------------------------------------------- /test/fixtures/start-app/ecosystem.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | apps : [{ 3 | cmd: "node -e 'setTimeout(function() { }, 100000); console.log(process.env.TEST)'", 4 | log: 'test-conf.log', 5 | merge_logs: true, 6 | env: { 7 | TEST: 'test_val' 8 | } 9 | }] 10 | }; 11 | -------------------------------------------------------------------------------- /test/fixtures/start-app/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 | -------------------------------------------------------------------------------- /test/fixtures/start-consistency/child.js: -------------------------------------------------------------------------------- 1 | 2 | require('@pm2/io').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 | -------------------------------------------------------------------------------- /test/fixtures/start-consistency/child.json: -------------------------------------------------------------------------------- 1 | { 2 | script:"./child.js", 3 | name :"child" 4 | } 5 | -------------------------------------------------------------------------------- /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/startProcessInsidePm2.json: -------------------------------------------------------------------------------- 1 | [{ 2 | "name" : "masterProcess", 3 | "script" : "./startProcessInsidePm2.js", 4 | "exec_mode" : "fork_mode", 5 | "min_uptime" : "100", 6 | "max_restarts" : "50" 7 | }] -------------------------------------------------------------------------------- /test/fixtures/stdin/stdin.js: -------------------------------------------------------------------------------- 1 | 2 | const readline = require('readline'); 3 | 4 | const rl = readline.createInterface({ 5 | input: process.stdin, 6 | output: process.stdout 7 | }); 8 | 9 | rl.prompt(); 10 | 11 | rl.on('line', function(line) { 12 | console.log('Line %s received', line); 13 | }); 14 | 15 | setInterval(function() { 16 | }, 100); 17 | -------------------------------------------------------------------------------- /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 | 10 | setInterval(function() { 11 | process.stdout.write('outwrite', 'utf8', function() { 12 | console.log('outcb'); 13 | }); 14 | 15 | process.stderr.write('errwrite', 'utf8', function() { 16 | console.log('errcb'); 17 | }); 18 | }, 1000) 19 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /test/fixtures/throw-string.js: -------------------------------------------------------------------------------- 1 | 2 | function crash() { 3 | throw 'crashed'; 4 | } 5 | 6 | crash(); 7 | -------------------------------------------------------------------------------- /test/fixtures/throw.js: -------------------------------------------------------------------------------- 1 | 2 | throw new Error('Exit error message'); 3 | -------------------------------------------------------------------------------- /test/fixtures/toto.js: -------------------------------------------------------------------------------- 1 | 2 | console.log(process.env.TOTO); 3 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /test/fixtures/watch/app-watch-rename.json: -------------------------------------------------------------------------------- 1 | { 2 | apps: [{ 3 | script : 'http.js', 4 | name : 'http', 5 | watch : true 6 | }] 7 | } 8 | -------------------------------------------------------------------------------- /test/fixtures/watch/app-watch.json: -------------------------------------------------------------------------------- 1 | { 2 | apps: [{ 3 | script : 'http.js', 4 | name : 'http', 5 | watch : true 6 | }] 7 | } 8 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/fixtures/watcher/donotwatchme.dir/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/socketio/pm2/311c53298448fc4575fc689c4943692a664373ad/test/fixtures/watcher/donotwatchme.dir/.gitkeep -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /test/fixtures/watcher/watchme.sym: -------------------------------------------------------------------------------- 1 | ./donotwatchme.dir -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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/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/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/yaml-configuration/malformated.yml: -------------------------------------------------------------------------------- 1 | { 2 | "ASDSDASD": "ASDSADSAD" 3 | } 4 | -------------------------------------------------------------------------------- /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/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/interface/mocha.opts: -------------------------------------------------------------------------------- 1 | --timeout 25000 2 | -------------------------------------------------------------------------------- /test/pm2_check_dependencies.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | SRC=$(cd $(dirname "$0"); pwd) 4 | 5 | # Abort script at first error 6 | set -e 7 | 8 | echo "Checking dependencies ...."; 9 | 10 | 11 | dependencies=("php" "nvm" "node" "python"); 12 | declare -A depCmd; 13 | depCmd=([nvm]="echo $NVM_DIR >/dev/null"); 14 | 15 | 16 | error=false; 17 | 18 | for i in "${dependencies[@]}"; do 19 | currentDepInstalled=true; 20 | 21 | if [ ${depCmd[$i]+_} ]; then 22 | eval ${depCmd[$i]} || { error=true; currentDepInstalled=false;} 23 | else 24 | command -v $i >/dev/null 2>&1 || { error=true; currentDepInstalled=false;} 25 | fi 26 | 27 | if [ "$currentDepInstalled" = true ]; then 28 | echo -e '\E[32m'"\033[1m[OK]\033[0m" $i; 29 | else 30 | echo -e '\E[31m'"\033[1m[KO]\033[0m" $i; 31 | fi 32 | done 33 | 34 | 35 | if [ "$error" = true ]; then 36 | echo "Aborting."; 37 | exit 1; 38 | fi 39 | 40 | 41 | -------------------------------------------------------------------------------- /test/programmatic/fixtures/auto-restart/throw.js: -------------------------------------------------------------------------------- 1 | throw new Error('err') 2 | -------------------------------------------------------------------------------- /test/programmatic/fixtures/exp-backoff/throw-stable.js: -------------------------------------------------------------------------------- 1 | 2 | if (parseInt(process.env.restart_time) === 5) { 3 | return setInterval(function() { 4 | console.log('Im stable mamen') 5 | }, 1000) 6 | } 7 | 8 | throw new Error('Ugly error') 9 | -------------------------------------------------------------------------------- /test/programmatic/fixtures/exp-backoff/throw.js: -------------------------------------------------------------------------------- 1 | throw new Error('Ugly error') 2 | -------------------------------------------------------------------------------- /test/programmatic/fixtures/instances/echo.js: -------------------------------------------------------------------------------- 1 | 2 | setInterval(function() { 3 | console.log('OK') 4 | }, 1000) 5 | -------------------------------------------------------------------------------- /test/programmatic/fixtures/instances/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(8008, function() { 8 | console.log('App listening on port %d', server.address().port); 9 | }); 10 | -------------------------------------------------------------------------------- /test/programmatic/fixtures/json-env-passing/echo.js: -------------------------------------------------------------------------------- 1 | 2 | setInterval(function() { 3 | console.log(process.env.JSONTEST); 4 | }, 50); 5 | -------------------------------------------------------------------------------- /test/programmatic/fixtures/json-env-passing/ecosystem.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | apps : [{ 3 | script: 'echo.js', 4 | env: { 5 | JSONTEST: { si: 'si' } 6 | }, 7 | env_production: { 8 | NODE_ENV: 'production' 9 | } 10 | }], 11 | 12 | deploy : { 13 | production : { 14 | user : 'node', 15 | host : '212.83.163.1', 16 | ref : 'origin/master', 17 | repo : 'git@github.com:repo.git', 18 | path : '/var/www/production', 19 | 'post-deploy' : 'npm install && pm2 reload ecosystem.config.js --env production' 20 | } 21 | } 22 | }; 23 | -------------------------------------------------------------------------------- /test/programmatic/fixtures/tar-module/mono-app-module/README.md: -------------------------------------------------------------------------------- 1 | 2 | To start http application in cluster mode: 3 | 4 | ```bash 5 | $ pm2 start ecosystem.config.js 6 | # OR 7 | $ pm2 start http.js -i max 8 | ``` 9 | -------------------------------------------------------------------------------- /test/programmatic/fixtures/tar-module/mono-app-module/ecosystem.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | name: 'envision', 3 | apps : [{ 4 | name : 'clustered_http', 5 | script : './http.js', 6 | instances : 'max', 7 | exec_mode : 'cluster', 8 | env : { 9 | PORT : 8002 10 | } 11 | }, { 12 | name : 'forked_app', 13 | script : './http.js', 14 | env : { 15 | PORT : 8001 16 | } 17 | }] 18 | } 19 | -------------------------------------------------------------------------------- /test/programmatic/fixtures/tar-module/mono-app-module/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', server.address().port); 9 | }); 10 | -------------------------------------------------------------------------------- /test/programmatic/fixtures/tar-module/mono-app-module/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mono-app-module", 3 | "version": "0.23.0", 4 | "pm2": [{ 5 | "name" : "mono_app", 6 | "script": "http.js", 7 | "env" : { 8 | "PORT" : "8008" 9 | } 10 | }] 11 | } 12 | -------------------------------------------------------------------------------- /test/programmatic/fixtures/tar-module/multi-app-module/README.md: -------------------------------------------------------------------------------- 1 | 2 | To start http application in cluster mode: 3 | 4 | ```bash 5 | $ pm2 start ecosystem.config.js 6 | # OR 7 | $ pm2 start http.js -i max 8 | ``` 9 | -------------------------------------------------------------------------------- /test/programmatic/fixtures/tar-module/multi-app-module/ecosystem.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | name: 'envision', 3 | apps : [{ 4 | name : 'clustered_http', 5 | script : './http.js', 6 | instances : 'max', 7 | exec_mode : 'cluster', 8 | env : { 9 | PORT : 8002 10 | } 11 | }, { 12 | name : 'forked_app', 13 | script : './http.js', 14 | env : { 15 | PORT : 8001 16 | } 17 | }] 18 | } 19 | -------------------------------------------------------------------------------- /test/programmatic/fixtures/tar-module/multi-app-module/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', server.address().port); 9 | }); 10 | -------------------------------------------------------------------------------- /test/programmatic/fixtures/tar-module/multi-app-module/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "multi-app-module", 3 | "version": "0.1", 4 | "pm2": [{ 5 | "name" : "first_app", 6 | "script": "http.js", 7 | "env" : { 8 | "PORT" : "8005" 9 | } 10 | }, { 11 | "name" : "second_app", 12 | "script" : "./http.js", 13 | "env" : { 14 | "PORT" : "8002" 15 | } 16 | }] 17 | } 18 | -------------------------------------------------------------------------------- /test/programmatic/fixtures/version-test/index.js: -------------------------------------------------------------------------------- 1 | 2 | setInterval(function() { 3 | console.log('HEY') 4 | }, 1000) 5 | -------------------------------------------------------------------------------- /test/programmatic/fixtures/version-test/package.json: -------------------------------------------------------------------------------- 1 | {"name":"version-module","version":"1.0.0","description":"","main":"index.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"author":"","license":"ISC"} -------------------------------------------------------------------------------- /test/programmatic/internal_config.mocha.js: -------------------------------------------------------------------------------- 1 | 2 | const PM2 = require('../..'); 3 | const should = require('should'); 4 | 5 | describe('Internal PM2 configuration', function() { 6 | var pm2 7 | 8 | before(function() { 9 | pm2 = new PM2.custom(); 10 | }) 11 | 12 | it('should set pm2:registry', function(done) { 13 | pm2.set('pm2:registry', 'http://thing.com', done) 14 | }) 15 | 16 | it('should new instance have the configuration', function() { 17 | var pm3 = new PM2.custom(); 18 | 19 | pm3.connect(() => { 20 | should(pm2.user_conf.registry).eql('http://thing.com') 21 | }) 22 | }) 23 | }) 24 | -------------------------------------------------------------------------------- /test/programmatic/sys_infos.mocha.js: -------------------------------------------------------------------------------- 1 | 2 | const Sysinfos = require('../../lib/Sysinfo/SystemInfo.js') 3 | const should = require('should'); 4 | const path = require('path') 5 | 6 | describe('Sysinfos', function() { 7 | var sysinfo 8 | 9 | after(() => { 10 | sysinfo.kill() 11 | }) 12 | 13 | it('should start a failing app in fork mode', function(done) { 14 | sysinfo = new Sysinfos() 15 | sysinfo.fork() 16 | done() 17 | }) 18 | 19 | it('should query procs', function(done) { 20 | 21 | setTimeout(() => { 22 | sysinfo.query((err, data) => { 23 | console.log(data) 24 | done() 25 | }) 26 | 27 | }, 500) 28 | }) 29 | 30 | }) 31 | -------------------------------------------------------------------------------- /types/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "lib": ["es6"], 5 | "noImplicitAny": true, 6 | "noImplicitThis": true, 7 | "strictNullChecks": true, 8 | 9 | // If the library is an external module (uses `export`), this allows your test file to import "mylib" instead of "./index". 10 | // If the library is global (cannot be imported via `import` or `require`), leave this out. 11 | "baseUrl": ".", 12 | "paths": { "mylib": ["."] } 13 | } 14 | } 15 | --------------------------------------------------------------------------------