@omnixal/openclaw-nats-plugin 0.1.4 → 0.1.5
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.
- package/cli/bun-setup.ts +0 -4
- package/cli/service-units.ts +17 -10
- package/package.json +1 -1
package/cli/bun-setup.ts
CHANGED
|
@@ -11,7 +11,6 @@ import { generateApiKey, writeEnvVariables } from './env-writer';
|
|
|
11
11
|
import {
|
|
12
12
|
getServiceManager, generateSystemdUnit, generateLaunchdPlist,
|
|
13
13
|
installSystemdUnit, installLaunchdPlist, startService,
|
|
14
|
-
registerDirectCommand,
|
|
15
14
|
} from './service-units';
|
|
16
15
|
|
|
17
16
|
const NATS_SERVICE = 'openclaw-nats';
|
|
@@ -59,7 +58,6 @@ export async function bunSetup(): Promise<void> {
|
|
|
59
58
|
|
|
60
59
|
// 8. Generate and install service units
|
|
61
60
|
const manager = getServiceManager();
|
|
62
|
-
const logsDir = join(PLUGIN_DIR, 'logs');
|
|
63
61
|
|
|
64
62
|
if (manager === 'systemd') {
|
|
65
63
|
const natsUnit = generateSystemdUnit({
|
|
@@ -99,8 +97,6 @@ export async function bunSetup(): Promise<void> {
|
|
|
99
97
|
} else {
|
|
100
98
|
// Direct mode — containers or systems without init
|
|
101
99
|
console.log('No init system detected, using direct process management');
|
|
102
|
-
registerDirectCommand(NATS_SERVICE, NATS_SERVER_BIN, ['-c', NATS_CONF], PLUGIN_DIR, join(logsDir, 'nats.log'));
|
|
103
|
-
registerDirectCommand(SIDECAR_SERVICE, 'bun', ['run', join(SIDECAR_DIR, 'src/index.ts')], SIDECAR_DIR, join(logsDir, 'sidecar.log'));
|
|
104
100
|
}
|
|
105
101
|
|
|
106
102
|
// 9. Start services
|
package/cli/service-units.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { mkdirSync, writeFileSync, readFileSync, rmSync, existsSync } from 'node:fs';
|
|
1
|
+
import { mkdirSync, writeFileSync, readFileSync, rmSync, existsSync, openSync } from 'node:fs';
|
|
2
2
|
import { execFileSync, spawn } from 'node:child_process';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
4
|
import { homedir, platform } from 'node:os';
|
|
5
|
+
import { NATS_SERVER_BIN, NATS_CONF, PLUGIN_DIR, SIDECAR_DIR } from './paths';
|
|
5
6
|
|
|
6
7
|
// --- Interfaces ---
|
|
7
8
|
|
|
@@ -144,19 +145,25 @@ function readPid(name: string): number | null {
|
|
|
144
145
|
}
|
|
145
146
|
}
|
|
146
147
|
|
|
147
|
-
|
|
148
|
-
const
|
|
148
|
+
const NATS_SERVICE_NAME = 'openclaw-nats';
|
|
149
|
+
const SIDECAR_SERVICE_NAME = 'openclaw-nats-sidecar';
|
|
149
150
|
|
|
150
|
-
|
|
151
|
-
|
|
151
|
+
function getDirectCommand(name: string): { cmd: string; args: string[]; cwd: string; logFile: string } {
|
|
152
|
+
const logsDir = join(PLUGIN_DIR, 'logs');
|
|
153
|
+
mkdirSync(logsDir, { recursive: true });
|
|
154
|
+
|
|
155
|
+
if (name === NATS_SERVICE_NAME) {
|
|
156
|
+
return { cmd: NATS_SERVER_BIN, args: ['-c', NATS_CONF], cwd: PLUGIN_DIR, logFile: join(logsDir, 'nats.log') };
|
|
157
|
+
}
|
|
158
|
+
if (name === SIDECAR_SERVICE_NAME) {
|
|
159
|
+
return { cmd: 'bun', args: ['run', join(SIDECAR_DIR, 'src/index.ts')], cwd: SIDECAR_DIR, logFile: join(logsDir, 'sidecar.log') };
|
|
160
|
+
}
|
|
161
|
+
throw new Error(`Unknown service "${name}"`);
|
|
152
162
|
}
|
|
153
163
|
|
|
154
164
|
function startDirect(name: string): void {
|
|
155
|
-
const
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
const { cmd, args, cwd, logFile } = entry;
|
|
159
|
-
const out = require('node:fs').openSync(logFile, 'a');
|
|
165
|
+
const { cmd, args, cwd, logFile } = getDirectCommand(name);
|
|
166
|
+
const out = openSync(logFile, 'a');
|
|
160
167
|
const child = spawn(cmd, args, {
|
|
161
168
|
cwd,
|
|
162
169
|
stdio: ['ignore', out, out],
|