Remove OTA update functionality

This commit is contained in:
2026-03-15 01:45:06 +08:00
parent 6bdb788e01
commit 92eea398ea
12 changed files with 7 additions and 1495 deletions

View File

@@ -138,7 +138,6 @@ COMMANDS:
stop Stop running instance(s)
restart Stop and start the server
status Show server status
update Check for and install updates
OPTIONS:
-p, --port Web server port (default: ${DEFAULT_PORT})
@@ -160,7 +159,6 @@ EXAMPLES:
openchamber stop # Stop all running instances
openchamber stop --port 3000 # Stop specific instance
openchamber status # Check status
openchamber update # Update to latest version
`);
}
@@ -862,132 +860,6 @@ const commands = {
}
},
async update() {
const os = await import('os');
const tmpDir = os.tmpdir();
const packageManagerPath = path.join(__dirname, '..', 'server', 'lib', 'package-manager.js');
const {
checkForUpdates,
executeUpdate,
detectPackageManager,
getCurrentVersion,
} = await importFromFilePath(packageManagerPath);
// Check for running instances before update
let runningInstances = [];
try {
const files = fs.readdirSync(tmpDir);
const pidFiles = files.filter(file => file.startsWith('openchamber-') && file.endsWith('.pid'));
for (const file of pidFiles) {
const port = parseInt(file.replace('openchamber-', '').replace('.pid', ''));
if (!isNaN(port)) {
const pidFilePath = path.join(tmpDir, file);
const instanceFilePath = path.join(tmpDir, `openchamber-${port}.json`);
const pid = readPidFile(pidFilePath);
if (pid && isProcessRunning(pid)) {
const storedOptions = readInstanceOptions(instanceFilePath);
runningInstances.push({
port,
pid,
pidFilePath,
instanceFilePath,
storedOptions: storedOptions || { port, daemon: true },
});
}
}
}
} catch (error) {
// Ignore
}
console.log('Checking for updates...');
console.log(`Current version: ${getCurrentVersion()}`);
const updateInfo = await checkForUpdates();
if (updateInfo.error) {
console.error(`Error: ${updateInfo.error}`);
process.exit(1);
}
if (!updateInfo.available) {
console.log('\nYou are running the latest version.');
return;
}
console.log(`\nNew version available: ${updateInfo.version}`);
if (updateInfo.body) {
console.log('\nChangelog:');
console.log('─'.repeat(40));
// Simple formatting for CLI
const formatted = updateInfo.body
.replace(/^## \[(\d+\.\d+\.\d+)\] - \d{4}-\d{2}-\d{2}/gm, '\nv$1')
.replace(/^### /gm, '\n')
.replace(/^- /gm, ' • ');
console.log(formatted);
console.log('─'.repeat(40));
}
// Stop running instances before update
if (runningInstances.length > 0) {
console.log(`\nStopping ${runningInstances.length} running instance(s) before update...`);
for (const instance of runningInstances) {
try {
await requestServerShutdown(instance.port);
process.kill(instance.pid, 'SIGTERM');
let attempts = 0;
while (isProcessRunning(instance.pid) && attempts < 20) {
await new Promise(resolve => setTimeout(resolve, 250));
attempts++;
}
if (isProcessRunning(instance.pid)) {
process.kill(instance.pid, 'SIGKILL');
}
removePidFile(instance.pidFilePath);
console.log(` Stopped instance on port ${instance.port}`);
} catch (error) {
console.warn(` Warning: Could not stop instance on port ${instance.port}`);
}
}
}
const pm = detectPackageManager();
console.log(`\nDetected package manager: ${pm}`);
console.log('Installing update...\n');
const result = executeUpdate(pm);
if (result.success) {
console.log('\nUpdate successful!');
// Restart previously running instances
if (runningInstances.length > 0) {
console.log(`\nRestarting ${runningInstances.length} instance(s)...`);
for (const instance of runningInstances) {
try {
// Force daemon mode for restart after update
const restartOptions = {
...instance.storedOptions,
daemon: true,
};
await commands.serve(restartOptions);
console.log(` Restarted instance on port ${instance.port}`);
} catch (error) {
console.error(` Failed to restart instance on port ${instance.port}: ${error.message}`);
console.log(` Run manually: openchamber serve --port ${instance.port} --daemon`);
}
}
}
} else {
console.error('\nUpdate failed.');
console.error(`Exit code: ${result.exitCode}`);
process.exit(1);
}
},
};
async function main() {