mirror of
https://github.com/dpup/meshstream.git
synced 2026-03-28 17:42:37 +01:00
Unique client id and fix graceful shutdown
This commit is contained in:
9
main.go
9
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
|
||||
}
|
||||
|
||||
|
||||
@@ -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."
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user