Add a launcher script to use a config file from a user writeable

area in the home directory. It will also copy the example config
in to the same location so that people can use it as a reference.
This commit is contained in:
Will Cooke
2018-03-21 22:51:54 +00:00
committed by Roger Light
parent 4f838e5161
commit 64ecb657a3
4 changed files with 47 additions and 10 deletions
+2
View File
@@ -0,0 +1,2 @@
port 1883
persistence false
+31
View File
@@ -0,0 +1,31 @@
#!/bin/sh
# Wrapper to check for custom config in $SNAP_USER_COMMON and use it
# otherwise fall back to the included basic config which will at least
# allow mosquitto to run and do something.
# This script will also copy the full example config in to SNAP_USER_COMMON
# so that people can refer to it.
CONFIG_FILE="$SNAP/default_config.conf"
CUSTOM_CONFIG="$SNAP_USER_COMMON/mosquitto.conf"
# Copy the example config if it doesn't exist
if [ ! -e "$SNAP_USER_COMMON/mosquitto_example.conf" ]
then
echo "Copying example config to $SNAP_USER_COMMON/mosquitto_example.conf"
echo "You can create a custom config by creating a file called $CUSTOM_CONFIG"
cp $SNAP/mosquitto.conf $SNAP_USER_COMMON/mosquitto_example.conf
fi
# Does the custom config exist? If so use it.
if [ -e "$CUSTOM_CONFIG" ]
then
echo "Found config in $CUSTOM_CONFIG"
CONFIG_FILE=$CUSTOM_CONFIG
else
echo "Using default config from $CONFIG_FILE"
fi
# Launch the snap
$SNAP/usr/local/sbin/mosquitto -c $CONFIG_FILE $@
-3
View File
@@ -1,3 +0,0 @@
port 1883
persistence true
user root
+14 -7
View File
@@ -9,10 +9,11 @@ description: This is a message broker that supports version 3.1 and 3.1.1 of the
where a sensor or other simple device may be implemented using an arduino for
example.
confinement: strict
grade: stable
apps:
mosquitto:
command: usr/local/sbin/mosquitto -c $SNAP/mosquitto.conf
command: launcher.sh
daemon: simple
restart-condition: always
plugs: [network, network-bind]
@@ -23,7 +24,14 @@ parts:
plugin: dump
source: snap/
prime:
- mosquitto.conf
- default_config.conf
- launcher.sh
config:
plugin: dump
source: .
prime:
- mosquitto.conf
mosquitto:
@@ -42,8 +50,7 @@ parts:
- libuuid1
- libc-ares2
prime:
- usr/local/sbin/mosquitto
- lib/*-linux-gnu/libcrypto.so*
- lib/*-linux-gnu/libssl.so*
- lib/*-linux-gnu/libuuid.so*
- usr/local/sbin/mosquitto
- lib/*-linux-gnu/libcrypto.so*
- lib/*-linux-gnu/libssl.so*
- lib/*-linux-gnu/libuuid.so*