nix: implicitly install pm2-prom-module on startup#319
Conversation
There was a problem hiding this comment.
Pull request overview
Updates the Nix-packaged startup wrapper for blockfrost-backend-ryo to automatically install pm2-prom-module on service start, aiming to reduce operator setup work for Prometheus/PM2 monitoring.
Changes:
- Split the PM2 startup wrapper into separate commands (delete, install module, start).
- Add
pm2 install pm2-prom-moduleduring startup (errors currently ignored).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ${nodePackages.pm2}/bin/pm2 delete all | ||
| ${nodePackages.pm2}/bin/pm2 install pm2-prom-module || true | ||
| ${nodePackages.pm2}/bin/pm2 start \ | ||
| $out/libexec/source/dist/server.js \ |
There was a problem hiding this comment.
pm2 delete all will remove every PM2-managed process for the service user/PM2_HOME, including any other apps or modules an operator may be running under the same user. Safer is to name this process explicitly (e.g., via pm2 start --name) and delete only that name (or use a dedicated PM2_HOME / user that is guaranteed to be exclusive).
| ${nodePackages.pm2}/bin/pm2 delete all | |
| ${nodePackages.pm2}/bin/pm2 install pm2-prom-module || true | |
| ${nodePackages.pm2}/bin/pm2 start \ | |
| $out/libexec/source/dist/server.js \ | |
| pm2AppName="${name}" | |
| ${nodePackages.pm2}/bin/pm2 delete "$pm2AppName" || true | |
| ${nodePackages.pm2}/bin/pm2 install pm2-prom-module || true | |
| ${nodePackages.pm2}/bin/pm2 start \ | |
| $out/libexec/source/dist/server.js \ | |
| --name "$pm2AppName" \ |
| ${nodePackages.pm2}/bin/pm2 delete all; \ | ||
| ${nodePackages.pm2}/bin/pm2 start \ | ||
| ${nodePackages.pm2}/bin/pm2 delete all | ||
| ${nodePackages.pm2}/bin/pm2 install pm2-prom-module || true |
There was a problem hiding this comment.
Installing pm2-prom-module at runtime (pm2 install ...) makes startup depend on external network availability and an unpinned npm artifact, which hurts reproducibility and can break cold starts/offline deployments. If this is required, prefer packaging/pinning it in Nix (or at least pinning the version in the install command) and handle failures explicitly rather than swallowing them with || true (e.g., log and continue, or gate install on module not already being present).
|
superseded by #320 |
this is non-ideal solution to get pm2-prom-module, as it will run on every consumer of the nix package of ryo. But with flakification work down the line we'll be able to add options to run custom pre/post scripts on startup. As a temporary workaround to prevent unnecessary complexity on operator side, we'll install this package, which is in a way quite useful for any operator of ryo anyway as they'll gain more visibility and stats to their monitoring setups.