aboutsummaryrefslogtreecommitdiff
path: root/unifi-video/entrypoint.sh
diff options
context:
space:
mode:
Diffstat (limited to 'unifi-video/entrypoint.sh')
-rwxr-xr-xunifi-video/entrypoint.sh97
1 files changed, 0 insertions, 97 deletions
diff --git a/unifi-video/entrypoint.sh b/unifi-video/entrypoint.sh
deleted file mode 100755
index 7b1e7b1..0000000
--- a/unifi-video/entrypoint.sh
+++ /dev/null
@@ -1,97 +0,0 @@
1#!/bin/sh
2
3set -e
4
5USERNAME="unifi-video"
6BASEDIR="/usr/lib/unifi-video"
7DATA_DIR="${BASEDIR}/data"
8
9# Default UID/GID to owner of the data directory
10UNIFI_UID=${UNIFI_UID:-$(stat -L -c "%u" $DATA_DIR)}
11UNIFI_GID=${UNIFI_GID:-$(stat -L -c "%u" $DATA_DIR)}
12
13if [ "$UNIFI_UID" = 0 -o "$UNIFI_GID" = 0 ]; then
14 echo "Set UNIFI_UID and UNIFI_GID in environment"
15 exit 1
16else
17 echo "Unifi UID/GID: $UNIFI_UID $UNIFI_GID"
18fi
19
20cd ${BASEDIR}
21
22# Create the user and group if they don't exist
23if ! grep "^${USERNAME}:" /etc/group &>/dev/null; then
24 addgroup -g ${UNIFI_GID} -S ${USERNAME}
25fi
26if ! grep "^${USERNAME}:" /etc/passwd &>/dev/null; then
27 adduser -u ${UNIFI_UID} -S -h /var/lib/${USERNAME} -H -D -G ${USERNAME} ${USERNAME}
28fi
29
30mkdir -p /var/log/mongodb/logs
31
32# Update permissions on the root directories
33chown -R ${USERNAME}:${USERNAME} \
34 /var/run/unifi-video \
35 /var/log/unifi-video \
36 /var/lib/unifi-video \
37 /var/log/mongodb/logs
38
39chown -R ${USERNAME}:${USERNAME} \
40 /usr/lib/unifi-video/conf/evostream \
41 /usr/lib/unifi-video/webapps \
42 /usr/lib/unifi-video/conf/Catalina \
43 /usr/lib/unifi-video/work
44
45# But do not let the unifi user write the ROOT WAR
46chown root:root /usr/lib/unifi-video/webapps/ROOT.war
47
48# Setup tmpfs if the user mounted it
49TMPFS_ARG=
50TMPFS_DIR="/var/cache/unifi-video"
51if [ -d $TMPFS_DIR ]; then
52 TMPFS_ARG="-Dav.tempdir=${TMPFS_DIR}"
53 chown ${USERNAME} ${TMPFS_DIR}
54 chmod -R 0700 ${TMPFS_DIR}
55fi
56
57# Do the base setup and migrate files
58if [ ! -f "${DATA_DIR}/system.properties" ]; then
59 cp -f "${BASEDIR}/etc/system.properties" "${DATA_DIR}/system.properties"
60fi
61
62if [ -f "${DATA_DIR}/truststore" ]; then
63 rm -f "${DATA_DIR}/truststore"
64fi
65
66if [ ! -f "${DATA_DIR}/ufv-truststore" ]; then
67 cp -f "${BASEDIR}/etc/ufv-truststore" "${DATA_DIR}/ufv-truststore"
68fi
69
70chown -h ${USERNAME}:${USERNAME} \
71 "${DATA_DIR}" \
72 "${DATA_DIR}/system.properties" \
73 "${DATA_DIR}/ufv-truststore"
74
75# Cleanup mongodb lock file if it exists otherwise the controller will freeze
76# forever trying to start Mongo
77[ -f data/db/mongod.lock ] && rm data/db/mongod.lock
78
79# Allow running a shell in the container
80if [ ! -z "$@" ]; then
81 /sbin/su-exec ${USERNAME} "$@"
82else
83 # Replace the current process with a scoped-down controller. The java app
84 # is designed to do its own job control but it has to run with an init
85 # system or it doesn't get the signals from docker.
86 exec /usr/bin/dumb-init -c /sbin/su-exec ${USERNAME} /usr/lib/jvm/default-jvm/jre/bin/java \
87 -cp ${BASEDIR}/lib/airvision.jar \
88 -Dlog4j.configurationFile=${BASEDIR}/log4j2.json \
89 ${TMPFS_ARG} \
90 -Djava.library.path=${BASEDIR}/lib \
91 -Djavax.net.ssl.trustStore=${DATA_DIR}/ufv-truststore \
92 -Djava.security.egd=file:/dev/urandom \
93 -Xmx$(free -m | awk 'NR==2{printf "%dM\n", $2*0.26 }') \
94 -Djava.awt.headless=true \
95 -Dfile.encoding=UTF-8 \
96 com.ubnt.airvision.Main start
97fi