New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

node-systemctl

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-systemctl

Systemd interface for NodeJS

latest
Source
npmnpm
Version
0.1.1
Version published
Maintainers
1
Created
Source

node-systemctl

Control your systemd services from the comfort of your NodeJS script, using this hacky interface module.

Installation

npm i node-systemctl

or

yarn add node-systemctl

Usage

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() - Actually restart() in disguise, see below.
  • restart() - Starts/restarts the service. Equivalent of systemctl restart <service>.
  • stop() - Stops the service. Equivalent of systemctl stop <service>.
  • enable() - Enables start at boot. Equivalent of systemctl enable <service>.
  • disable() - Disables start at boot. Equivalent of systemctl disable <service>.
  • edit() - Opens the unit file in an editor. Equivalent of systemctl edit --full <service>. (Only for use in a CLI environment)

Getters

  • isActive: boolean - Returns true if the service is running, i.e., the following are both true:
    • service ActiveState is active
    • service SubState is running
  • isEnabled: boolean - Returns true if service start at boot is enabled, i.e., UnitFileState is enabled or static.
  • status: string - Returns service state as would be displayed in output of systemctl status. Ex.: active (running)

Keywords

systemd

FAQs

Package last updated on 22 Feb 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts