Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: destroy dangling processes on uninstall #945

Merged
merged 1 commit into from
Jul 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 29 additions & 21 deletions cortex-js/uninstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,38 @@ const os = require('os');
const fs = require('fs');
const path = require('path');
const yaml = require('js-yaml');
const constants = require('./dist/src/infrastructure/constants/cortex.js')

const uninstall = async () => {
const cortexConfigPath = path.join(os.homedir(), '.cortexrc');
if (fs.existsSync(cortexConfigPath)) {
const content = await promises.readFile(cortexConfigPath, 'utf8');
const config = yaml.load(content);
if(!config) {
return;
}
const { dataFolderPath } = config;
const modelsFolderPath = path.join(dataFolderPath, 'models');
// remove all data in data folder path except models
const files = fs.readdirSync(dataFolderPath);
for (const file of files) {
const fileStat = fs.statSync(path.join(dataFolderPath, file));
if (file !== 'models') {
if (fileStat.isDirectory()) {
fs.rmSync(path.join(dataFolderPath, file), { recursive: true });
} else {
fs.unlinkSync(path.join(dataFolderPath, file));
}
}
const cortexConfigPath = path.join(os.homedir(), '.cortexrc');
if (fs.existsSync(cortexConfigPath)) {
const content = await promises.readFile(cortexConfigPath, 'utf8');
const config = yaml.load(content);
if(!config) {
return;
}
const { dataFolderPath, cortexCppHost, cortexCppPort, apiServerHost, apiServerPort } = config;

await fetch(constants.CORTEX_CPP_PROCESS_DESTROY_URL(cortexCppHost, cortexCppPort),
{ method: 'DELETE' })
.catch(() => {})
await fetch(constants.CORTEX_JS_SYSTEM_URL(apiServerHost, apiServerPort),
{ method: 'DELETE' })
.catch(() => {})
// remove all data in data folder path except models
const modelsFolderPath = path.join(dataFolderPath, 'models');
const files = fs.readdirSync(dataFolderPath);
for (const file of files) {
const fileStat = fs.statSync(path.join(dataFolderPath, file));
if (file !== 'models') {
if (fileStat.isDirectory()) {
fs.rmSync(path.join(dataFolderPath, file), { recursive: true });
} else {
fs.unlinkSync(path.join(dataFolderPath, file));
}
}
}
}
};

uninstall();
uninstall();
Loading