|
6 | 6 | "os/exec" |
7 | 7 | "os/signal" |
8 | 8 | "path/filepath" |
| 9 | + "strings" |
9 | 10 | "syscall" |
10 | 11 | "time" |
11 | 12 |
|
@@ -92,20 +93,23 @@ func main() { |
92 | 93 | "This message appears because the program was started directly instead of using 'start'.") |
93 | 94 | return |
94 | 95 | } |
| 96 | + autoUpdaterEnabled := configs.Coordinator.Canopy.AutoUpdate |
| 97 | + binPath := configs.Coordinator.BinPath |
95 | 98 | // 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) |
98 | 101 | } |
99 | | - if configs.Coordinator.Canopy.AutoUpdate { |
| 102 | + if autoUpdaterEnabled { |
100 | 103 | logger.Infof("auto-update enabled, starting coordinator on version %s", rpc.SoftwareVersion) |
101 | 104 | } else { |
102 | | - logger.Infof("auto-update disabled, starting binary: %s", configs.Coordinator.BinPath) |
| 105 | + logger.Infof("auto-update disabled, starting binary: %s", binPath) |
103 | 106 | } |
104 | 107 | // handle external shutdown signals |
105 | 108 | sigChan := make(chan os.Signal, 1) |
106 | 109 | signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT) |
107 | 110 | // setup the dependencies |
108 | | - updater := NewReleaseManager(configs.Updater, rpc.SoftwareVersion, configs.Coordinator.Canopy.AutoUpdate) |
| 111 | + updater := NewReleaseManager(configs.Updater, |
| 112 | + getSoftwareVersion(autoUpdaterEnabled, binPath), autoUpdaterEnabled) |
109 | 113 | snapshot := NewSnapshotManager(configs.Snapshot) |
110 | 114 | // setup plugin updater and config if configured |
111 | 115 | var pluginUpdater *ReleaseManager |
@@ -244,6 +248,17 @@ func isExecutable(path string) bool { |
244 | 248 | return info.Mode()&0111 != 0 |
245 | 249 | } |
246 | 250 |
|
| 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 | + |
247 | 262 | // envOrDefault returns the value of the environment variable with the given key, |
248 | 263 | // or the default value if the variable is not set. |
249 | 264 | func envOrDefault(key, defaultValue string) string { |
|
0 commit comments