0.1.1 • Published 4 years ago
node-systemctl v0.1.1
node-systemctl
Control your systemd services from the comfort of your NodeJS script, using this hacky interface module.
Installation
npm i node-systemctlor
yarn add node-systemctlUsage
Note: examples assume ES6 modules enabled.
Quick start example
import SystemService from 'node-systemctl'
// construct the service
// using await
const unit = await new SystemService('custom-unit')
if (!unit.isActive) await unit.start()
// or using .then()
new SystemService('custom-unit').then(async unit => {
if (!unit.isActive) await unit.start()
})If your service requires root privilages (or you are getting the Interactive authentication required error) pass a truthy value as the second argument:
const superUnit = await new SystemService('custom-unit', true)Methods
Note: Following methods are async, use await if you need to wait for them to finish.
start()- Actuallyrestart()in disguise, see below.restart()- Starts/restarts the service. Equivalent ofsystemctl restart <service>.stop()- Stops the service. Equivalent ofsystemctl stop <service>.enable()- Enables start at boot. Equivalent ofsystemctl enable <service>.disable()- Disables start at boot. Equivalent ofsystemctl disable <service>.edit()- Opens the unit file in an editor. Equivalent ofsystemctl edit --full <service>. (Only for use in a CLI environment)
Getters
isActive: boolean- Returnstrueif the service is running, i.e., the following are both true:- service
ActiveStateisactive - service
SubStateisrunning
- service
isEnabled: boolean- Returnstrueif service start at boot is enabled, i.e.,UnitFileStateisenabledorstatic.status: string- Returns service state as would be displayed in output ofsystemctl status. Ex.:active (running)