@systemd-js/conf
TypeScript icon, indicating that this package has built-in type declarations

0.10.0 • Public • Published

@systemd-js/conf

INI parser for systemd config files. Set of fluent builders to create and modify unit files. Based on systemd v255.4

Installation

yarn add @systemd-js/conf

Examples

Parse systemd ini file into object.

Note: Ini parser is not fully implemented, lacks support for escaping and quoting.

import {INI} from "@systemd-js/conf";

const unit = `
[Unit]
Description=example
After=network.target

[Install]
WantedBy=multi-user.target

[Service]
ExecStartPre=/opt/example/agent start-1
ExecStartPre=/opt/example/agent start-2
ExecStart=/opt/example/agent start
EnvironmentFile=/opt/example/.env
Restart=always
PrivateTmp=yes
User=root
`;

const ini = INI.fromString(unit).toObject();

{
  Unit: {
    Description: "example",
    After: "network.target",
  },
  Install: {
    WantedBy: "multi-user.target",
  },
  Service: {
    ExecStartPre: [
      "/opt/example/agent start-1",
      "/opt/example/agent start-2",
    ],
    ExecStart: "/opt/example/agent start",
    EnvironmentFile: "/opt/example/.env",
    Restart: "always",
    PrivateTmp: true,
    User: "root",
  },
};

Create service unit for ini string and modify service user definition.

const unit = `
[Unit]
Description=example
After=network.target

[Install]
WantedBy=multi-user.target

[Service]
ExecStartPre=/opt/example/agent start-1
ExecStartPre=/opt/example/agent start-2
ExecStart=/opt/example/agent start
EnvironmentFile=/opt/example/.env
Restart=always
PrivateTmp=yes
User=root
`;

const ini = INI.fromString(unit);
const service = Service.fromINI(ini);

service
  .getServiceSection()
  .setUser("test");

service.toINIString();

Create service unit using fluent builder

import { Service } from "@systemd-js/config";

const service = new Service();

service
  .getUnitSection()
  .setDescription("This is a example unit");

service
  .getInstallSection()
  .setWantedBy("multi-user.target");

service
  .getServiceSection()
  .setType("simple")
  .setWorkingDirectory("/tmp")
  .setRestart("always")
  .setExecStartPre("/usr/bin/echo 'Before'")
  .setExecStart("/usr/bin/echo 'Hello World'")
  .setExecStartPost("/usr/bin/echo 'After'");

Create timer unit using fluent builder

import { Timer } from "@systemd-js/config";
const timer = new Timer();

timer
  .getUnitSection()
  .setDescription("example")
  .setAfter("network.target");

timer
  .getInstallSection()
  .setWantedBy("multi-user.target");

timer
  .getTimerSection()
  .setOnCalendar("daily")
  .setUnit("postgresql-dump.target");

Package Sidebar

Install

npm i @systemd-js/conf

Weekly Downloads

10

Version

0.10.0

License

Apache-2.0

Unpacked Size

1.1 MB

Total Files

82

Last publish

Collaborators

  • chyzwar_owner