omnikey-cli 1.0.10 → 1.0.11
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/killDaemon.js +28 -17
- package/dist/removeConfig.js +20 -15
- package/package.json +1 -1
- package/src/killDaemon.ts +29 -16
- package/src/removeConfig.ts +18 -13
package/dist/killDaemon.js
CHANGED
|
@@ -2,31 +2,42 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.killDaemon = killDaemon;
|
|
4
4
|
const child_process_1 = require("child_process");
|
|
5
|
+
const removeConfig_1 = require("./removeConfig");
|
|
5
6
|
/**
|
|
6
7
|
* Kill the Omnikey API backend daemon running on a given port (default 7071).
|
|
7
8
|
* Looks for node processes running backend-dist/index.js on the specified port and kills them.
|
|
8
9
|
* @param port The port to look for (default 7071)
|
|
9
10
|
*/
|
|
10
11
|
function killDaemon(port = 7071) {
|
|
12
|
+
// 1. Unload/kill the launchd agent first
|
|
11
13
|
try {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
console.log(`Killed daemon process with PID ${pid} on port ${port}.`);
|
|
23
|
-
}
|
|
24
|
-
catch (e) {
|
|
25
|
-
console.error(`Failed to kill process ${pid}:`, e);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
14
|
+
(0, removeConfig_1.killLaunchdAgent)();
|
|
15
|
+
console.log('Launchd agent unloaded (if it existed).');
|
|
16
|
+
}
|
|
17
|
+
catch (e) {
|
|
18
|
+
console.warn('Failed to unload launchd agent or agent did not exist:', e);
|
|
19
|
+
}
|
|
20
|
+
// 2. Check if the port is still in use
|
|
21
|
+
let pids = [];
|
|
22
|
+
try {
|
|
23
|
+
pids = (0, child_process_1.execSync)(`lsof -i :${port} -t`).toString().split('\n').filter(Boolean);
|
|
28
24
|
}
|
|
29
25
|
catch (e) {
|
|
30
|
-
|
|
26
|
+
// lsof returns non-zero exit code if nothing is using the port
|
|
27
|
+
pids = [];
|
|
28
|
+
}
|
|
29
|
+
if (pids.length === 0) {
|
|
30
|
+
console.log(`No process found using port ${port} after unloading launchd agent.`);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
// 3. If the port is still occupied, kill the process using the port
|
|
34
|
+
for (const pid of pids) {
|
|
35
|
+
try {
|
|
36
|
+
process.kill(Number(pid), 'SIGTERM');
|
|
37
|
+
console.log(`Killed process with PID ${pid} using port ${port}.`);
|
|
38
|
+
}
|
|
39
|
+
catch (e) {
|
|
40
|
+
console.error(`Failed to kill process ${pid}:`, e);
|
|
41
|
+
}
|
|
31
42
|
}
|
|
32
43
|
}
|
package/dist/removeConfig.js
CHANGED
|
@@ -3,11 +3,30 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.killLaunchdAgent = killLaunchdAgent;
|
|
6
7
|
exports.removeConfigAndDb = removeConfigAndDb;
|
|
7
8
|
const fs_1 = __importDefault(require("fs"));
|
|
8
9
|
const path_1 = __importDefault(require("path"));
|
|
9
10
|
const os_1 = __importDefault(require("os"));
|
|
10
11
|
const child_process_1 = require("child_process");
|
|
12
|
+
function killLaunchdAgent() {
|
|
13
|
+
const homeDir = process.env.HOME || process.env.USERPROFILE || os_1.default.homedir();
|
|
14
|
+
const plistName = 'com.omnikey.daemon.plist';
|
|
15
|
+
const plistPath = path_1.default.join(homeDir, 'Library', 'LaunchAgents', plistName);
|
|
16
|
+
if (fs_1.default.existsSync(plistPath)) {
|
|
17
|
+
try {
|
|
18
|
+
(0, child_process_1.execSync)(`launchctl unload "${plistPath}"`);
|
|
19
|
+
fs_1.default.rmSync(plistPath);
|
|
20
|
+
console.log(`Removed launchd agent: ${plistPath}`);
|
|
21
|
+
}
|
|
22
|
+
catch (e) {
|
|
23
|
+
console.error(`Failed to remove launchd agent: ${e}`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
console.log(`Launchd agent does not exist: ${plistPath}`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
11
30
|
/**
|
|
12
31
|
* Removes the ~/.omnikey config directory and the SQLite database file specified in config.json.
|
|
13
32
|
*/
|
|
@@ -31,21 +50,7 @@ function removeConfigAndDb() {
|
|
|
31
50
|
}
|
|
32
51
|
}
|
|
33
52
|
// Remove launchd agent if exists (macOS)
|
|
34
|
-
|
|
35
|
-
const plistPath = path_1.default.join(homeDir, 'Library', 'LaunchAgents', plistName);
|
|
36
|
-
if (fs_1.default.existsSync(plistPath)) {
|
|
37
|
-
try {
|
|
38
|
-
(0, child_process_1.execSync)(`launchctl unload "${plistPath}"`);
|
|
39
|
-
fs_1.default.rmSync(plistPath);
|
|
40
|
-
console.log(`Removed launchd agent: ${plistPath}`);
|
|
41
|
-
}
|
|
42
|
-
catch (e) {
|
|
43
|
-
console.error(`Failed to remove launchd agent: ${e}`);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
console.log(`Launchd agent does not exist: ${plistPath}`);
|
|
48
|
-
}
|
|
53
|
+
killLaunchdAgent();
|
|
49
54
|
// Remove SQLite database
|
|
50
55
|
if (fs_1.default.existsSync(sqlitePath)) {
|
|
51
56
|
try {
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"access": "public",
|
|
5
5
|
"registry": "https://registry.npmjs.org/"
|
|
6
6
|
},
|
|
7
|
-
"version": "1.0.
|
|
7
|
+
"version": "1.0.11",
|
|
8
8
|
"description": "CLI for onboarding users to Omnikey AI and configuring OPENAI_API_KEY. Use Yarn for install/build.",
|
|
9
9
|
"engines": {
|
|
10
10
|
"node": ">=14.0.0",
|
package/src/killDaemon.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { execSync } from 'child_process';
|
|
2
|
+
import { killLaunchdAgent } from './removeConfig';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Kill the Omnikey API backend daemon running on a given port (default 7071).
|
|
@@ -6,23 +7,35 @@ import { execSync } from 'child_process';
|
|
|
6
7
|
* @param port The port to look for (default 7071)
|
|
7
8
|
*/
|
|
8
9
|
export function killDaemon(port: number = 7071) {
|
|
10
|
+
// 1. Unload/kill the launchd agent first
|
|
9
11
|
try {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
console.log(`Killed daemon process with PID ${pid} on port ${port}.`);
|
|
21
|
-
} catch (e) {
|
|
22
|
-
console.error(`Failed to kill process ${pid}:`, e);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
12
|
+
killLaunchdAgent();
|
|
13
|
+
console.log('Launchd agent unloaded (if it existed).');
|
|
14
|
+
} catch (e) {
|
|
15
|
+
console.warn('Failed to unload launchd agent or agent did not exist:', e);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// 2. Check if the port is still in use
|
|
19
|
+
let pids: string[] = [];
|
|
20
|
+
try {
|
|
21
|
+
pids = execSync(`lsof -i :${port} -t`).toString().split('\n').filter(Boolean);
|
|
25
22
|
} catch (e) {
|
|
26
|
-
|
|
23
|
+
// lsof returns non-zero exit code if nothing is using the port
|
|
24
|
+
pids = [];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (pids.length === 0) {
|
|
28
|
+
console.log(`No process found using port ${port} after unloading launchd agent.`);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// 3. If the port is still occupied, kill the process using the port
|
|
33
|
+
for (const pid of pids) {
|
|
34
|
+
try {
|
|
35
|
+
process.kill(Number(pid), 'SIGTERM');
|
|
36
|
+
console.log(`Killed process with PID ${pid} using port ${port}.`);
|
|
37
|
+
} catch (e) {
|
|
38
|
+
console.error(`Failed to kill process ${pid}:`, e);
|
|
39
|
+
}
|
|
27
40
|
}
|
|
28
41
|
}
|
package/src/removeConfig.ts
CHANGED
|
@@ -3,6 +3,23 @@ import path from 'path';
|
|
|
3
3
|
import os from 'os';
|
|
4
4
|
import { execSync } from 'child_process';
|
|
5
5
|
|
|
6
|
+
export function killLaunchdAgent() {
|
|
7
|
+
const homeDir = process.env.HOME || process.env.USERPROFILE || os.homedir();
|
|
8
|
+
const plistName = 'com.omnikey.daemon.plist';
|
|
9
|
+
const plistPath = path.join(homeDir, 'Library', 'LaunchAgents', plistName);
|
|
10
|
+
if (fs.existsSync(plistPath)) {
|
|
11
|
+
try {
|
|
12
|
+
execSync(`launchctl unload "${plistPath}"`);
|
|
13
|
+
fs.rmSync(plistPath);
|
|
14
|
+
console.log(`Removed launchd agent: ${plistPath}`);
|
|
15
|
+
} catch (e) {
|
|
16
|
+
console.error(`Failed to remove launchd agent: ${e}`);
|
|
17
|
+
}
|
|
18
|
+
} else {
|
|
19
|
+
console.log(`Launchd agent does not exist: ${plistPath}`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
6
23
|
/**
|
|
7
24
|
* Removes the ~/.omnikey config directory and the SQLite database file specified in config.json.
|
|
8
25
|
*/
|
|
@@ -27,19 +44,7 @@ export function removeConfigAndDb() {
|
|
|
27
44
|
}
|
|
28
45
|
|
|
29
46
|
// Remove launchd agent if exists (macOS)
|
|
30
|
-
|
|
31
|
-
const plistPath = path.join(homeDir, 'Library', 'LaunchAgents', plistName);
|
|
32
|
-
if (fs.existsSync(plistPath)) {
|
|
33
|
-
try {
|
|
34
|
-
execSync(`launchctl unload "${plistPath}"`);
|
|
35
|
-
fs.rmSync(plistPath);
|
|
36
|
-
console.log(`Removed launchd agent: ${plistPath}`);
|
|
37
|
-
} catch (e) {
|
|
38
|
-
console.error(`Failed to remove launchd agent: ${e}`);
|
|
39
|
-
}
|
|
40
|
-
} else {
|
|
41
|
-
console.log(`Launchd agent does not exist: ${plistPath}`);
|
|
42
|
-
}
|
|
47
|
+
killLaunchdAgent();
|
|
43
48
|
|
|
44
49
|
// Remove SQLite database
|
|
45
50
|
if (fs.existsSync(sqlitePath)) {
|