bundles/mosquitto: introduce, add to node home.nas
All checks were successful
bundlewrap/pipeline/head This commit looks good
All checks were successful
bundlewrap/pipeline/head This commit looks good
This commit is contained in:
parent
f8bbe00d47
commit
9cbf866de7
4 changed files with 119 additions and 9 deletions
39
bundles/mosquitto/files/mosquitto.conf
Normal file
39
bundles/mosquitto/files/mosquitto.conf
Normal file
|
@ -0,0 +1,39 @@
|
|||
per_listener_settings true
|
||||
|
||||
allow_zero_length_clientid true
|
||||
autosave_interval 5
|
||||
autosave_on_changes true
|
||||
log_dest syslog
|
||||
log_timestamp false
|
||||
persistence true
|
||||
persistence_location /var/lib/mosquitto/
|
||||
pid_file /run/mosquitto/mosquitto.pid
|
||||
set_tcp_nodelay ${str(node.metadata.get('mosquitto/tcp_nodelay', True)).lower()}
|
||||
|
||||
% for port, config in sorted(node.metadata.get('mosquitto/listeners', {}).items()):
|
||||
listener ${port}
|
||||
max_connections ${config.get('max_connections', -1)}
|
||||
protocol ${config.get('protocol', 'mqtt')}
|
||||
allow_anonymous ${str(config.get('allow_anonymous', True)).lower()}
|
||||
|
||||
% endfor
|
||||
|
||||
% for bridge, config in sorted(node.metadata.get('mosquitto/bridges', {}).items()):
|
||||
connection ${bridge}
|
||||
address ${config['peer']}
|
||||
bridge_attempt_unsubscribe true
|
||||
cleansession ${str(config.get('cleansession', True)).lower()}
|
||||
notifications true
|
||||
notifications_local_only true
|
||||
remote_clientid ${config.get('client_id', node.name)}
|
||||
% if 'auth' in config:
|
||||
remote_password ${config['auth']['password']}
|
||||
remote_username ${config['auth']['username']}
|
||||
% endif
|
||||
start_type automatic
|
||||
% for topic in config['topics']:
|
||||
topic ${topic['pattern']} ${topic.get('direction', 'in')} ${topic.get('qos', 0)} /${topic.get('local_prefix', bridge)}/ ${topic.get('remote_prefix', '')}
|
||||
% endfor
|
||||
try_private ${str(config.get('try_private', True)).lower()}
|
||||
|
||||
% endfor
|
17
bundles/mosquitto/items.py
Normal file
17
bundles/mosquitto/items.py
Normal file
|
@ -0,0 +1,17 @@
|
|||
files = {
|
||||
'/etc/mosquitto/mosquitto.conf': {
|
||||
'content_type': 'mako',
|
||||
'triggers': {
|
||||
'svc_systemd:mosquitto:restart',
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
svc_systemd = {
|
||||
'mosquitto': {
|
||||
'needs': {
|
||||
'file:/etc/mosquitto/mosquitto.conf',
|
||||
'pkg_apt:mosquitto',
|
||||
},
|
||||
},
|
||||
}
|
33
bundles/mosquitto/metadata.py
Normal file
33
bundles/mosquitto/metadata.py
Normal file
|
@ -0,0 +1,33 @@
|
|||
from bundlewrap.metadata import atomic
|
||||
|
||||
|
||||
defaults = {
|
||||
'apt': {
|
||||
'packages': {
|
||||
'mosquitto': {},
|
||||
'mosquitto-clients': {},
|
||||
},
|
||||
},
|
||||
'mosquitto': {
|
||||
'listeners': {
|
||||
'1883': {},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@metadata_reactor.provides(
|
||||
'iptables/port_rules',
|
||||
)
|
||||
def iptables(metadata):
|
||||
sources = metadata.get('mosquitto/restrict-to', {'*'})
|
||||
result = {}
|
||||
|
||||
for listener in metadata.get('mosquitto/listeners').keys():
|
||||
result[listener] = atomic(sources)
|
||||
|
||||
return {
|
||||
'iptables': {
|
||||
'port_rules': result,
|
||||
},
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue