Skip to content

Commit

Permalink
Auto-save on changes and persist data to data directory
Browse files Browse the repository at this point in the history
  • Loading branch information
jzombie committed Jul 31, 2024
1 parent 55aea84 commit ef13877
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
.env

data/*
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ services:
- ./mosquitto/mosquitto.conf:/mosquitto/config/mosquitto.conf
- ./mosquitto/aclfile:/mosquitto/config/aclfile
- ./mosquitto/entrypoint.sh:/entrypoint.sh
- ./data/:/var/lib/mosquitto/
entrypoint: /entrypoint.sh
restart: unless-stopped

Expand Down
6 changes: 6 additions & 0 deletions mosquitto/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#!/bin/sh

# Set permissions for the aclfile
chmod 0700 /mosquitto/config/aclfile

# Ensure the persistence directory exists and set appropriate permissions
mkdir -p /var/lib/mosquitto
chown mosquitto:mosquitto /var/lib/mosquitto
chmod 0755 /var/lib/mosquitto

# Start the Mosquitto service
exec mosquitto -c /mosquitto/config/mosquitto.conf
13 changes: 13 additions & 0 deletions mosquitto/mosquitto.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,16 @@ listener 9001
protocol websockets

acl_file /mosquitto/config/aclfile

# Enable persistent storage
persistence true

# Set the location for the persistence files
persistence_location /var/lib/mosquitto

# If configured with `autosave_on_changes` represents, this represents the total
# number of changes before an autosave. Otherwise, it uses seconds, and defaults
# to 1800 (30 minutes).
autosave_interval 1

autosave_on_changes true

0 comments on commit ef13877

Please sign in to comment.