Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit 979be8b

Browse files
authored
chore: destroy dangling processes on uninstall (#945)
1 parent 0511475 commit 979be8b

File tree

1 file changed

+29
-21
lines changed

1 file changed

+29
-21
lines changed

cortex-js/uninstall.js

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,38 @@ const os = require('os');
33
const fs = require('fs');
44
const path = require('path');
55
const yaml = require('js-yaml');
6+
const constants = require('./dist/src/infrastructure/constants/cortex.js')
67

78
const uninstall = async () => {
8-
const cortexConfigPath = path.join(os.homedir(), '.cortexrc');
9-
if (fs.existsSync(cortexConfigPath)) {
10-
const content = await promises.readFile(cortexConfigPath, 'utf8');
11-
const config = yaml.load(content);
12-
if(!config) {
13-
return;
14-
}
15-
const { dataFolderPath } = config;
16-
const modelsFolderPath = path.join(dataFolderPath, 'models');
17-
// remove all data in data folder path except models
18-
const files = fs.readdirSync(dataFolderPath);
19-
for (const file of files) {
20-
const fileStat = fs.statSync(path.join(dataFolderPath, file));
21-
if (file !== 'models') {
22-
if (fileStat.isDirectory()) {
23-
fs.rmSync(path.join(dataFolderPath, file), { recursive: true });
24-
} else {
25-
fs.unlinkSync(path.join(dataFolderPath, file));
26-
}
27-
}
9+
const cortexConfigPath = path.join(os.homedir(), '.cortexrc');
10+
if (fs.existsSync(cortexConfigPath)) {
11+
const content = await promises.readFile(cortexConfigPath, 'utf8');
12+
const config = yaml.load(content);
13+
if(!config) {
14+
return;
15+
}
16+
const { dataFolderPath, cortexCppHost, cortexCppPort, apiServerHost, apiServerPort } = config;
17+
18+
await fetch(constants.CORTEX_CPP_PROCESS_DESTROY_URL(cortexCppHost, cortexCppPort),
19+
{ method: 'DELETE' })
20+
.catch(() => {})
21+
await fetch(constants.CORTEX_JS_SYSTEM_URL(apiServerHost, apiServerPort),
22+
{ method: 'DELETE' })
23+
.catch(() => {})
24+
// remove all data in data folder path except models
25+
const modelsFolderPath = path.join(dataFolderPath, 'models');
26+
const files = fs.readdirSync(dataFolderPath);
27+
for (const file of files) {
28+
const fileStat = fs.statSync(path.join(dataFolderPath, file));
29+
if (file !== 'models') {
30+
if (fileStat.isDirectory()) {
31+
fs.rmSync(path.join(dataFolderPath, file), { recursive: true });
32+
} else {
33+
fs.unlinkSync(path.join(dataFolderPath, file));
2834
}
35+
}
2936
}
37+
}
3038
};
3139

32-
uninstall();
40+
uninstall();

0 commit comments

Comments
 (0)