diff --git a/main.go b/main.go index 79192db..5a96bf0 100644 --- a/main.go +++ b/main.go @@ -72,8 +72,8 @@ func parseConfig() *Config { flag.StringVar(&config.MQTTBroker, "mqtt-broker", getEnv("MQTT_BROKER", "mqtt.bayme.sh"), "MQTT broker address") flag.StringVar(&config.MQTTUsername, "mqtt-username", getEnv("MQTT_USERNAME", "meshdev"), "MQTT username") flag.StringVar(&config.MQTTPassword, "mqtt-password", getEnv("MQTT_PASSWORD", "large4cats"), "MQTT password") - flag.StringVar(&config.MQTTTopicPrefix, "mqtt-topic-prefix", getEnv("MQTT_TOPIC_PREFIX", "msh/US/CA/Motherlode"), "MQTT topic prefix") - flag.StringVar(&config.MQTTClientID, "mqtt-client-id", getEnv("MQTT_CLIENT_ID", "meshstream-client"), "MQTT client ID") + flag.StringVar(&config.MQTTTopicPrefix, "mqtt-topic-prefix", getEnv("MQTT_TOPIC_PREFIX", "msh/US/bayarea"), "MQTT topic prefix") + flag.StringVar(&config.MQTTClientID, "mqtt-client-id", getEnv("MQTT_CLIENT_ID", "meshstream"), "MQTT client ID") // MQTT connection tuning parameters flag.IntVar(&config.MQTTKeepAlive, "mqtt-keepalive", intFromEnv("MQTT_KEEPALIVE", 60), "MQTT keep alive interval in seconds") @@ -98,14 +98,15 @@ func parseConfig() *Config { flag.IntVar(&config.CacheSize, "cache-size", intFromEnv("CACHE_SIZE", 50), "Number of packets to cache for new subscribers") flag.BoolVar(&config.VerboseLogging, "verbose", boolFromEnv("VERBOSE_LOGGING", false), "Enable verbose message logging") - // Parse flags flag.Parse() - // Process channel keys from the command line if *channelKeysFlag != "" { config.ChannelKeys = strings.Split(*channelKeysFlag, ",") } + // Unique client ID for this process. + config.MQTTClientID = fmt.Sprintf("%s-%d-%d", config.MQTTClientID, os.Getpid(), time.Now().Unix()) + return config } diff --git a/scripts/push-to-ecr.sh b/scripts/push-to-ecr.sh index 5c5b3bd..8b8801c 100755 --- a/scripts/push-to-ecr.sh +++ b/scripts/push-to-ecr.sh @@ -14,6 +14,7 @@ if [ -f .env ]; then value=$(echo "$value" | sed -E 's/^"(.*)"$/\1/' | sed -E "s/^'(.*)'$/\1/") # Export the variable preserving spaces in the value export "$key=$value" + echo "$key=$value" done < .env else echo "Warning: .env file not found. Using default environment variables." diff --git a/server/server.go b/server/server.go index 86180e9..23c6f84 100644 --- a/server/server.go +++ b/server/server.go @@ -96,15 +96,18 @@ func (s *Server) Start() error { // Stop shuts down the server func (s *Server) Stop() error { - // Set the shutdown flag first to prevent new connections from starting streams - s.isShuttingDown.Store(true) + if !s.isShuttingDown.Load() { + s.logger.Info("Stopping server...") + // Set the shutdown flag first to prevent new connections from starting streams + s.isShuttingDown.Store(true) - // Signal all active connections to close - close(s.shutdown) + // Signal all active connections to close + close(s.shutdown) - // Then shut down the HTTP server - if s.server != nil { - return s.server.Shutdown() + // Then shut down the HTTP server + if s.server != nil { + return s.server.Shutdown() + } } return nil }