{"id":28502585,"url":"https://github.com/systemd/node-sd-notify","last_synced_at":"2025-10-29T02:37:09.936Z","repository":{"id":19154463,"uuid":"83549875","full_name":"systemd/node-sd-notify","owner":"systemd","description":"wrapper around sd_notify for using systemd as a node process manager","archived":false,"fork":false,"pushed_at":"2023-03-01T21:02:50.000Z","size":223,"stargazers_count":44,"open_issues_count":8,"forks_count":13,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-06-08T16:37:44.658Z","etag":null,"topics":["daemon","forever","nodemon","process","process-manager","sd-notify","systemd"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/sd-notify","language":"C++","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/systemd.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":"AUTHORS","dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-03-01T12:02:39.000Z","updated_at":"2025-05-30T16:59:57.000Z","dependencies_parsed_at":"2024-06-18T16:42:09.454Z","dependency_job_id":"d48949c5-b5d0-4eff-b0f1-86b247b4a35f","html_url":"https://github.com/systemd/node-sd-notify","commit_stats":{"total_commits":42,"total_committers":10,"mean_commits":4.2,"dds":0.5952380952380952,"last_synced_commit":"57377d629c4959bf4f76608fae69b227222d951d"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/systemd/node-sd-notify","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/systemd%2Fnode-sd-notify","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/systemd%2Fnode-sd-notify/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/systemd%2Fnode-sd-notify/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/systemd%2Fnode-sd-notify/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/systemd","download_url":"https://codeload.github.com/systemd/node-sd-notify/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/systemd%2Fnode-sd-notify/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263733447,"owners_count":23503158,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["daemon","forever","nodemon","process","process-manager","sd-notify","systemd"],"created_at":"2025-06-08T16:30:48.849Z","updated_at":"2025-10-29T02:37:09.876Z","avatar_url":"https://github.com/systemd.png","language":"C++","readme":"# sd-notify [![Build Status](https://travis-ci.org/systemd/node-sd-notify.svg?branch=master)](https://travis-ci.org/systemd/node-sd-notify) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://github.com/feross/standard) [![NPM version](https://img.shields.io/npm/v/sd-notify.svg)](https://npmjs.org/package/sd-notify) [![License](http://img.shields.io/npm/l/sd-notify.svg)](LICENSE)\n\n\u003e Extremely minimal wrapper around [`sd_notify`](https://www.freedesktop.org/software/systemd/man/sd_notify.html)\n\n### Requirements\n\n* any Linux distribution that supports [__systemd__](https://en.wikipedia.org/wiki/Systemd)\n* C/C++ tool stack (GCC/Clang, etc...)\n* Node.js \u003e= `8.0.0`\n\n### Installation\n\nFirstly you need some __systemd__ development files, on __Ubuntu__ these can be installed via:\n\n```\n$ sudo apt install libsystemd-dev\n```\n\n...then using `npm`:\n\n```\n$ npm install --save sd-notify\n```\n\n### Usage\n\n__Example:__\n\n```javascript\nconst notify = require('sd-notify')\n\n// call notify after some async start up process\n// such as in the `http` or `express` listen callback\n\napp.listen(PORT, () =\u003e {\n  console.log('listening on port ' + PORT)\n  notify.ready()\n})\n```\n\nCalling `.ready()` will inform [__systemd__](https://www.freedesktop.org/software/systemd/man/systemd.service.html) that the process has started, when using `notify` type in a service definition file, eg:\n\n```ini\n[Unit]\nDescription=Simple notifying service\n\n[Service]\nEnvironment=\"NODE_ENV=production\"\nType=notify\nExecStart=/usr/sbin/simple-notifying-service\nTimeoutStartSec=30\nRestart=always\n\n[Install]\nWantedBy=multi-user.target\n```\n\n__\"Watchdog\" mode:__\n\nIn the service file add `WatchdogSec=n` where `n` is the amount of seconds __`systemd`__ should\nstop (or restart) the service if there is no contact.\n\n```ini\n[Service]\nEnvironment=\"NODE_ENV=production\"\nType=notify\nExecStart=/usr/sbin/simple-notifying-service\nTimeoutStartSec=30\nRestart=always\nWatchdogSec=3\n```\n\n...and in Node, you can call the native method `.watchdog()` directly in a `setInterval` or any other mechanism\ndepending on what kind of application you are developing, or you can use the helper function\n`startWatchdogMode(milliseconds)`:\n\n```javascript\nconst notify = require('sd-notify')\n\napp.listen(PORT, () =\u003e {\n  console.log('listening on port ' + PORT)\n  notify.ready()\n  notify.startWatchdogMode(2800)\n})\n```\n\n...above the number supplied to the `startWatchdogMode` method is the amount of milliseconds\nwe want to _ping_ `systemd`, in the example this is 200ms less than the 3 seconds set in the\nservice file. Due to the event loop there is no guarantee the `setInterval` underneath will\nfire exactly 2800ms, this will change depending on how many functions are being called in the process,\nthough this has a nice side effect, as if the process gets that busy, that blocked, `systemd` will kill it\n(and restart it with the `Restart=` config set); and in the context of having multiple processes being load\nbalanced with Nginx (as an example) and across multiple machines, ensures that no one process is blocking\nfor any significant amount of time.\n\nYou can also check if the process was called by __systemd__ with Watchdog mode\nenabled, using `watchdogInterval()` which returns the amount of milliseconds\nwatchdog has been set to, or `0` if it has not been set:\n\n```javascript\napp.listen(PORT, () =\u003e {\n  console.log('listening on port ' + PORT)\n  notify.ready()\n\n  const watchdogInterval = notify.watchdogInterval()\n\n  if (watchdogInterval \u003e 0) {\n    const interval = Math.floor(watchdogInterval / 2)\n    notify.startWatchdogMode(interval)\n  }\n})\n```\n\n...this way the Node process will behave in the correct manner in either situation.\n\n__Status:__\n\nYou can also send some status string to __systemd__, which will append to the service's log.\n\n```javascript\nconst notify = require('sd-notify')\n\n// ...\n\nnotify.sendStatus('send some status to systemd')\n\n// ...\n```\n\n...then, for example:\n\n```\n$ journalctl -u node-status\n\n...\nApr 22 17:29:41 lenovo node[8275]: (8275) listening on 8000\nApr 22 17:29:41 lenovo systemd[1]: Started Express Node.js.\nApr 22 17:35:50 lenovo node[8275]: send some status to systemd\n...\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsystemd%2Fnode-sd-notify","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsystemd%2Fnode-sd-notify","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsystemd%2Fnode-sd-notify/lists"}