From 64ecb657a33fef92c58755f5d40253d670f73278 Mon Sep 17 00:00:00 2001 From: Will Cooke Date: Mon, 19 Mar 2018 18:39:30 +0000 Subject: [PATCH] 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. --- snap/default_config.conf | 2 ++ snap/launcher.sh | 31 +++++++++++++++++++++++++++++++ snap/mosquitto.conf | 3 --- snap/snapcraft.yaml | 21 ++++++++++++++------- 4 files changed, 47 insertions(+), 10 deletions(-) create mode 100644 snap/default_config.conf create mode 100755 snap/launcher.sh delete mode 100644 snap/mosquitto.conf diff --git a/snap/default_config.conf b/snap/default_config.conf new file mode 100644 index 00000000..2647d15e --- /dev/null +++ b/snap/default_config.conf @@ -0,0 +1,2 @@ +port 1883 +persistence false diff --git a/snap/launcher.sh b/snap/launcher.sh new file mode 100755 index 00000000..803999e6 --- /dev/null +++ b/snap/launcher.sh @@ -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 $@ diff --git a/snap/mosquitto.conf b/snap/mosquitto.conf deleted file mode 100644 index 43396eb7..00000000 --- a/snap/mosquitto.conf +++ /dev/null @@ -1,3 +0,0 @@ -port 1883 -persistence true -user root diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index b5925130..216b1914 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -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*