eclipse-thingweb / eclipse-thingweb/node-wot
Servient's runScript() lacks management funcionality (stop, monitor)
- Dominant language
- TypeScript
- Stars
- 192
- Forks
- 100
- Avg merge
- 3d 2h
- Merged PRs (30d)
- 6
Description
**feat(core):** add support for script runtime management functionality into Servient
Hello everyone! I realized the core/Servient `runScript()` and `runPriviledgedScript()` methods only allow running arbitrary code, without the ability to stop it. I have a use case where I need to execute scripts and have not only basic management like stop, restart, but also [more advanced process monitoring capabilities](https://pm2.keymetrics.io/docs/usage/pm2-doc-single-page/) (e.g. metrics, logs).
Digging into the documentation for the [vm](https://www.npmjs.com/package/vm)/[vm2](https://www.npmjs.com/package/vm2#vm) libraries, I haven't found a way of doing so with such libraries. On the other hand, a process monitoring library like [pm2](https://www.npmjs.com/package/pm2) does **allow not only running but also stopping processes as well as programatic access to monitoring information and metrics** (which is in any case, a nice to have). It basically allows programatically embedding a process manager directly in code, spawning processes, keeping them alive even if the main script is exited.
**Request:**
Would it be possible to consider a process management library like pm2 rather than vm/vm2 for the `runScript()` and `runPriviledgedScript()` methods, and additionally add something like `stopScript()`, `restartScript()` and maybe e.g. `getInfo()` `getActiveProcesses()` among other useful features for monitoring the running scripts. This might be necesarry for production use cases where you cannot simply run and forget. I am not sure of the sandboxing capabilities offered by pm2 though.
Thanks!
Contributor guide
Assessment
This issue has not been assessed yet.