Skip to content

Commit

Permalink
Add a launcher script to use a config file from a user writeable
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
8none1 authored and ralight committed Mar 21, 2018
1 parent 4f838e5 commit 64ecb65
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 10 deletions.
2 changes: 2 additions & 0 deletions snap/default_config.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
port 1883
persistence false
31 changes: 31 additions & 0 deletions snap/launcher.sh
Original file line number Diff line number Diff line change
@@ -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 changes: 0 additions & 3 deletions snap/mosquitto.conf

This file was deleted.

21 changes: 14 additions & 7 deletions snap/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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:
Expand All @@ -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*

0 comments on commit 64ecb65

Please sign in to comment.