Skip to content
Draft
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
1,232 changes: 481 additions & 751 deletions Cargo.lock

Large diffs are not rendered by default.

21 changes: 11 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,31 @@ name = "balena-systemd"
version = "0.5.11"
description = "Essential systemd D-Bus bindings for Node.js "
repository = "https://github.com/balena-io-modules/systemd/"
authors = [ "Balena Inc. <hello@balena.io>" ]
authors = ["Balena Inc. <hello@balena.io>"]
license = "Apache-2.0"
edition = "2021"
exclude = [ "index.node" ]
exclude = ["index.node"]

[lib]
crate-type = [ "cdylib" ]
crate-type = ["cdylib"]

[dependencies]
once_cell = "1.18.0"
once_cell = "1.21.4"
futures-util = "0.3"

[dependencies.zbus]
version = "3.14.1"
version = "5.15.0"
default-features = false
features = [ "tokio" ]
features = ["tokio"]

[dependencies.tokio]
version = "1.29.1"
features = [ "rt-multi-thread" ]
version = "1.52.1"
features = ["rt-multi-thread"]

[dependencies.neon]
version = "0.10"
version = "1.1"
default-features = false
features = [ "napi-6", "channel-api", "promise-api" ]
features = ["napi-6"]

[profile.release]
opt-level = "z"
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
# - test the build of the project in a musl containerized environment
# - provide an install to run integration tests
# - generate a binary to be published with the package to be used by node-pre-gyp
FROM alpine:3.20
FROM alpine:3.23

RUN apk add --update --no-cache \
build-base \
nodejs~=20 \
nodejs~=24 \
npm \
dbus \
rust cargo \
Expand All @@ -32,4 +32,4 @@
COPY tests ./tests
COPY ./wait-for-it.sh /

CMD npm run test:integration

Check warning on line 35 in Dockerfile

View workflow job for this annotation

GitHub Actions / Flowzone / Test docker (default, linux/arm/v7, self-hosted, ARM64, arm32v7, default)

JSON arguments recommended for ENTRYPOINT/CMD to prevent unintended behavior related to OS signals

JSONArgsRecommended: JSON arguments recommended for CMD to prevent unintended behavior related to OS signals More info: https://docs.docker.com/go/dockerfile/rule/json-args-recommended/

Check warning on line 35 in Dockerfile

View workflow job for this annotation

GitHub Actions / Flowzone / Test docker (default, linux/386, ubuntu-24.04, i386, default)

JSON arguments recommended for ENTRYPOINT/CMD to prevent unintended behavior related to OS signals

JSONArgsRecommended: JSON arguments recommended for CMD to prevent unintended behavior related to OS signals More info: https://docs.docker.com/go/dockerfile/rule/json-args-recommended/

Check warning on line 35 in Dockerfile

View workflow job for this annotation

GitHub Actions / Flowzone / Test docker (default, linux/arm/v6, self-hosted, ARM64, arm32v6, default)

JSON arguments recommended for ENTRYPOINT/CMD to prevent unintended behavior related to OS signals

JSONArgsRecommended: JSON arguments recommended for CMD to prevent unintended behavior related to OS signals More info: https://docs.docker.com/go/dockerfile/rule/json-args-recommended/

Check warning on line 35 in Dockerfile

View workflow job for this annotation

GitHub Actions / Flowzone / Test docker (default, linux/amd64, ubuntu-24.04, amd64, default)

JSON arguments recommended for ENTRYPOINT/CMD to prevent unintended behavior related to OS signals

JSONArgsRecommended: JSON arguments recommended for CMD to prevent unintended behavior related to OS signals More info: https://docs.docker.com/go/dockerfile/rule/json-args-recommended/

Check warning on line 35 in Dockerfile

View workflow job for this annotation

GitHub Actions / Flowzone / Test docker (default, linux/arm64, self-hosted, ARM64, arm64v8, default)

JSON arguments recommended for ENTRYPOINT/CMD to prevent unintended behavior related to OS signals

JSONArgsRecommended: JSON arguments recommended for CMD to prevent unintended behavior related to OS signals More info: https://docs.docker.com/go/dockerfile/rule/json-args-recommended/
6 changes: 2 additions & 4 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { SystemBus } from '../native/index.node';
import {
SystemBus,
unitActiveState,
unitPartOf,
unitStart,
Expand All @@ -21,9 +21,7 @@ export { system, SystemBus } from '../native/index.node';
export const singleton = (() => {
let bus: SystemBus | null = null;
return async function () {
if (!bus) {
bus = await system();
}
bus ??= await system();
return bus;
};
})();
Expand Down
19 changes: 10 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
"name": "@balena/systemd",
"version": "0.5.11",
"description": "Essential systemd D-Bus bindings for Node.js",
"homepage": "https://github.com/balena-io-modules/systemd#readme",
"homepage": "https://github.com/balena-io-modules/node-systemd#readme",
"main": "build/index.js",
"repository": {
"type": "git",
"url": "git+https://github.com/balena-io-modules/systemd.git"
"url": "git+https://github.com/balena-io-modules/node-systemd.git"
},
"bugs": {
"url": "https://github.com/balena-io-modules/systemd/issues"
"url": "https://github.com/balena-io-modules/node-systemd/issues"
},
"files": [
"build/",
Expand Down Expand Up @@ -37,19 +37,20 @@
"author": "Balena Inc. <hello@balena.io>",
"license": "Apache-2.0",
"devDependencies": {
"@balena/lint": "^8.0.0",
"@types/chai": "^4.3.5",
"@types/chai-as-promised": "^7.1.5",
"@balena/lint": "^9.4.1",
"@types/chai": "^5.2.3",
"@types/chai-as-promised": "^8.0.2",
"@types/mocha": "^10.0.1",
"@types/node": "^24.12.2",
"cargo-cp-artifact": "^0.1",
"chai": "^4.3.7",
"chai-as-promised": "^7.1.1",
"chai": "^6.2.2",
"chai-as-promised": "^8.0.2",
"husky": "^8.0.3",
"lint-staged": "^13.2.3",
"mocha": "^11.0.0",
"rimraf": "^5.0.1",
"ts-node": "^10.9.1",
"typescript": "^5.1.6"
"typescript": "^6.0.3"
},
"versionist": {
"publishedAt": "2026-02-19T23:51:24.422Z"
Expand Down
24 changes: 12 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use futures_util::TryFutureExt;
use neon::prelude::*;
use once_cell::sync::OnceCell;
use tokio::runtime::Runtime;
use zbus::dbus_proxy;
use zbus::export::futures_util::TryFutureExt;
use zbus::proxy;
use zbus::Connection;

// Return a global tokio runtime or create one if it doesn't exist.
Expand All @@ -13,44 +13,44 @@ fn runtime<'a, C: Context<'a>>(cx: &mut C) -> NeonResult<&'static Runtime> {
RUNTIME.get_or_try_init(|| Runtime::new().or_else(|err| cx.throw_error(err.to_string())))
}

#[dbus_proxy(
#[proxy(
interface = "org.freedesktop.systemd1.Manager",
default_service = "org.freedesktop.systemd1",
default_path = "/org/freedesktop/systemd1"
)]
pub trait ServiceManager {
#[dbus_proxy(object = "Unit")]
#[zbus(object = "Unit")]
fn get_unit(&self, unit: &str) -> zbus::Result<Unit>;

#[dbus_proxy(object = "Job")]
#[zbus(object = "Job")]
fn start_unit(&self, unit: &str, mode: &str) -> zbus::Result<Job>;

#[dbus_proxy(object = "Job")]
#[zbus(object = "Job")]
fn stop_unit(&self, unit: &str, mode: &str) -> zbus::Result<Job>;

#[dbus_proxy(object = "Job")]
#[zbus(object = "Job")]
fn restart_unit(&self, unit: &str, mode: &str) -> zbus::Result<Job>;
}

#[dbus_proxy(
#[proxy(
default_service = "org.freedesktop.systemd1",
interface = "org.freedesktop.systemd1.Job"
)]
pub trait Job {}

#[dbus_proxy(
#[proxy(
default_service = "org.freedesktop.systemd1",
interface = "org.freedesktop.systemd1.Unit"
)]
pub trait Unit {
#[dbus_proxy(property)]
#[zbus(property)]
fn active_state(&mut self) -> zbus::Result<String>;

#[dbus_proxy(property)]
#[zbus(property)]
fn part_of(&mut self) -> zbus::Result<Vec<String>>;
}

#[dbus_proxy(
#[proxy(
interface = "org.freedesktop.login1.Manager",
default_service = "org.freedesktop.login1",
default_path = "/org/freedesktop/login1"
Expand Down
5 changes: 2 additions & 3 deletions tests/chai.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as chai from 'chai';
import * as chaiAsPromised from 'chai-as-promised';
chai.use(chaiAsPromised);
import chaiAsPromised from 'chai-as-promised';

export default chai;
chai.use(chaiAsPromised);

export const { expect } = chai;
4 changes: 2 additions & 2 deletions tests/service-manager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ describe('ServiceManager', () => {
// main thread?
await expect(
Promise.all([
await manager.getUnit('dummy.service').activeState,
await manager.getUnit('dummy.service').activeState,
manager.getUnit('dummy.service').activeState,
manager.getUnit('dummy.service').activeState,
]),
).to.not.be.rejected;
});
Expand Down
7 changes: 5 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
{
"compilerOptions": {
"module": "commonjs",
"rootDir": "./",
"outDir": "build",
"noUnusedParameters": true,
"noUnusedLocals": true,
"removeComments": true,
"sourceMap": true,
"strict": true,
"target": "es2015",
"target": "es2025",
"module": "commonjs",
"esModuleInterop": true,
"types": ["node", "mocha"],
"declaration": true,
"skipLibCheck": true
},
Expand Down
Loading