Skip to content

Commit c79c38f

Browse files
committed
fix: auto updater using coordinator version for initial update check
1 parent 0aa16a7 commit c79c38f

1 file changed

Lines changed: 20 additions & 5 deletions

File tree

cmd/auto-update/main.go

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"os/exec"
77
"os/signal"
88
"path/filepath"
9+
"strings"
910
"syscall"
1011
"time"
1112

@@ -92,20 +93,23 @@ func main() {
9293
"This message appears because the program was started directly instead of using 'start'.")
9394
return
9495
}
96+
autoUpdaterEnabled := configs.Coordinator.Canopy.AutoUpdate
97+
binPath := configs.Coordinator.BinPath
9598
// ensure the binary exists before proceeding
96-
if !isExecutable(configs.Coordinator.BinPath) {
97-
logger.Fatalf("canopy binary not found or not executable: %s", configs.Coordinator.BinPath)
99+
if !isExecutable(binPath) {
100+
logger.Fatalf("canopy binary not found or not executable: %s", binPath)
98101
}
99-
if configs.Coordinator.Canopy.AutoUpdate {
102+
if autoUpdaterEnabled {
100103
logger.Infof("auto-update enabled, starting coordinator on version %s", rpc.SoftwareVersion)
101104
} else {
102-
logger.Infof("auto-update disabled, starting binary: %s", configs.Coordinator.BinPath)
105+
logger.Infof("auto-update disabled, starting binary: %s", binPath)
103106
}
104107
// handle external shutdown signals
105108
sigChan := make(chan os.Signal, 1)
106109
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
107110
// setup the dependencies
108-
updater := NewReleaseManager(configs.Updater, rpc.SoftwareVersion, configs.Coordinator.Canopy.AutoUpdate)
111+
updater := NewReleaseManager(configs.Updater,
112+
getSoftwareVersion(autoUpdaterEnabled, binPath), autoUpdaterEnabled)
109113
snapshot := NewSnapshotManager(configs.Snapshot)
110114
// setup plugin updater and config if configured
111115
var pluginUpdater *ReleaseManager
@@ -244,6 +248,17 @@ func isExecutable(path string) bool {
244248
return info.Mode()&0111 != 0
245249
}
246250

251+
func getSoftwareVersion(autoUpdate bool, binPath string) string {
252+
if !autoUpdate {
253+
return rpc.SoftwareVersion
254+
}
255+
out, err := exec.Command(binPath, "version").Output()
256+
if err != nil {
257+
panic(fmt.Sprintf("failed to get software version from binary: %v", err))
258+
}
259+
return strings.TrimSpace(string(out))
260+
}
261+
247262
// envOrDefault returns the value of the environment variable with the given key,
248263
// or the default value if the variable is not set.
249264
func envOrDefault(key, defaultValue string) string {

0 commit comments

Comments
 (0)