{"_id":"@codersyndicate/graceful-shutdown","_rev":"5-fd4dce39868df6e48ac0433814d0376e","name":"@codersyndicate/graceful-shutdown","dist-tags":{"latest":"1.1.1"},"versions":{"1.0.0":{"name":"@codersyndicate/graceful-shutdown","version":"1.0.0","description":"Module that listens on posix signals and gracefully shutdowns the given server","main":"index.js","license":"MIT","repository":{"type":"git","url":"git+https://github.com/CoderSyndicate/nodejs-graceful-shutdown.git"},"bugs":{"url":"https://github.com/CoderSyndicate/nodejs-graceful-shutdown/issues"},"homepage":"https://github.com/CoderSyndicate/nodejs-graceful-shutdown","scripts":{"test":"mocha ./test --exit"},"dependencies":{"async":"^3.2.0","http-shutdown":"^1.2.2"},"devDependencies":{"chai":"^4.3.4","mocha":"^9.0.1"},"gitHead":"8f4235033651754e0074b02312fc14f579a58289","_id":"@codersyndicate/graceful-shutdown@1.0.0","_nodeVersion":"14.17.0","_npmVersion":"6.14.13","dist":{"integrity":"sha512-gejNwufp2MtdCsg+zBwDiCEr+QH6QR36ApRkkacfJjniFhHPCW+H7Ks2KGPo+0fWedeKH1Jxsgoxh1s9yOm62w==","shasum":"65b7ada62cf32b605aebce5fe36e6e49200abaa5","tarball":"https://registry.npmjs.org/@codersyndicate/graceful-shutdown/-/graceful-shutdown-1.0.0.tgz","fileCount":8,"unpackedSize":41915,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJg0c6HCRA9TVsSAnZWagAA2QgP/0VBtfVaAzegM/nL/sCa\nvTLAXRv9pqIYxbNmzIEpVvvYBJbmUwoApNQmeryoceuEvcjAeSyiUNFtQ0bM\nYPeAibFMSBxBHJHE5BA4YIRFOJRLLGxbNb6KHigtvflRxSmTXecZ75i5uOUp\n8g00+OzFmJqtZdffWwTaPO+Sv59vpyiWYiKkug4Dz3ipRldkCldJl1Z0FpTl\nrZ+vdcdrFayAdwqhBdbDPGkPY/vctBr4FMaRBmSt5jDQbRI0jOJ8BRwC7Xqm\nVJnnoCPmGX+G7MkPusY1LnBDjXI8U2p3ow3uaz3xCw/14Qah5rykL36/xS3e\nWoW0tXD/xIQ0AJjQ8pLp6Oj2YTZMJA0NwsudnIJc35OlWerHPvzQjZsgJGXA\n4MHo9S4UShxQTDAk9wZgPBmrSj0MMLvCmD0peN7ZND+SlENcQKag6psCset3\nrrkbWq/zmaPX8tnS/5bzqYCzqTApYCi5niC4g/3XakWg0NDaSVVOIGW9k4Qc\n2/xkpl09GPGeeHVZen2i1sQi/PJboPm/Pr7/dN5Jn7AdH6/AiDR2O+g1Mdja\nbBlbMJQ41Daz1RGsLVqOGFLcYuwTvAFM6WCwHraCAH7nvcKxbj2brCU9iLSp\nSkeLCpl5KALYxwwZf8wqpMfEj6d8HpyanLZz4xaZyaHE3GTqoUMPHN2JHLTv\n9k7n\r\n=Oil+\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIAe0z+wzesOtFsAbos5hVCWb29GL2kBL7smqWw8MXsg4AiAR5Rd9PChYQuoOfR2ptuWvFPrnEOHDtNZeA/2Zv/si1w=="}]},"_npmUser":{"name":"luscus","email":"luscus.redbeard@gmail.com"},"directories":{},"maintainers":[{"name":"luscus","email":"luscus.redbeard@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/graceful-shutdown_1.0.0_1624362631292_0.1732887111626038"},"_hasShrinkwrap":false},"1.0.1":{"name":"@codersyndicate/graceful-shutdown","version":"1.0.1","description":"Module that listens on posix signals and gracefully shutdowns the given server","main":"index.js","license":"MIT","repository":{"type":"git","url":"git+https://github.com/CoderSyndicate/nodejs-graceful-shutdown.git"},"bugs":{"url":"https://github.com/CoderSyndicate/nodejs-graceful-shutdown/issues"},"homepage":"https://github.com/CoderSyndicate/nodejs-graceful-shutdown","keywords":["graceful","shutdown","finalizer","sigterm"],"scripts":{"test":"mocha ./test --exit"},"dependencies":{"async":"^3.2.0","http-shutdown":"^1.2.2"},"devDependencies":{"chai":"^4.3.4","mocha":"^9.0.1"},"gitHead":"d9722435811fd6cd7291402e888d8f78c0451c9b","_id":"@codersyndicate/graceful-shutdown@1.0.1","_nodeVersion":"14.17.0","_npmVersion":"6.14.13","dist":{"integrity":"sha512-vU6aZWrvOhS6JNeRAvJJmgL2DdCq8uo+H2Cgl2KFZhLFcj+K63EVlHUSIJqJil5zotXvV4HdbmJa4VOdNm5J9A==","shasum":"42de074bf6d04da47a0bec5afaa8e911f724c02f","tarball":"https://registry.npmjs.org/@codersyndicate/graceful-shutdown/-/graceful-shutdown-1.0.1.tgz","fileCount":8,"unpackedSize":42563,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJg0d6PCRA9TVsSAnZWagAA8UoP/RUw/d8Sk4xheUQb7kkr\nA2ZyVHcQpk1JoajSURHWCQgDfiURyYJpTQna/sXUronvBT2IsTM7QKhvVg+d\nxxM0iLZHQhOcZpGUIlSew98pZXs5Cek8a9ngfBz9vKBD0uEDF9No5vB6L9QF\n2KLxR0NihYiNm/kKRM/z7pWVUsZa4On63DqbXzC+vOtXJTAX81MXiAxTyMIh\nHXJramA/SWLfdxuAL9sKA9vos35wDcnenAK0WlMXeRx4gtzZgl9jLG0aX9P5\nOVzNPfijoDFICixwlaL9af8MWsH8WNRerlK+AAYM3CthpEK+9d0z24/7vsyy\nGNypVq8p8782QpXMsRbWjKEC+wyx/RchBZh0hdDQlSjF9hOeNZD04kHjXyYA\nqvdXtwTH8m2RVgpEjWQODGg3xDPSEqGG4N88OYtE/28QydIDXNXaE0VMmHYh\nLBgcBR7xcxn1rNJMNKjF0K8hahJ+JQMqJKlDaUFbuEirsu5OgApA6gPhfddn\nuN2an1V38dLe2Vq96sTTbwLUxNywY1XHHU6kK8m7miLEcjVCbUH6N+nA/Lws\n4Xx/v0jG7k3BMxmGrERH9phUowIeIQI7S2/dsPzfLVJjhGzptF2hqVIclt4W\nUq9R72iC+dLLjUqvYd86WntfJKxL49J9eOF0LouzKvtCLL9r/XimKKySogAs\nLaiE\r\n=rLq2\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCerns4f9PiyQZGQAkk4BS79bTX3HxRSWBTeApdKQSZ1QIhAMdsVmH2lr5FVvlpB5twmWa8MbJoN5VxN5CniU5Wm4MJ"}]},"_npmUser":{"name":"luscus","email":"luscus.redbeard@gmail.com"},"directories":{},"maintainers":[{"name":"luscus","email":"luscus.redbeard@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/graceful-shutdown_1.0.1_1624366735212_0.014508669024426712"},"_hasShrinkwrap":false},"1.0.2":{"name":"@codersyndicate/graceful-shutdown","version":"1.0.2","description":"Module that listens on posix signals and gracefully shutdowns the given server","main":"index.js","license":"MIT","repository":{"type":"git","url":"git+https://github.com/CoderSyndicate/nodejs-graceful-shutdown.git"},"bugs":{"url":"https://github.com/CoderSyndicate/nodejs-graceful-shutdown/issues"},"homepage":"https://github.com/CoderSyndicate/nodejs-graceful-shutdown","keywords":["graceful","shutdown","finalizer","sigterm"],"scripts":{"test":"mocha ./test --exit"},"dependencies":{"async":"^3.2.0","http-shutdown":"^1.2.2"},"devDependencies":{"chai":"^4.3.4","mocha":"^9.0.1"},"gitHead":"064ab876d533db2c634ce3ac2c9f19526959ddbc","_id":"@codersyndicate/graceful-shutdown@1.0.2","_nodeVersion":"14.17.0","_npmVersion":"6.14.13","dist":{"integrity":"sha512-vF2tfrNx3CA5Pu6DlahyURmRi6eXCuzSkDzsbKJsIEbf8I1dvLrfePRmjg1c/mENQr1T9LfRHMbFS3VEa4XC2w==","shasum":"7b00687cab3e4c48cc3acde002b2fb3b0823b7c2","tarball":"https://registry.npmjs.org/@codersyndicate/graceful-shutdown/-/graceful-shutdown-1.0.2.tgz","fileCount":8,"unpackedSize":42563,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJg0eMBCRA9TVsSAnZWagAAIoAQAJTLZ339rb4jig60W56D\nurE7alfZMQsLGCRLC0ZEA35v+nHV+MBBkjN6eUCSt8dI+kyVM+hm71ZHPyKS\no/57m5X1/SMEbbiWZgnKmPtIT+d2CRD/UIB6k2HH52tctvNjCFNsV4Tdg5NX\n5o6JTNEU6C7RFgLoXBTixdcdYYjgxQALTDhGnwk59sjOq79I0uLKiRr8bUo4\nf37ClfAKEcnRWPM2r2oDbvdSfDbXp9N71Ga5geq7QYvo8xvUachDDCTHKI2q\nJSbggZDawI4Mfow6lVRkvdyufjtKl9sgWL6UHWK9uKl76MPBgrZ1I9KzsCxd\nLG21fwjRbEtyt5o9Vb0QxfWYywIyBGuo5c8JTVyhkK+2VcfpaLKXgCO2qp08\nUR6w8mg/0ASftJdHF80qTtC8bfNgREaSFpx0euVbVQkzqrJXd7OYw7ZngJ6r\n0suY55tjrxQo6WgTlU8KIDDW7y1pSIuSMBjZotoHbrHF4OBEJ6Mbo6y5efxJ\nG7H5Vp40nYbEOnQq6SXaNqBjZDI/6oygM4xFYvkX7SvIMoEQzVvL2PSzfuhG\n2iQeyUgsXmTbUVsvMvQhMce5JuaQ27m6W+ITaMofXQuGv8hKs5ij60dbXjjY\nAyHt5OmEzz6dnRG61ESYrBpmGdw4Q6JoGdAE748U0RURcHCIHRtsnQ7wlCkC\nqJH6\r\n=ILj2\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGmUx5Vye4L7R5mQK6Xf5Mt/SiuV9Da8wmK4j6ix4885AiEAyIN+levVSJhXjzy7iIRVXJZkSuD/jppEuuaZMOMZLZI="}]},"_npmUser":{"name":"luscus","email":"luscus.redbeard@gmail.com"},"directories":{},"maintainers":[{"name":"luscus","email":"luscus.redbeard@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/graceful-shutdown_1.0.2_1624367873307_0.2697169250375451"},"_hasShrinkwrap":false},"1.1.0":{"name":"@codersyndicate/graceful-shutdown","version":"1.1.0","description":"Module that listens on posix signals and gracefully shutdowns the given server","main":"index.js","license":"MIT","repository":{"type":"git","url":"git+https://github.com/CoderSyndicate/nodejs-graceful-shutdown.git"},"bugs":{"url":"https://github.com/CoderSyndicate/nodejs-graceful-shutdown/issues"},"homepage":"https://github.com/CoderSyndicate/nodejs-graceful-shutdown","keywords":["graceful","shutdown","finalizer","sigterm"],"scripts":{"test":"mocha ./test --exit"},"dependencies":{"async":"^3.2.0","http-shutdown":"^1.2.2"},"devDependencies":{"chai":"^4.3.4","mocha":"^9.0.1"},"gitHead":"caadc30e873c9d2cbfdd6a72a4faf63fb7808cba","_id":"@codersyndicate/graceful-shutdown@1.1.0","_nodeVersion":"14.17.0","_npmVersion":"6.14.13","dist":{"integrity":"sha512-W/b+ZwYiKKw97mxhmXdyERFUUF1Mtzev1XYv3M7i9mMhZzK3H2g/A/hvX77FN6pGPd3T29FA2SyfJH4ZMeI0fA==","shasum":"d3bcd7fbf83ecb306ea459cdc7df51b15e52977c","tarball":"https://registry.npmjs.org/@codersyndicate/graceful-shutdown/-/graceful-shutdown-1.1.0.tgz","fileCount":8,"unpackedSize":50688,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJg5C7TCRA9TVsSAnZWagAAFXwP/3rz8MJbKKZ8CWoFoqqy\nu/B6x9Vuve5XO0SAYa2it66sfm4L468uKe9mvlp2bpYXIJTIItPS0J0BG61W\ndmMcOYZqGdGFB+1hEi4elnTt1hDswy3wm+kp/P0CzKBAeYp85lvg7at05anz\npQdilVKQiTFpB2GPtJSg7nKEHWVkxoyqI2EEgLhFB2eUHsjapxH3KcVFMs4I\nhd1Xbj9tjVTcAReVQAaBXQSX1gditXjPAG9vSq/oeef9XF6bbLKB0qax+UF7\nsASOMm7hykDZI8GmduXFXxc12QeQzEuMpt1Cw14FJc4s6OF5RWOEwGdwOCK8\nhkEemsuv6k6HtwvpJ9HRekTUkTaG8PVVi7MRU/Y9P3P8qSNqzJQTcwJbj2S2\nkL+GmXRSHLKS3ZkZWfOBLOLtZeXhBvOV+gahw4z2PTvUSf++YzkMCvzuXm/z\nLX7PAif1NASkH9aTMnho/lSqO7Ljl5rWj68DOp5SxDlE/Fh42AV/Z6VrhEJ+\n7ytbvTOAPMKUXg8XVJG98XitS66xKGQqmGi0YBWEOCsukgWSVKhklPtb22Wo\nOK+RSA/ct59r6YQpeUv1n2f8YWsGVTCoNRoaiWuzHneXtWC3wUXmb7ZafKTG\necmdbBpEZ42ssFdIyhCv44/YorwMu1lxk4ZlbhPaqwbMkxGONZe7PaZTHSiw\nH7qD\r\n=cmLl\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQD1enEq7hF9xzncik+JR5UZ1i4oMWoWRxkUEDby0Xk/uQIhAIPJFzKIS9FpuCZEjs64C7CAeLpW/0XUaOTV2DdtByul"}]},"_npmUser":{"name":"luscus","email":"luscus.redbeard@gmail.com"},"directories":{},"maintainers":[{"name":"luscus","email":"luscus.redbeard@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/graceful-shutdown_1.1.0_1625566930634_0.5541277337531048"},"_hasShrinkwrap":false},"1.1.1":{"name":"@codersyndicate/graceful-shutdown","version":"1.1.1","description":"Module that listens on posix signals and gracefully shutdowns the given server","main":"index.js","license":"MIT","repository":{"type":"git","url":"git+https://github.com/CoderSyndicate/nodejs-graceful-shutdown.git"},"bugs":{"url":"https://github.com/CoderSyndicate/nodejs-graceful-shutdown/issues"},"homepage":"https://github.com/CoderSyndicate/nodejs-graceful-shutdown","keywords":["graceful","shutdown","finalizer","sigterm"],"scripts":{"test":"mocha ./test --exit"},"dependencies":{"async":"^3.2.0","http-shutdown":"^1.2.2"},"devDependencies":{"chai":"^4.3.4","mocha":"^9.0.1"},"gitHead":"8c231a21d3fc5a5d4a54725649e4679fe532f60d","_id":"@codersyndicate/graceful-shutdown@1.1.1","_nodeVersion":"14.17.0","_npmVersion":"6.14.13","dist":{"integrity":"sha512-4hO+whs20hDgjCz7Tqg8GD2KdFTimkMT9mrZ588LeFusOTdJ+EQtF4NS+28tVXDGhuVpN7DlYnRu/wIK4WKvXQ==","shasum":"b62579e0f11e63f8d6013b617fc1cb81ae585eb6","tarball":"https://registry.npmjs.org/@codersyndicate/graceful-shutdown/-/graceful-shutdown-1.1.1.tgz","fileCount":8,"unpackedSize":50958,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJg5YUrCRA9TVsSAnZWagAAd9QP/1vGaqxBmFmhz/0/X8Zq\n3TndsuXcTt+NRmx2KHlxzAQigY7GyN7NY88E1sGgDDlGyYY1qwiCj7reQNOY\n0hlHLdYjE6cFTLyFr8ljHSpHFsG/FFk6E9dBmG/DIGJHxT3B3aV2rgD5uN1p\nnpshtSZjMSGAXsPDp+hfhTLA0ijir7k2JMDFhHMRa4aEsYzn+87WlK7qh3lL\nleB3GW8FBJvmvwwlt5XD5s7TH6m7dFoBjJ3cecPLhT7d3pgzFdi2DtaSwcDp\n3HCecnWOYuCaArhJU8AbgORl3ND9lct2GHmJNKmrTpC6fnU98C4BA+3JLpzr\ntpZE98PvKWyqliYo7eSMI8+8FHgWayTYt/UjLSiDhGodo+rwM0AjFAYh5/4c\n+uUO53sHjwUazhIeC+XE8Og1LPJF9GAVZa484sJv14a1lXn20rmaR/K1FQ6G\n4vOLiMGdiikmx+lvQ03Xs6rtJZoO3mUqVrVdg3VToDhnFsi+7uzzhj1vMe0p\n4EwM9HjXKXSOlChViekxzcVDDZDxNyuJpHJfopSmBp6GLFH7MrVuqAu1xTd/\nrPEGqUe7kXlELCYrM2UUbS9K1XDy4PBGAnRXh/d6iKypoZyGog/RtrJLD9t9\nNMQRlZBlwy5tWTTBYTJO5yRt4UxZVP6jbYYTiQzwPTWB7+iNuVZ9bD2CWzB7\nKIFr\r\n=DeAn\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGPnZ3JzMFOPN9iKt0X9LWWJ737p5UBHFPqMIaRZ8wVKAiAmCsYE1M0pUfW883xIMMz4xpMi0jrRsVRyT443Oc4UPA=="}]},"_npmUser":{"name":"luscus","email":"luscus.redbeard@gmail.com"},"directories":{},"maintainers":[{"name":"luscus","email":"luscus.redbeard@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/graceful-shutdown_1.1.1_1625654570621_0.32330601150209604"},"_hasShrinkwrap":false}},"time":{"created":"2021-06-22T11:50:31.113Z","1.0.0":"2021-06-22T11:50:31.439Z","modified":"2022-04-05T00:05:58.302Z","1.0.1":"2021-06-22T12:58:55.447Z","1.0.2":"2021-06-22T13:17:53.445Z","1.1.0":"2021-07-06T10:22:10.805Z","1.1.1":"2021-07-07T10:42:50.807Z"},"maintainers":[{"name":"luscus","email":"luscus.redbeard@gmail.com"}],"description":"Module that listens on posix signals and gracefully shutdowns the given server","homepage":"https://github.com/CoderSyndicate/nodejs-graceful-shutdown","repository":{"type":"git","url":"git+https://github.com/CoderSyndicate/nodejs-graceful-shutdown.git"},"bugs":{"url":"https://github.com/CoderSyndicate/nodejs-graceful-shutdown/issues"},"license":"MIT","readme":"graceful-shutdown\n====\n\n## Concept\n\nA Graceful Shutdown allows the process to finish processing pending responses and release used ressources before been killed\n\nIn Kubernetes a Service Pod can be killed any time due to scaling or any other automated/manual administration command,\nthe service process must be able to support the [Kubernetes Pod Lifecycle](https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/) by providing 2 probe routes: liveness and readiness\n\n- `liveness` only refects that the process exists, is stable and is accessible\n- `readiness` shows that the service dependencies (DB, ...) are available and is ready to process requests\n\nWhile `READY` a pod will be in the service pod pool to which the traffic is directed and will receive requests to process,\non the other hand while `NOT-READY` it will leave the pool, receive no new traffic and have a grace periode to finish processing\npending responses and release used resources (DB connections, ...) before been shut down\n\n## Features\n\n### Multi Framework Support\n\nThe graceful shutdown logic is applied to the [net.Server](https://nodejs.org/dist/latest-v16.x/docs/api/net.html#net_class_net_server) object,\nwhich means that all service frameworks should be supported.\n\n### Startup Readiness Checks\n\nFunction list that is used by the readiness route to assess if start conditions are met.\n\n### Shutdown Finalizers\n\nFunction list that has to be executed in parallel on shutdown.\nAs an example, you may want to push your metrics before shutdown in order to avoid metric gaps.\n\n\n## Flowchart\n\n![graceful-shutdown-flowchart](./Kubernetes-graceful-shutdown-flowchart.png)\n\n### Liveness\n\na route `/health` returning a Response Status `200` and Body `OK` as soon as the service port is open\n\n### Readiness\n\na route `/health/readiness` returning a Response Status `200` and Body `READY` as soon as\nall service dependencies are available (DB connections, ...), `503` and `NOT-READY` otherwise\n\n## Options\n\n- `gracePeriodMilliseconds`: grace period in milliseconds, must be longer than the average processing time (default: 5000)\n- `finalizers`: an array of functions, taking \"server\" and \"callback\" as arguments, to be executed on shutdown. \n\n## Knowledge\n\n- https://blog.laputa.io/graceful-shutdown-in-kubernetes-85f1c8d586da\n- https://blog.risingstack.com/graceful-shutdown-node-js-kubernetes/\n- https://cloud.google.com/blog/products/containers-kubernetes/kubernetes-best-practices-terminating-with-grace\n- https://expressjs.com/en/advanced/healthcheck-graceful-shutdown.html\n\n## Usage\n\n```javascript\nconst astalavista = require('@codersyndicate/graceful-shutdown');\nconst someDBLib = require('something'); // optional: service may have no dependencies\n\nconst options = {\n    gracePeriodMilliseconds: 10000,\n    finalizers: [\n        function doSomethingUseful(server, callback) {\n            console.log('i am dead...')\n            callback();\n        },\n    ],\n    readinessChecks: [\n        function checkDBReadiness(server, callback) {\n            if (ready) {\n                callback();\n                return;\n            }\n            \n            callback(new Error('DB not reachable'));\n        }\n    ],\n}\n\n// astalavista returns a ServerGracefulShutdown instance\nlet graceful = astalavista.enable(server, options);\n\nserver.use('/health', graceful.liveliness);\n\n// add a finalizer after initialisation\ngraceful.addFinalizer(function doSomethingEvenBetter(server, callback) {\n  console.log('i shall return! (famous last words)')\n  callback();\n});\n\n```\n\nyou have two possibilities to implement the readiness route\n\n```javascript\n// use existing readiness check handler\nserver.use('/health/readiness', graceful.readiness);\n\n// use a custom readiness check handler\nserver.use('/health/readiness', (req, res) => {\n    if (astalavista.isTerminated()) {\n        // service has been terminated by an external signal\n        // this condition is mandatory\n        return res.send(503, 'NOT-READY');\n    }\n\n    graceful.checkReadiness((error) => {\n        if (error !== undefined) {\n            response.send(503, 'NOT-READY');\n            return;\n        }\n\n        request.send(200, 'READY');\n    });\n});\n\n// add a readiness check after initialisation\ngraceful.addReadinessCheck(function checkSomethingElse(callback) {\n    console.log('does it work?')\n    callback();\n});\n\n```\n","readmeFilename":"README.md","keywords":["graceful","shutdown","finalizer","sigterm"]}