lobstakit-cloud 1.3.0 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/gateway.js +41 -0
  2. package/package.json +1 -1
package/lib/gateway.js CHANGED
@@ -23,10 +23,50 @@ function isGatewayRunning() {
23
23
  }
24
24
  }
25
25
 
26
+ /**
27
+ * Ensure D-Bus user session is available (required for OpenClaw on headless VPS).
28
+ * Without this, `systemctl --user` fails with "Failed to connect to bus: No medium found".
29
+ */
30
+ function ensureUserSession() {
31
+ try {
32
+ // Enable lingering so user services survive without a login session
33
+ execSync('loginctl enable-linger root 2>/dev/null || true', { encoding: 'utf8', timeout: 5000 });
34
+
35
+ // Ensure XDG_RUNTIME_DIR exists
36
+ const uid = execSync('id -u', { encoding: 'utf8', timeout: 3000 }).trim();
37
+ const runtimeDir = `/run/user/${uid}`;
38
+ execSync(`mkdir -p ${runtimeDir} && chmod 700 ${runtimeDir}`, { encoding: 'utf8', timeout: 3000 });
39
+
40
+ // Set environment for this process and children
41
+ process.env.XDG_RUNTIME_DIR = runtimeDir;
42
+ process.env.DBUS_SESSION_BUS_ADDRESS = `unix:path=${runtimeDir}/bus`;
43
+
44
+ // Start a D-Bus session if the socket doesn't exist
45
+ try {
46
+ execSync(`test -S ${runtimeDir}/bus || dbus-daemon --session --address=unix:path=${runtimeDir}/bus --fork --nopidfile 2>/dev/null || true`, {
47
+ encoding: 'utf8',
48
+ timeout: 5000,
49
+ env: { ...process.env, XDG_RUNTIME_DIR: runtimeDir }
50
+ });
51
+ } catch (e) {
52
+ // dbus-daemon might not be installed, try systemd approach
53
+ execSync(`systemd-run --user --scope true 2>/dev/null || true`, {
54
+ encoding: 'utf8',
55
+ timeout: 5000,
56
+ env: { ...process.env, XDG_RUNTIME_DIR: runtimeDir }
57
+ });
58
+ }
59
+ console.log('[gateway] User session ensured (linger + D-Bus)');
60
+ } catch (err) {
61
+ console.warn('[gateway] User session setup warning:', err.message);
62
+ }
63
+ }
64
+
26
65
  /**
27
66
  * Start the gateway service.
28
67
  */
29
68
  function startGateway() {
69
+ ensureUserSession();
30
70
  try {
31
71
  execSync(`systemctl start ${SERVICE_NAME}`, {
32
72
  encoding: 'utf8',
@@ -61,6 +101,7 @@ function stopGateway() {
61
101
  * Restart the gateway service (enables it first if not already enabled).
62
102
  */
63
103
  function restartGateway() {
104
+ ensureUserSession();
64
105
  try {
65
106
  // Ensure service is enabled (cloud-init doesn't enable it — LobstaKit does after setup)
66
107
  execSync(`systemctl enable ${SERVICE_NAME}`, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lobstakit-cloud",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
4
4
  "description": "LobstaKit Cloud — Setup wizard and management for LobstaCloud gateways",
5
5
  "main": "server.js",
6
6
  "bin": {