|
|
@@ -976,12 +976,18 @@ func (s *ServerService) ImportDB(file multipart.File) error {
|
|
|
return common.NewErrorf("Invalid or corrupt db file: %v", err)
|
|
|
}
|
|
|
|
|
|
- // Stop Xray (ignore error but log)
|
|
|
+ xrayStopped := true
|
|
|
+ defer func() {
|
|
|
+ if xrayStopped {
|
|
|
+ if errR := s.RestartXrayService(); errR != nil {
|
|
|
+ logger.Warningf("Failed to restart Xray after DB import error: %v", errR)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }()
|
|
|
if errStop := s.StopXrayService(); errStop != nil {
|
|
|
logger.Warningf("Failed to stop Xray before DB import: %v", errStop)
|
|
|
}
|
|
|
|
|
|
- // Close existing DB to release file locks (especially on Windows)
|
|
|
if errClose := database.CloseDB(); errClose != nil {
|
|
|
logger.Warningf("Failed to close existing DB before replacement: %v", errClose)
|
|
|
}
|
|
|
@@ -1029,7 +1035,7 @@ func (s *ServerService) ImportDB(file multipart.File) error {
|
|
|
|
|
|
s.inboundService.MigrateDB()
|
|
|
|
|
|
- // Start Xray
|
|
|
+ xrayStopped = false
|
|
|
if err = s.RestartXrayService(); err != nil {
|
|
|
return common.NewErrorf("Imported DB but failed to start Xray: %v", err)
|
|
|
}
|