Skip to content

Commit

Permalink
chore(docs): improve docs added badge
Browse files Browse the repository at this point in the history
  • Loading branch information
chyzwar committed Sep 20, 2024
1 parent 2f4df62 commit 0c87eed
Showing 1 changed file with 50 additions and 51 deletions.
101 changes: 50 additions & 51 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Systemd.js

![Publish](https://github.com/systemd-js/systemd/actions/workflows/publish.yaml/badge.svg)

Collection of packages useful when interfacing with systemd.

## @systemd-js/conf
Expand All @@ -19,7 +21,8 @@ yarn add @systemd-js/conf

Parse systemd ini file into object.

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

```ts
import {INI} from "@systemd-js/conf";
Expand Down Expand Up @@ -64,7 +67,6 @@ const ini = INI.fromString(unit).toObject();
User: "root",
},
};

```

Create service unit for ini string and modify service user definition.
Expand All @@ -88,46 +90,46 @@ PrivateTmp=yes
User=root
`;

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

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

service.toINIString();
```

Create service unit using fluent builder

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

const service = new Service();

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

service
.getInstallSection()
.setWantedBy("multi-user.target")
.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'")
.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

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

timer
.getUnitSection()
Expand All @@ -136,7 +138,7 @@ timer

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

timer
.getTimerSection()
Expand All @@ -146,8 +148,8 @@ timer

## @systemd-js/ctl

Control over units. Interface to systemctl.
At the moment this lack proper error handling.
Control over units. Interface to systemctl. At the moment this lack proper error
handling.

### Installation

Expand All @@ -160,57 +162,54 @@ yarn add @systemd-js/ctl
State manipulation of existing service.

```ts
import {Ctl} from "@systemd-js/ctl";

const ctl = new Ctl("test.service")
import { Ctl } from "@systemd-js/ctl";

ctl.disable()
ctl.enable()
ctl.stop()
ctl.start()
ctl.restart()
const ctl = new Ctl("test.service");

ctl.disable();
ctl.enable();
ctl.stop();
ctl.start();
ctl.restart();
```

Creation of new service "example.service"

```ts
import {Service} from "@systemd-js/config";
import {Ctl} from "@systemd-js/ctl";
import { Service } from "@systemd-js/config";
import { Ctl } from "@systemd-js/ctl";

const service = new Service();

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

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

service
.getServiceSection()
.setType("simple")
.setExecStart("/usr/bin/echo 'Hello World'")
.setWantedBy("multi-user.target");

const ctl = new Ctl("example", service)
service
.getServiceSection()
.setType("simple")
.setExecStart("/usr/bin/echo 'Hello World'");

ctl.create()
ctl.enable()
ctl.start()
const ctl = new Ctl("example", service);

ctl.create();
ctl.enable();
ctl.start();
```

In addition to `Ctl` class, package expose functions to call systemctl directly.

```ts
import {restart, start, stop} from "@systemd-js/ctl";

stop("example.service")
start("example.service")
enable("example.service")
disable("example.service")
reload("example.service")
restart("example.service")

import { restart, start, stop } from "@systemd-js/ctl";

stop("example.service");
start("example.service");
enable("example.service");
disable("example.service");
reload("example.service");
restart("example.service");
```

0 comments on commit 0c87eed

Please sign in to comment.