systemctl-rest
v0.3.5
Published
Simple REST server to manipulate system services via systemctl
Downloads
9
Maintainers
Readme
systemctl-rest
REST endpoint for manipulation of system services. This serves as a thin wrapper around native linux systemctl command (leveraging sysctlx package).
Prerequisites
- linux host supporting service manipulation via systemctl
API
http://localhost:<port>/service/<service>
- returns structuredsystemctl status
in JSONhttp://localhost:<port>/service/<service>/enable
- callssystemctl enable
http://localhost:<port>/service/<service>/disable
- callssystemctl disable
http://localhost:<port>/service/<service>/start
- callssystemctl start
http://localhost:<port>/service/<service>/stop
- callssystemctl stop
http://localhost:<port>/service/<service>/restart
- callssystemctl restart
Usage
1. Directly as a standalone server
When invoked directly from the command line, systemctl-rest configures express server instance and automatically starts listening on given port.
$ sudo node systemctl-rest
(with default port 8181
)
$ sudo node systemctl-rest 8080
2. Required to provide configured server instance
In case you would like to build on top of this package you could reuse the existing configured express instance and add your own routing paths with respective handlers. This helps you to avoid combining multiple server instances to achieve your goal with systemctl.
Please note that in this scenario you need to retrieve the port and start listening on it yourself:
let server = require('systemctl-rest').server;
# .. add your paths
server.get('/my/custom/path', myHandlerFunction);
# .. start the server
server.listen(<my-port>);
References
- https://www.npmjs.com/package/sysctlx
- https://www.npmjs.com/package/express
- https://www.digitalocean.com/community/tutorials/how-to-use-systemctl-to-manage-systemd-services-and-units