Skip to content

Commit 68c75ff

Browse files
fix: fix auto updater for debian (#656) (#657)
(cherry picked from commit dcb892c) Co-authored-by: Tanmoy Sarkar <[email protected]>
1 parent 2d7f56b commit 68c75ff

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

swiftwave_service/cmd/swiftwave-updater.service

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ After=multi-user.target
44

55
[Service]
66
ExecStart=/bin/sh -c "/usr/bin/swiftwave update || true"
7-
Type=simple
7+
Type=oneshot
88

99
[Install]
1010
WantedBy=multi-user.target

swiftwave_service/cmd/update.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ var updateCmd = &cobra.Command{
4040
if isUpdated {
4141
fmt.Println("Swiftwave has been updated successfully")
4242
fmt.Println("Trying to restart the service...")
43-
_ = exec.Command("systemctl", "daemon-reload").Run()
44-
_ = exec.Command("systemctl", "restart", "swiftwave.service").Run()
43+
out, _ := exec.Command("systemctl", "daemon-reload").Output()
44+
fmt.Println(string(out))
45+
out, _ = exec.Command("systemctl", "restart", "swiftwave.service").Output()
46+
fmt.Println(string(out))
4547
os.Exit(0)
4648
} else {
4749
fmt.Println("Swiftwave is already up to date")
@@ -68,12 +70,16 @@ func detectDistro() (string, error) {
6870

6971
func updateDebianPackage(packageName string) (bool, error) {
7072
// run apt update first
71-
output, err := exec.Command("apt", "update", "-y").Output()
73+
cmd := exec.Command("apt", "update", "-y")
74+
output, err := cmd.Output()
7275
fmt.Println(string(output))
7376
if err != nil {
7477
return false, err
7578
}
76-
output, err = exec.Command("apt", "install", "--only-upgrade", packageName).Output()
79+
cmd = exec.Command("apt", "install", "--only-upgrade", packageName)
80+
cmd.Env = os.Environ()
81+
cmd.Env = append(cmd.Env, "NEEDRESTART_SUSPEND=1")
82+
output, err = cmd.Output()
7783
fmt.Println(string(output))
7884
if err != nil {
7985
return false, err
@@ -87,7 +93,7 @@ func updateDebianPackage(packageName string) (bool, error) {
8793
}
8894

8995
func updateRedHatPackage(packageName string) (bool, error) {
90-
output, err := exec.Command("dnf", "update", packageName).Output()
96+
output, err := exec.Command("dnf", "update", packageName, "-y").Output()
9197
if err != nil {
9298
return false, err
9399
}

0 commit comments

Comments
 (0)