Skip to content

A modern, self-hosted backup solution for secure, encrypted backups across local and cloud storage.

fix: prevent duplicate instances on startup

towfiqi46b133bda733
diff --git a/backend/src/index.ts b/backend/src/index.ts
index fb638f1..e983749 100644
--- a/backend/src/index.ts
+++ b/backend/src/index.ts
@@ -92,13 +92,26 @@ if (isMainModule || isDevelopment) {
const { app } = await createApp();
- const server = app.listen(configService.config.SERVER_PORT || 5173, () => {
- console.log(`Server running on port ${configService.config.SERVER_PORT || 5173}`);
+ const port = configService.config.SERVER_PORT || 5173;
+
+ const server = app.listen(port, () => {
+ console.log(`Server running on port ${port}`);
if (configService.isSetupPending()) {
console.log(
- `⚠️ Initial setup required. Visit http://localhost:${configService.config.SERVER_PORT || 5173} to complete setup.`
+ `⚠️ Initial setup required. Visit http://localhost:${port} to complete setup.`
+ );
+ }
+ });
+
+ server.on('error', (err: NodeJS.ErrnoException) => {
+ if (err.code === 'EADDRINUSE') {
+ console.error(
+ `[Startup] Port ${port} is already in use. Another Pluton instance is running. Exiting.`
);
+ process.exit(0);
}
+ console.error('[Startup] HTTP server error:', err);
+ process.exit(1);
});
// Handle graceful shutdown
diff --git a/installers/windows/pluton-setup.iss b/installers/windows/pluton-setup.iss
index 4426e78..39c259d 100644
--- a/installers/windows/pluton-setup.iss
+++ b/installers/windows/pluton-setup.iss
@@ -103,6 +103,8 @@ Filename: "{app}\nssm.exe"; Parameters: "set {#MyAppServiceName} Start SERVICE_A
Filename: "{app}\nssm.exe"; Parameters: "set {#MyAppServiceName} AppDirectory ""{app}"""; Flags: runhidden
; Set environment variables for data directory on the service
Filename: "{app}\nssm.exe"; Parameters: "set {#MyAppServiceName} AppEnvironmentExtra PLUTON_DATA_DIR=""{commonappdata}\{#MyAppName}"""; Flags: runhidden
+; Exit code 0 is a deliberate stop (e.g. port already in use) - do not restart
+Filename: "{app}\nssm.exe"; Parameters: "set {#MyAppServiceName} AppExit 0 Exit"; Flags: runhidden
; Set stdout and stderr logging
Filename: "{app}\nssm.exe"; Parameters: "set {#MyAppServiceName} AppStdout ""{commonappdata}\{#MyAppName}\logs\service-out.log"""; Flags: runhidden
Filename: "{app}\nssm.exe"; Parameters: "set {#MyAppServiceName} AppStderr ""{commonappdata}\{#MyAppName}\logs\service-err.log"""; Flags: runhidden