#!/bin/sh set -e USERNAME="unifi" BASEDIR="/usr/lib/unifi" DATA_DIR="${BASEDIR}/data" # Default UID/GID to owner of the data directory UNIFI_UID=${UNIFI_UID:-$(stat -L -c "%u" $DATA_DIR)} UNIFI_GID=${UNIFI_GID:-$(stat -L -c "%u" $DATA_DIR)} if [ "$UNIFI_GID" = 0 -o "$UNIFI_GID" = 0 ]; then echo "Set UNIFI_UID and UNIFI_GID in environment" exit 1 else echo "Unifi UID/GID: $UNIFI_UID $UNIFI_GID" fi cd ${BASEDIR} # Create the user and group if ! getent group ${USERNAME} > /dev/null 2>&1; then addgroup -g ${UNIFI_GID} -S ${USERNAME} fi if ! getent passwd ${USERNAME} > /dev/null 2>&1; then adduser -u ${UNIFI_UID} -S -h /var/lib/${USERNAME} -H -D -G ${USERNAME} ${USERNAME} fi # Update permissions on the root directories chown -R ${USERNAME}:${USERNAME} \ /var/lib/unifi \ /var/log/unifi \ /var/run/unifi \ /usr/lib/unifi/dl ln -s /var/log/unifi /logs # Cleanup mongodb lock file if it exists otherwise the controller will freeze # forever trying to start Mongo [ -f data/db/mongod.lock ] && rm data/db/mongod.lock if [ -n "$MONGO_URL" ]; then echo "Using external mongodb instance" echo "db.mongo.local=false" >> /var/lib/unifi/system.properties echo "db.mongo.uri=${MONGO_URL}" >> /var/lib/unifi/system.properties echo "statdb.mongo.uri=${MONGO_STATS_URL}" >> /var/lib/unifi/system.properties echo "unifi.db.name=${MONGO_DB_NAME:-ace}" >> /var/lib/unifi/system.properties echo "statdb.db.name=${MONGO_STATS_DB_NAME:-ace_stat}" >> /var/lib/unifi/system.properties fi # If this is set that the controller will start with no settings and will run # the setup. # # WARNING! If this is set on a live database then the controller will delete # all data and start fresh. if [ -z "$START_DEFAULT" ]; then echo "is_default=false" >> /var/lib/unifi/system.properties fi # Replace the current process with a scoped-down controller. The java app # is designed to do its own job control but it has to run with an init # system or it doesn't get the signals from docker. # # Use the snappy native library installed with apk because the bundled on # is built against libc which is not available in Alpine. Without this # inform will fail with a decompression library error. # NOTE: This has been migrated to simplevisor.json