{"id":31262721,"url":"https://github.com/aymenjd/pm2-restart-hook","last_synced_at":"2026-01-20T17:00:15.584Z","repository":{"id":315006004,"uuid":"1056917277","full_name":"AYMENJD/pm2-restart-hook","owner":"AYMENJD","description":"A PM2 module to automatically restart child processes when a parent app is restarted","archived":false,"fork":false,"pushed_at":"2025-09-21T08:01:52.000Z","size":33,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-30T22:47:49.338Z","etag":null,"topics":["manager","npm","pm2","pm2-module"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AYMENJD.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-09-15T03:07:47.000Z","updated_at":"2025-09-21T08:01:23.000Z","dependencies_parsed_at":"2025-09-16T07:09:59.854Z","dependency_job_id":"a1ef5f44-2f3e-4ce6-925c-351fe147f55b","html_url":"https://github.com/AYMENJD/pm2-restart-hook","commit_stats":null,"previous_names":["aymenjd/pm2-restart-hook"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/AYMENJD/pm2-restart-hook","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AYMENJD%2Fpm2-restart-hook","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AYMENJD%2Fpm2-restart-hook/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AYMENJD%2Fpm2-restart-hook/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AYMENJD%2Fpm2-restart-hook/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AYMENJD","download_url":"https://codeload.github.com/AYMENJD/pm2-restart-hook/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AYMENJD%2Fpm2-restart-hook/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28607624,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-20T16:10:39.856Z","status":"ssl_error","status_checked_at":"2026-01-20T16:10:39.493Z","response_time":117,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["manager","npm","pm2","pm2-module"],"created_at":"2025-09-23T11:51:34.509Z","updated_at":"2026-01-20T17:00:15.551Z","avatar_url":"https://github.com/AYMENJD.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pm2-restart-hook [![NPM Version](https://img.shields.io/npm/v/pm2-restart-hook?style=flat\u0026logo=npm)](https://www.npmjs.com/package/pm2-restart-hook) [![License](https://img.shields.io/npm/l/pm2-restart-hook?style=flat)](LICENSE)\n\nA simple and lightweight PM2 module that creates a parent-child dependency between your applications, automatically restarting child processes when their designated parent application is restarted\n\n### Features\n\n`pm2-restart-hook` offers several key features for better process management:\n\n-   **Dependency Management**: Easily create a parent-child relationship between any PM2-managed applications\n-   **Automated Cascading Restarts**: When a parent app restarts, all its children are automatically restarted\n-   **Highly Configurable**: Customize behavior using environment variables, with sensible defaults for zero-configuration use\n-   **Lightweight \u0026 Simple**: No external dependencies beyond PM2 itself\n\n### Requirements\n\n- PM2 v5.0.0+\n\n### Installation\n\nYou can install the module directly from NPM:\n\n```bash\npm2 install pm2-restart-hook\n```\n\n### How It Works\n\nThe hook identifies the parent-child relationship using a simple environment variable. When a parent application restarts, the hook finds all other applications that have their `PM2_PARENT_APP` environment variable set to the parent's name and restarts them\n\n### Usage Example\n\nThe best way to manage parent-child applications is with an `ecosystem.config.js` file\n\n1.  **Create your applications.** For this example, we'll use a placeholder script `dummy-app.js`\n2.  **Define the relationship in `ecosystem.config.js`:**\n\n```js\n// ecosystem.config.js\n\nmodule.exports = {\n  apps: [\n    // 1. The Parent Application\n    {\n      name: 'api-server',\n      script: 'api.js',\n      // Common reasons for automated restarts\n      max_memory_restart: '500M',\n      cron_restart: '0 2 * * *', // Restart every day at 2 AM\n    },\n\n    // 2. Child Worker #1\n    {\n      name: 'email-worker',\n      script: 'worker.js',\n      env: {\n        // This links the worker to its parent.\n        // The value MUST match the parent's 'name'.\n        PM2_PARENT_APP: 'api-server',\n      },\n    },\n\n    // 3. Child Worker #2\n    {\n      name: 'analytics-worker',\n      script: 'worker.js',\n      env: {\n        PM2_PARENT_APP: 'api-server',\n      },\n    },\n  ],\n};\n```\n\n3.  **Start your applications:**\n\n```bash\npm2 start ecosystem.config.js\n```\n\nNow, whenever `api-server` restarts (whether from its cron schedule, memory limit, or a manual command), `email-worker` and `analytics-worker` will be gracefully restarted one after another\n\n### Configuration\n\nYou can configure the hook's behavior by setting variables on the module itself using the `pm2 set` command\n\n| Environment Variable         | Description                                                                                             | Default            |\n| ---------------------------- | ------------------------------------------------------------------------------------------------------- | ------------------ |\n| `PARENT_ENV_KEY`             | The environment variable key used to identify the parent app                                            | `PM2_PARENT_APP`   |\n| `IGNORE_MANUAL_RESTARTS`     | If set to `true`, manual restarts (`pm2 restart \u003capp\u003e`) will be ignored                                 | `true`             |\n| `CHILD_RESTART_DELAY_MS`     | The delay in milliseconds between restarting each child process to prevent system overload              | `200`              |\n\n**Example of setting a configuration variable:**\n\n```bash\n# Make the hook to not ignore manual restarts\npm2 set pm2-restart-hook:IGNORE_MANUAL_RESTARTS false\n\n# Change the restart delay to 1 second\npm2 set pm2-restart-hook:CHILD_RESTART_DELAY_MS 1000\n```\n\n### Thanks To\n\n-   You for viewing or using this project\n-   The Keymetrics team for creating and maintaining the powerful PM2 process manager\n\n### License\n\nThis project is licensed under the MIT [License](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faymenjd%2Fpm2-restart-hook","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faymenjd%2Fpm2-restart-hook","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faymenjd%2Fpm2-restart-hook/lists"}