Update 2026-06-23 10:40:10
Build and Push Docker Images / Build Backend Image (push) Has been cancelled
Build and Push Docker Images / Build Frontend Image (push) Has been cancelled
Build and Push Docker Images / Notify Build Complete (push) Has been cancelled

This commit is contained in:
yi
2026-06-23 10:40:10 +08:00
parent 864efb7f9d
commit e9bff9beb3
56 changed files with 295 additions and 292 deletions
+21 -21
View File
@@ -1,12 +1,12 @@
#!/usr/bin/env node
/**
* IDC设备管理系统 - 卸载脚本 v2.0.0
* 云睿资产管理系统 - 卸载脚本 v2.0.0
*
* 功能说明:
* - 停止并删除 PM2 管理的后端和前端服务
* - 清理 Nginx 配置文件(可选)
* - 删除生成的配置文件(.env、ecosystem.config.js、nginx-idc.conf
* - 删除生成的配置文件(.env、ecosystem.config.js、nginx-yunrui.conf
* - 可选删除数据库文件(SQLite)
* - 可选删除 node_modules 和构建产物
*
@@ -58,7 +58,7 @@ function parseArgs() {
function showHelp() {
console.log(`
${colors.bright}IDC设备管理系统 - 卸载脚本 v${SCRIPT_VERSION}${colors.reset}
${colors.bright}云睿资产管理系统 - 卸载脚本 v${SCRIPT_VERSION}${colors.reset}
${colors.bright}用法:${colors.reset} node uninstall.js [选项]
@@ -105,7 +105,7 @@ function commandExists(command) {
}
function getPM2ServiceNames() {
const defaultNames = { backendName: 'idc-backend', frontendName: 'idc-frontend' };
const defaultNames = { backendName: 'yunrui_asset-backend', frontendName: 'yunrui_asset-frontend' };
const configPath = path.join(__dirname, 'deploy', 'ecosystem.config.js');
if (!fs.existsSync(configPath)) {
@@ -123,7 +123,7 @@ function getPM2ServiceNames() {
if (app.name && app.name.startsWith('idc-')) {
if (app.name.includes('backend') || (app.script && app.script.includes('server'))) {
names.backendName = app.name;
} else if (app.name.includes('frontend') || app.name === 'idc-frontend') {
} else if (app.name.includes('frontend') || app.name === 'yunrui_asset-frontend') {
names.frontendName = app.name;
}
}
@@ -137,7 +137,7 @@ function getPM2ServiceNames() {
function getDatabaseConfig() {
const defaultConfig = {
dbType: 'sqlite',
sqliteDbPath: path.join(__dirname, 'backend', 'idc_management.db')
sqliteDbPath: path.join(__dirname, 'backend', 'yunrui_management.db')
};
const envPath = path.join(__dirname, 'backend', '.env');
@@ -304,13 +304,13 @@ async function cleanupNginxConfig(cmdArgs) {
const sudoPrefix = root ? '' : 'sudo ';
const idcConfigPaths = [
{ path: '/etc/nginx/sites-available/idc', label: 'sites-available/idc' },
{ path: '/etc/nginx/sites-enabled/idc', label: 'sites-enabled/idc(软链接)' },
{ path: '/etc/nginx/sites-available/yunrui_asset', label: 'sites-available/yunrui_asset' },
{ path: '/etc/nginx/sites-enabled/yunrui_asset', label: 'sites-enabled/yunrui_asset(软链接)' },
{ path: '/etc/nginx/conf.d/idc', label: 'conf.d/idc' },
{ path: '/etc/nginx/conf.d/idc.conf', label: 'conf.d/idc.conf' },
];
const wwwDir = '/var/www/idc';
const wwwDir = '/var/www/yunrui_asset';
const defaultSitePath = '/etc/nginx/sites-enabled/default';
const defaultAvailablePath = '/etc/nginx/sites-available/default';
@@ -331,15 +331,15 @@ async function cleanupNginxConfig(cmdArgs) {
}
if (!configRemoved) {
log.info('未找到 IDC Nginx 站点配置文件');
log.info('未找到云睿资产 Nginx 站点配置文件');
}
if (fs.existsSync(wwwDir)) {
log.info('清理前端部署目录...');
const result = runCommand(`${sudoPrefix}rm -rf "${wwwDir}"`, { silent: true });
if (result.success) {
log.success('前端部署目录已删除 (/var/www/idc)');
deletedItems.push({ type: '目录', name: '/var/www/idc' });
log.success('前端部署目录已删除 (/var/www/yunrui_asset)');
deletedItems.push({ type: '目录', name: '/var/www/yunrui_asset' });
} else {
log.warning('前端部署目录删除失败,请手动清理');
}
@@ -384,7 +384,7 @@ async function cleanupConfigFiles() {
const filesToDelete = [
{ path: path.join(__dirname, 'backend', '.env'), name: '后端环境变量 (.env)', type: '配置文件' },
{ path: path.join(__dirname, 'deploy', 'ecosystem.config.js'), name: 'PM2 配置 (ecosystem.config.js)', type: '配置文件' },
{ path: path.join(__dirname, 'deploy', 'nginx-idc.conf'), name: 'Nginx 配置 (nginx-idc.conf)', type: '配置文件' }
{ path: path.join(__dirname, 'deploy', 'nginx-yunrui.conf'), name: 'Nginx 配置 (nginx-yunrui.conf)', type: '配置文件' }
];
for (const file of filesToDelete) {
@@ -513,7 +513,7 @@ async function cleanupDatabase(cmdArgs) {
log.section('MySQL 删除方法');
console.log(` ${ICONS.pipe} 方法1 - MySQL 命令行:`);
console.log(` ${ICONS.pipe} ${colors.cyan}mysql -u root -p${colors.reset}`);
console.log(` ${ICONS.pipe} ${colors.cyan}DROP DATABASE idc_management;${colors.reset}`);
console.log(` ${ICONS.pipe} ${colors.cyan}DROP DATABASE yunrui_management;${colors.reset}`);
console.log(` ${ICONS.pipe} 方法2 - 使用数据库管理工具(如 Navicat、DBeaver、phpMyAdmin`);
console.log(` ${ICONS.pipe} 方法3 - 如果不再需要 MySQL 数据,可直接卸载 MySQL 服务`);
}
@@ -681,15 +681,15 @@ function showDryRunPreview(cmdArgs) {
console.log(`\n ${ICONS.pointer} ${colors.bright}2. 清理 Nginx 配置${colors.reset}`);
if (process.platform === 'linux') {
const nginxConfigPaths = ['/etc/nginx/sites-available/idc', '/etc/nginx/sites-enabled/idc',
const nginxConfigPaths = ['/etc/nginx/sites-available/yunrui_asset', '/etc/nginx/sites-enabled/yunrui_asset',
'/etc/nginx/conf.d/idc', '/etc/nginx/conf.d/idc.conf'];
nginxConfigPaths.forEach(p => {
if (fs.existsSync(p)) {
console.log(` ${ICONS.pipe} 删除 IDC 站点配置: ${p}`);
console.log(` ${ICONS.pipe} 删除云睿资产站点配置: ${p}`);
}
});
if (fs.existsSync('/var/www/idc')) {
console.log(` ${ICONS.pipe} 删除前端部署目录 (/var/www/idc)`);
if (fs.existsSync('/var/www/yunrui_asset')) {
console.log(` ${ICONS.pipe} 删除前端部署目录 (/var/www/yunrui_asset)`);
}
if (!fs.existsSync('/etc/nginx/sites-enabled/default') && fs.existsSync('/etc/nginx/sites-available/default')) {
console.log(` ${ICONS.pipe} 恢复 Nginx 默认站点`);
@@ -707,7 +707,7 @@ function showDryRunPreview(cmdArgs) {
const configFiles = [
{ path: path.join(__dirname, 'backend', '.env'), name: '后端环境变量 (.env)' },
{ path: path.join(__dirname, 'deploy', 'ecosystem.config.js'), name: 'PM2 配置' },
{ path: path.join(__dirname, 'deploy', 'nginx-idc.conf'), name: 'Nginx 配置' }
{ path: path.join(__dirname, 'deploy', 'nginx-yunrui.conf'), name: 'Nginx 配置' }
];
configFiles.forEach(f => {
if (fs.existsSync(f.path)) {
@@ -825,12 +825,12 @@ async function main() {
initLogFile(LOG_DIR);
log.banner(
'IDC 设备管理系统',
'云睿资产管理系统',
'卸载脚本',
SCRIPT_VERSION
);
log.warning('此脚本将卸载 IDC 设备管理系统');
log.warning('此脚本将卸载 云睿资产管理系统');
if (cmdArgs.force) {
log.info('运行模式: 强制卸载(无需确认)');