Skip to content

Commit eab295c

Browse files
committed
fix(installer): enhance post-installation error handling and Docker shutdown for security risks
1 parent ee8537c commit eab295c

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

installer/install.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"fmt"
5+
"os"
56
"time"
67

78
"github.com/utmstack/UTMStack/installer/config"
@@ -45,7 +46,15 @@ func Install() error {
4546

4647
fmt.Println("Running post installation scripts. This may take a while.")
4748
if err := docker.PostInstallation(); err != nil {
48-
return err
49+
fmt.Printf("\nCRITICAL ERROR: Post-installation failed: %v\n", err)
50+
fmt.Println("Stopping Docker service to prevent security risk (ports may be left open).")
51+
if stopErr := utils.StopService("docker"); stopErr != nil {
52+
fmt.Printf("WARNING: Failed to stop Docker service: %v\n", stopErr)
53+
} else {
54+
fmt.Println("Docker service has been stopped. Manual intervention required.")
55+
fmt.Println("Please check /var/log/utmstack-installer.log for details.")
56+
}
57+
os.Exit(1)
4958
}
5059

5160
fmt.Println("Installation fisnished successfully. We have generated a configuration file for you, please do not modify or remove it. You can find it at /root/utmstack.yml.")

installer/updater/service.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"github.com/kardianos/service"
1010
"github.com/utmstack/UTMStack/installer/config"
11+
"github.com/utmstack/UTMStack/installer/docker"
1112
"github.com/utmstack/UTMStack/installer/setup"
1213
"github.com/utmstack/UTMStack/installer/utils"
1314
)
@@ -59,6 +60,21 @@ func (p *program) run() {
5960
} else {
6061
config.Logger().Info("Successfully applied update %s", pendingUpdate.Version)
6162

63+
// Close ports after update (same as initial installation)
64+
config.Logger().Info("Running post-installation scripts to secure ports...")
65+
if err := docker.PostInstallation(); err != nil {
66+
config.Logger().ErrorF("error running post-installation: %v", err)
67+
config.Logger().ErrorF("CRITICAL: Post-installation failed. Stopping Docker to prevent security risk.")
68+
// Stop Docker to prevent leaving ports open
69+
if stopErr := utils.StopService("docker"); stopErr != nil {
70+
config.Logger().ErrorF("Failed to stop Docker service: %v", stopErr)
71+
} else {
72+
config.Logger().ErrorF("Docker service has been stopped. Manual intervention required.")
73+
}
74+
// Stop the updater service to prevent further processing
75+
return
76+
}
77+
6278
// Mark as sent in CM after successful apply
6379
if pendingUpdate.ID != "offline" {
6480
client := GetUpdaterClient()

0 commit comments

Comments
 (0)