#!/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 # 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 fi # Allow running a shell in the container if [ ! -z "$@" ]; then /sbin/su-exec ${USERNAME} "$@" else # 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. exec /usr/bin/dumb-init -c /sbin/su-exec ${USERNAME} /usr/lib/jvm/default-jvm/bin/java \ -cp ${BASEDIR}/lib/ace.jar \ -Dlog4j.configuration=file:${BASEDIR}/log4j.properties \ -Dunifi.datadir=${BASEDIR}/data \ -Dunifi.logdir=${BASEDIR}/logs \ -Dunifi.rundir=${BASEDIR}/run \ -Xmx1024M \ -Djava.awt.headless=true \ -Dorg.xerial.snappy.use.systemlib=true \ -Dfile.encoding=UTF-8 \ com.ubnt.ace.Launcher start fi