r/mosquitto: Support persistence

Mosquitto can save retained messages, persistent clients, etc. to the
filesystem and restore them at startup.  This allows state to be
maintained even after the process restarts.
collectd-buildroot
Dustin 2022-05-29 11:25:25 -05:00
parent 24228953b0
commit e7534d36cf
2 changed files with 41 additions and 0 deletions

View File

@ -5,6 +5,17 @@
tags: tags:
- install - install
- name: ensure mosquitto persistence directory exists
file:
path: '{{ mosquitto_persistence_location }}'
mode: u=rwx,go=
owner: mosquitto
group: mosquitto
state: directory
when: mosquitto_persistence_location|d(none) is not none
tags:
- datadir
- name: ensure mosquitto certificate is installed - name: ensure mosquitto certificate is installed
copy: copy:
src: certs/mosquitto/{{ inventory_hostname }}.cer src: certs/mosquitto/{{ inventory_hostname }}.cer
@ -15,6 +26,8 @@
notify: notify:
- restart mosquitto - restart mosquitto
when: mosquitto_certfile is defined when: mosquitto_certfile is defined
tags:
- cert
- name: ensure mosquitto private key is installed - name: ensure mosquitto private key is installed
copy: copy:
src: certs/mosquitto/{{ inventory_hostname }}.key src: certs/mosquitto/{{ inventory_hostname }}.key
@ -26,6 +39,8 @@
notify: notify:
- restart mosquitto - restart mosquitto
when: mosquitto_keyfile is defined when: mosquitto_keyfile is defined
tags:
- cert
- name: ensure mosquitto is configured - name: ensure mosquitto is configured
template: template:
@ -34,6 +49,8 @@
mode: '0644' mode: '0644'
notify: notify:
- restart mosquitto - restart mosquitto
tags:
- mosquitto-config
- meta: flush_handlers - meta: flush_handlers
@ -41,7 +58,11 @@
service: service:
name: mosquitto name: mosquitto
enabled: true enabled: true
tags:
- service
- name: ensure mosquitto is running - name: ensure mosquitto is running
service: service:
name: mosquitto name: mosquitto
state: started state: started
tags:
- service

View File

@ -405,31 +405,51 @@ listener {{ listener.port }} {{ listener.address|d('') }}
# autosave_on_changes. # autosave_on_changes.
# Note that writing of the persistence database can be forced by # Note that writing of the persistence database can be forced by
# sending mosquitto a SIGUSR1 signal. # sending mosquitto a SIGUSR1 signal.
{% if mosquitto_autosave_interval|d(none) is not none %}
autosave_interval {{ mosquitto_autosave_interval }}
{% else %}
#autosave_interval 1800 #autosave_interval 1800
{% endif %}
# If true, mosquitto will count the number of subscription changes, retained # If true, mosquitto will count the number of subscription changes, retained
# messages received and queued messages and if the total exceeds # messages received and queued messages and if the total exceeds
# autosave_interval then the in-memory database will be saved to disk. # autosave_interval then the in-memory database will be saved to disk.
# If false, mosquitto will save the in-memory database to disk by treating # If false, mosquitto will save the in-memory database to disk by treating
# autosave_interval as a time in seconds. # autosave_interval as a time in seconds.
{% if mosquitto_autosave_on_changes|d(none) is not none %}
autosave_on_changes {{ mosquitto_autosave_on_changes|bool|string|lower }}
{% else %}
#autosave_on_changes false #autosave_on_changes false
{% endif %}
# Save persistent message data to disk (true/false). # Save persistent message data to disk (true/false).
# This saves information about all messages, including # This saves information about all messages, including
# subscriptions, currently in-flight messages and retained # subscriptions, currently in-flight messages and retained
# messages. # messages.
# retained_persistence is a synonym for this option. # retained_persistence is a synonym for this option.
{% if mosquitto_persistence|d(none) is not none %}
persistence {{ mosquitto_persistence|bool|string|lower }}
{% else %}
#persistence false #persistence false
{% endif %}
# The filename to use for the persistent database, not including # The filename to use for the persistent database, not including
# the path. # the path.
{% if mosquitto_persistence_file|d(none) is not none %}
persistence_file {{ mosquitto_persistence_file }}
{% else %}
#persistence_file mosquitto.db #persistence_file mosquitto.db
{% endif %}
# Location for persistent database. # Location for persistent database.
# Default is an empty string (current directory). # Default is an empty string (current directory).
# Set to e.g. /var/lib/mosquitto if running as a proper service on Linux or # Set to e.g. /var/lib/mosquitto if running as a proper service on Linux or
# similar. # similar.
{% if mosquitto_persistence_location|d(none) is not none %}
persistence_location {{ mosquitto_persistence_location }}
{% else %}
#persistence_location #persistence_location
{% endif %}
# ================================================================= # =================================================================