1
0
mirror of https://github.com/eclipse/mosquitto.git synced 2025-05-09 01:01:11 +08:00

Snap config for daemon or user mode.

This commit is contained in:
Roger A. Light 2018-04-04 23:05:04 +01:00
parent 9d46fbf03c
commit ff1afbabbf
2 changed files with 21 additions and 8 deletions

View File

@ -1,2 +1,3 @@
port 1883
persistence false
user root

View File

@ -1,20 +1,32 @@
#!/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
# Wrapper to check for custom config in $SNAP_USER_COMMON or $SNAP_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.
# This script will also copy the full example config in to SNAP_USER_COMMON or
# SNAP_COMMON so that people can refer to it.
#
# The decision about whether to use SNAP_USER_COMMON or SNAP_COMMON is taken
# based on the user that runs the command. If the user is root, it is assumed
# that mosquitto is being run as a system daemon, and SNAP_COMMON will be used.
# If a non-root user runs the command, then SNAP_USER_COMMON will be used.
if [ "$USER" = "root" ]
then
COMMON=$SNAP_COMMON
else
COMMON=$SNAP_USER_COMMON
fi
CONFIG_FILE="$SNAP/default_config.conf"
CUSTOM_CONFIG="$SNAP_USER_COMMON/mosquitto.conf"
CUSTOM_CONFIG="$COMMON/mosquitto.conf"
# Copy the example config if it doesn't exist
if [ ! -e "$SNAP_USER_COMMON/mosquitto_example.conf" ]
if [ ! -e "$COMMON/mosquitto_example.conf" ]
then
echo "Copying example config to $SNAP_USER_COMMON/mosquitto_example.conf"
echo "Copying example config to $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
cp $SNAP/mosquitto.conf $COMMON/mosquitto_example.conf
fi