blob: 3d9e93a96fc0930d3aa4cc917063ea139274475b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
#!/bin/bash
#
# Generate Mosquitto configuration
#
set -euo pipefail
CONFIG_DIR="${CONFIG_DIR:-/etc/cluster-config}"
MOSQUITTO_DIR="/etc/mosquitto"
MOSQUITTO_CONFIG="$MOSQUITTO_DIR/mosquitto.conf"
mkdir -p "$MOSQUITTO_DIR"
# Source environment
if [ -f /etc/cluster-config/environment/mqtt.env ]; then
source /etc/cluster-config/environment/mqtt.env
fi
# Read service config
SERVICE_CONFIG="$CONFIG_DIR/services/mqtt.yaml"
# Generate mosquitto.conf
cat > "$MOSQUITTO_CONFIG" <<EOF
# Mosquitto MQTT Broker Configuration
# Listener
listener 1883 ${NODE_IP:-0.0.0.0}
protocol mqtt
# Persistence
persistence true
persistence_location /var/lib/mosquitto/
autosave_interval 300
# Logging
log_dest syslog
log_type all
log_timestamp true
log_timestamp_format %Y-%m-%dT%H:%M:%S
# Security
allow_anonymous false
password_file $MOSQUITTO_DIR/passwd
acl_file $MOSQUITTO_DIR/acl
# Connection limits
max_connections 10000
# Performance
max_queued_messages 1000
max_inflight_messages 100
EOF
# Create empty passwd and acl files if they don't exist
touch "$MOSQUITTO_DIR/passwd"
touch "$MOSQUITTO_DIR/acl"
chown -R mosquitto:mosquitto "$MOSQUITTO_DIR" 2>/dev/null || true
echo "Mosquitto configuration generated at $MOSQUITTO_CONFIG"
|