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

feat: stop-backend.js and update.js linux support #701

Merged
merged 2 commits into from
Jul 26, 2023
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
23 changes: 23 additions & 0 deletions config/stop-backend.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// eslint-disable-next-line
const helpers = require('./helpers');
const { exec } = require('child_process');
const { promisify } = require('util');

const isWindows = process.platform === 'win32';
const execAsync = promisify(exec);

async function main() {
try {
if (isWindows) {
console.red('The backend process has been terminated');
await execAsync('taskkill /F /IM node.exe /T');
} else {
await execAsync('pkill -f api/server/index.js');
console.orange('The backend process has been terminated');
}
} catch (err) {
console.red('The backend process has been terminated', err.message);
}
}

main();
25 changes: 21 additions & 4 deletions config/update.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
const { execSync } = require('child_process');
const path = require('path');
const fs = require('fs');
const rimraf = require('rimraf');
const { askQuestion, isDockerRunning, silentExit } = require('./helpers');

const isWindows = process.platform === 'win32';

const config = {
localUpdate: process.argv.includes('-l'),
dockerUpdate: process.argv.includes('-d'),
useSingleComposeFile: process.argv.includes('-s'),
useSudo: process.argv.includes('--sudo'),
};

// Set the directories
@@ -51,7 +55,11 @@ function deleteNodeModules(dir) {
const nodeModulesPath = path.join(dir, 'node_modules');
if (fs.existsSync(nodeModulesPath)) {
console.purple(`Deleting node_modules in ${dir}`);
execSync(`rd /s /q "${nodeModulesPath}"`, { stdio: 'inherit', shell: 'cmd.exe' });
if (isWindows) {
execSync(`rd /s /q "${nodeModulesPath}"`, { stdio: 'inherit', shell: 'cmd.exe' });
} else {
rimraf.sync(nodeModulesPath);
}
}
}

@@ -63,7 +71,7 @@ function deleteNodeModules(dir) {
}

await validateDockerRunning();
const { dockerUpdate, useSingleComposeFile: singleCompose } = config;
const { dockerUpdate, useSingleComposeFile: singleCompose, useSudo } = config;

// Fetch latest repo
console.purple('Fetching the latest repo...');
@@ -79,9 +87,12 @@ function deleteNodeModules(dir) {

if (dockerUpdate) {
console.purple('Removing previously made Docker container...');
const downCommand = `docker-compose ${
let downCommand = `docker-compose ${
singleCompose ? '-f ./docs/dev/single-compose.yml ' : ''
}down --volumes`;
if (useSudo) {
downCommand = `sudo ${downCommand}`;
}
console.orange(downCommand);
execSync(downCommand, { stdio: 'inherit' });
console.purple('Pruning all LibreChat Docker images...');
@@ -95,9 +106,12 @@ function deleteNodeModules(dir) {
console.purple('Removing all unused dangling Docker images...');
execSync('docker image prune -f', { stdio: 'inherit' });
console.purple('Building new LibreChat image...');
const buildCommand = `docker-compose ${
let buildCommand = `docker-compose ${
singleCompose ? '-f ./docs/dev/single-compose.yml ' : ''
}build`;
if (useSudo) {
buildCommand = `sudo ${buildCommand}`;
}
console.orange(buildCommand);
execSync(buildCommand, { stdio: 'inherit' });
} else {
@@ -120,6 +134,9 @@ function deleteNodeModules(dir) {
let startCommand = 'npm run backend';
if (dockerUpdate) {
startCommand = `docker-compose ${singleCompose ? '-f ./docs/dev/single-compose.yml ' : ''}up`;
if (useSudo) {
startCommand = `sudo ${startCommand}`;
}
}
console.green('Your LibreChat app is now up to date! Start the app with the following command:');
console.purple(startCommand);
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -13,10 +13,12 @@
"update:local": "node config/update.js -l",
"update:docker": "node config/update.js -d",
"update:single": "node config/update.js -s",
"update:sudo": "node config/update.js --sudo",
"upgrade": "node config/upgrade.js",
"create-user": "node config/create-user.js",
"backend": "cross-env NODE_ENV=production node api/server/index.js",
"backend:dev": "cross-env NODE_ENV=development npx nodemon api/server/index.js",
"backend:stop": "node config/stop-backend.js",
"build:data-provider": "cd packages/data-provider && npm run build",
"frontend": "npm run build:data-provider && cd client && npm run build",
"frontend:ci": "npm run build:data-provider && cd client && npm run build:ci",