Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweaks3 #26

Merged
merged 3 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: "Checkout"
uses: actions/checkout@v4

- name: "Use NodeJS 22"
- name: "Setup NodeJS 22"
uses: actions/setup-node@v4
with:
node-version: '22'
Expand All @@ -21,11 +21,11 @@ jobs:
- name: Install
run: yarn install

- name: Run build
- name: Build
run: yarn build

- name: Run test
- name: Test
run: yarn test

- name: Run lint
- name: Lint
run: yarn lint
18 changes: 10 additions & 8 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
with:
fetch-depth: 0

- name: "Use NodeJS 22"
- name: "Setup NodeJS 22"
uses: actions/setup-node@v4
with:
node-version: '22'
Expand All @@ -42,24 +42,26 @@ jobs:
- name: Install
run: yarn install

- name: Run build
- name: Build
run: yarn build

- name: Run test
- name: Test
run: yarn test

- name: Run lint
- name: Lint
run: yarn lint

- name: Setup git user
run: |
echo "Setup git user to github action user"
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor}}@users.noreply.github.com"

- name: "Version and publish"
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Setup git user for lerna publish
git config --global user.name "${{ github.actor }}"
git config --global user.email "${{ github.actor }}@users.noreply.github.com"

echo "Version"
yarn lerna version \
--conventional-commits \
Expand Down
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");
```
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
"@lerna-lite/publish": "^3.9.1",
"@lerna-lite/version": "^3.9.1",
"@types/node": "^22.5.5",
"conventional-changelog-conventionalcommits": "^7.0.2",
"eslint": "^9.10.0",
"conventional-changelog-conventionalcommits": "^8.0.0",
"eslint": "^9.11.0",
"husky": "^9.1.6",
"lint-staged": "^15.2.10",
"ts-node": "^10.9.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/conf/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"@chyzwar/eslint-config": "^0.2.29",
"@chyzwar/tsconfig": "^0.2.29",
"@types/node": "^22.5.5",
"eslint": "^9.10.0",
"eslint": "^9.11.0",
"typescript": "^5.6.2",
"vitest": "^2.1.1"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/ctl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@chyzwar/eslint-config": "^0.2.29",
"@chyzwar/tsconfig": "^0.2.29",
"@types/node": "^22.5.5",
"eslint": "^9.10.0",
"eslint": "^9.11.0",
"typescript": "^5.6.2",
"vitest": "^2.1.1"
}
Expand Down
3 changes: 3 additions & 0 deletions packages/ctl/src/ctl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ const getPath = (name: string, type: string) => {
: `/etc/containers/systemd/${name}.${type}`;
};

/**
* Create Unit from filesystem
*/
function getUnit(unitName: string, type: string = getType(unitName)): Unit | undefined {
const name = getName(unitName);
const path = `/etc/systemd/system/${name}.${type}`;
Expand Down
Loading
Loading