This repository has been archived by the owner on Feb 21, 2020. It is now read-only.
forked from travishegner/docker-unifi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.sh
executable file
·105 lines (86 loc) · 2.78 KB
/
init.sh
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/bin/bash
trap graceful_stop SIGHUP SIGINT SIGTERM
set_java_home () {
arch=`dpkg --print-architecture 2>/dev/null`
support_java_ver='6 7 8'
java_list=''
for v in ${support_java_ver}; do
java_list=`echo ${java_list} java-$v-openjdk-${arch}`
java_list=`echo ${java_list} java-$v-openjdk`
done
cur_java=`update-alternatives --query java | awk '/^Value: /{print $2}'`
cur_real_java=`readlink -f ${cur_java} 2>/dev/null`
for jvm in ${java_list}; do
jvm_real_java=`readlink -f /usr/lib/jvm/${jvm}/bin/java 2>/dev/null`
[ "${jvm_real_java}" != "" ] || continue
if [ "${jvm_real_java}" == "${cur_real_java}" ]; then
JAVA_HOME="/usr/lib/jvm/${jvm}"
return
fi
done
alts_java=`update-alternatives --query java | awk '/^Alternative: /{print $2}'`
for cur_java in ${alts_java}; do
cur_real_java=`readlink -f ${cur_java} 2>/dev/null`
for jvm in ${java_list}; do
jvm_real_java=`readlink -f /usr/lib/jvm/${jvm}/bin/java 2>/dev/null`
[ "${jvm_real_java}" != "" ] || continue
if [ "${jvm_real_java}" == "${cur_real_java}" ]; then
JAVA_HOME="/usr/lib/jvm/${jvm}"
return
fi
done
done
JAVA_HOME=/usr/lib/jvm/java-6-openjdk
}
NAME="unifi"
DESC="Ubiquiti UniFi Controller"
BASEDIR="/usr/lib/unifi"
MAINCLASS="com.ubnt.ace.Launcher"
PIDFILE="/var/run/${NAME}/${NAME}.pid"
PATH=/bin:/usr/bin:/sbin:/usr/sbin
MONGOPORT=27117
MONGOLOCK="${BASEDIR}/data/db/mongod.lock"
ENABLE_UNIFI=yes
JVM_EXTRA_OPTS=
JSVC_EXTRA_OPTS=
[ -f /etc/default/${NAME} ] && . /etc/default/${NAME}
[ "x${ENABLE_UNIFI}" != "xyes" ] && exit 0
JVM_OPTS="${JVM_EXTRA_OPTS} -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Xmx1024M"
set_java_home
# JSVC - for running java apps as services
JSVC=`which jsvc`
#JSVC_OPTS="-debug"
JSVC_OPTS="${JSVC_OPTS}\
-home ${JAVA_HOME} \
-cp /usr/share/java/commons-daemon.jar:${BASEDIR}/lib/ace.jar \
-pidfile ${PIDFILE} \
-procname ${NAME} \
-outfile SYSLOG \
-errfile SYSLOG \
${JSVC_EXTRA_OPTS} \
${JVM_OPTS}"
[ -d /var/run/${NAME} ] || mkdir -p /var/run/${NAME}
cd ${BASEDIR}
function graceful_stop {
echo "Stopping unifi service..."
${JSVC} ${JSVC_OPTS} -stop ${MAINCLASS} stop
for i in `seq 1 10` ; do
[ -z "$(pgrep -f ${BASEDIR}/lib/ace.jar)" ] && break
# graceful shutdown
[ $i -gt 1 ] && [ -d ${BASEDIR}/run ] && touch ${BASEDIR}/run/server.stop || true
# savage shutdown
[ $i -gt 7 ] && pkill -f ${BASEDIR}/lib/ace.jar || true
sleep 1
done
# shutdown mongod
if [ -f ${MONGOLOCK} ]; then
echo "Stopping mongo service..."
mongo localhost:${MONGOPORT} --eval "db.getSiblingDB('admin').shutdownServer()" >/dev/null 2>&1
fi
echo "Exiting..."
exit 0
}
echo "Starting unifi service..."
${JSVC} ${JSVC_OPTS} ${MAINCLASS} start
sleep 5
while true; do sleep 0.1; done