-
Notifications
You must be signed in to change notification settings - Fork 5
/
unifi.init
executable file
·80 lines (57 loc) · 2.24 KB
/
unifi.init
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/bash
# Startup script for Ubiquiti UniFi
set -ex
NAME="unifi"
BASEDIR="/usr/lib/unifi"
MAINCLASS="com.ubnt.ace.Launcher"
PATH=/bin:/usr/bin:/sbin:/usr/sbin
MONGOPORT=27117
JAVA_ENTROPY_GATHER_DEVICE=
JVM_MAX_HEAP_SIZE=1024M
JVM_INIT_HEAP_SIZE=
UNIFI_JVM_EXTRA_OPTS=
ENABLE_UNIFI=yes
JVM_EXTRA_OPTS="-XX:+ExitOnOutOfMemoryError -XX:+CrashOnOutOfMemoryError"
[ -f "/etc/default/${NAME}" ] && . "/etc/default/${NAME}"
[ "x${ENABLE_UNIFI}" != "xyes" ] && exit 0
# Unifi Init and Init-UOS
/usr/lib/unifi/bin/unifi-network-service-helper init
/usr/lib/unifi/bin/unifi-network-service-helper init-uos
DATADIR=${UNIFI_DATA_DIR:-/var/lib/${NAME}}
LOGDIR=${UNIFI_LOG_DIR:-/var/log/${NAME}}
RUNDIR=${UNIFI_RUN_DIR:-/var/run/${NAME}}
JVM_EXTRA_OPTS="${JVM_EXTRA_OPTS} -Dunifi.datadir=${DATADIR} -Dunifi.logdir=${LOGDIR} -Dunifi.rundir=${RUNDIR} -XX:ErrorFile=${LOGDIR}/unifi_crash.log -Xlog:gc:logs/gc.log:time:filecount=2,filesize=5M"
if [ ! -z "${JAVA_ENTROPY_GATHER_DEVICE}" ]; then
JVM_EXTRA_OPTS="${JVM_EXTRA_OPTS} -Djava.security.egd=${JAVA_ENTROPY_GATHER_DEVICE}"
fi
if [ ! -z "${JVM_MAX_HEAP_SIZE}" ]; then
JVM_EXTRA_OPTS="${JVM_EXTRA_OPTS} -Xmx${JVM_MAX_HEAP_SIZE}"
fi
if [ ! -z "${JVM_INIT_HEAP_SIZE}" ]; then
JVM_EXTRA_OPTS="${JVM_EXTRA_OPTS} -Xms${JVM_INIT_HEAP_SIZE}"
fi
if [ ! -z "${UNIFI_JVM_EXTRA_OPTS}" ]; then
JVM_EXTRA_OPTS="${JVM_EXTRA_OPTS} ${UNIFI_JVM_EXTRA_OPTS}"
fi
JVM_OPTS="${JVM_EXTRA_OPTS} -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djava.awt.headless=true"
UNIFI_USER=${UNIFI_USER:-unifi}
MONGOLOCK="${DATADIR}/db/mongod.lock"
UNIFI_UID=$(id -u "${UNIFI_USER}")
DATADIR_UID=$(stat "${DATADIR}" -Lc %u)
if (( UNIFI_UID != DATADIR_UID )); then
msg="${NAME} cannot start. Please create ${UNIFI_USER} user, and chown -R ${UNIFI_USER} ${DATADIR} ${LOGDIR} ${RUNDIR}"
echo "$msg" >&2
exit 1
fi
cd ${BASEDIR}
echo "Starting ${NAME}"
/usr/bin/java ${JVM_OPTS} \
--add-opens java.base/java.lang=ALL-UNNAMED \
--add-opens java.base/java.time=ALL-UNNAMED \
--add-opens java.base/sun.security.util=ALL-UNNAMED \
--add-opens java.base/java.io=ALL-UNNAMED \
--add-opens java.rmi/sun.rmi.transport=ALL-UNNAMED \
-jar "${BASEDIR}/lib/ace.jar" start
# After exiting
/usr/lib/unifi/bin/unifi-network-service-helper cleanup
exit 0