open-agents-ai 0.187.320 → 0.187.321
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/dist/postinstall-daemon.cjs +46 -7
- package/package.json +1 -1
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
// Safe, best-effort, idempotent. Skips if systemd --user is unavailable.
|
|
4
4
|
|
|
5
5
|
const { execSync } = require('node:child_process');
|
|
6
|
-
const { mkdirSync, writeFileSync } = require('node:fs');
|
|
7
|
-
const { join } = require('node:path');
|
|
6
|
+
const { mkdirSync, writeFileSync, existsSync } = require('node:fs');
|
|
7
|
+
const { join, resolve } = require('node:path');
|
|
8
8
|
|
|
9
9
|
function hasSystemdUser() {
|
|
10
10
|
try { execSync('systemctl --user --version', { stdio: 'pipe' }); return true; } catch { return false; }
|
|
@@ -101,18 +101,57 @@ try { migrate(); } catch {}
|
|
|
101
101
|
// 1) Prefer systemd --user: restart open-agents-daemon.service if present
|
|
102
102
|
// 2) Fallback: launch the freshly installed CLI's launcher in daemon mode
|
|
103
103
|
// using this package's dist/launcher.cjs (absolute path), detached.
|
|
104
|
-
|
|
104
|
+
// 3) If the unit is missing, write a sane user service pointing to this
|
|
105
|
+
// package's launcher and enable it.
|
|
106
|
+
function ensureSystemdUnit() {
|
|
105
107
|
try {
|
|
106
|
-
|
|
108
|
+
if (!hasSystemdUser()) return false;
|
|
109
|
+
const unitDir = join(process.env.HOME || process.env.USERPROFILE || '.', '.config', 'systemd', 'user');
|
|
110
|
+
mkdirSync(unitDir, { recursive: true });
|
|
111
|
+
const unitPath = join(unitDir, 'open-agents-daemon.service');
|
|
112
|
+
const nodeBin = process.execPath; // current Node used for this install
|
|
113
|
+
const launcher = resolve(__dirname, 'launcher.cjs');
|
|
114
|
+
const svc = [
|
|
115
|
+
'[Unit]',
|
|
116
|
+
'Description=Open Agents API Daemon',
|
|
117
|
+
'After=default.target',
|
|
118
|
+
'',
|
|
119
|
+
'[Service]',
|
|
120
|
+
'Type=simple',
|
|
121
|
+
`ExecStart=${JSON.stringify(nodeBin)} ${JSON.stringify(launcher)} serve --daemon --quiet`,
|
|
122
|
+
`WorkingDirectory=${JSON.stringify(process.env.HOME || process.cwd())}`,
|
|
123
|
+
'Restart=always',
|
|
124
|
+
'RestartSec=2',
|
|
125
|
+
'Environment=OA_DAEMON=1',
|
|
126
|
+
'',
|
|
127
|
+
'[Install]',
|
|
128
|
+
'WantedBy=default.target',
|
|
129
|
+
''
|
|
130
|
+
].join('\n');
|
|
131
|
+
writeFileSync(unitPath, svc);
|
|
107
132
|
try {
|
|
108
|
-
execSync('systemctl --user
|
|
109
|
-
|
|
133
|
+
execSync('systemctl --user daemon-reload', { stdio: 'pipe' });
|
|
134
|
+
execSync('systemctl --user enable --now open-agents-daemon.service', { stdio: 'pipe' });
|
|
110
135
|
} catch {}
|
|
136
|
+
return true;
|
|
137
|
+
} catch { return false; }
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function restartDaemon() {
|
|
141
|
+
try {
|
|
142
|
+
if (hasSystemdUser()) {
|
|
143
|
+
// If service missing, create it first
|
|
144
|
+
try { execSync('systemctl --user cat open-agents-daemon.service >/dev/null 2>&1'); }
|
|
145
|
+
catch { try { ensureSystemdUnit(); } catch {} }
|
|
146
|
+
// Restart via systemd
|
|
147
|
+
try { execSync('systemctl --user restart open-agents-daemon.service', { stdio: 'pipe' }); return; } catch {}
|
|
148
|
+
}
|
|
111
149
|
} catch {}
|
|
112
150
|
try {
|
|
113
151
|
const { spawn } = require('node:child_process');
|
|
114
|
-
const { resolve, join } = require('node:path');
|
|
115
152
|
const la = resolve(__dirname, 'launcher.cjs');
|
|
153
|
+
// Best-effort: kill any old OA daemon owned by this user
|
|
154
|
+
try { execSync("pkill -f 'open-agents-ai.*serve' || true", { stdio: 'pipe' }); } catch {}
|
|
116
155
|
const nodeBin = process.execPath;
|
|
117
156
|
const child = spawn(nodeBin, [la, 'serve', '--daemon', '--quiet'], {
|
|
118
157
|
detached: true,
|
package/package.json
CHANGED