Skip to content
This repository was archived by the owner on Jan 7, 2024. It is now read-only.

Commit ed90f50

Browse files
authored
Merge pull request #119 from linuxserver/memory-management
2 parents eb685e8 + 62102f3 commit ed90f50

File tree

4 files changed

+113
-13
lines changed

4 files changed

+113
-13
lines changed

readme-vars.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ param_volumes:
2525
# optional container parameters
2626
opt_param_usage_include_env: true
2727
opt_param_env_vars:
28-
- { env_var: "MEM_LIMIT", env_value: "1024M", desc: "Optionally change the Java memory limit (-Xmx) (default is 1024M)." }
29-
- { env_var: "MEM_STARTUP", env_value: "1024M", desc: "Optionally change the Java initial memory (-Xms) (default is 1024M)." }
28+
- { env_var: "MEM_LIMIT", env_value: "1024", desc: "Optionally change the Java memory limit. Set to `default` to reset to default" }
29+
- { env_var: "MEM_STARTUP", env_value: "1024", desc: "Optionally change the Java initial/minimum memory. Set to `default` to reset to default" }
3030

3131
param_usage_include_ports: true
3232
param_ports:
@@ -64,6 +64,7 @@ app_setup_block: |
6464
6565
# changelog
6666
changelogs:
67+
- { date: "23.12.21:", desc: "Move min/max memory config from run to system.properties."}
6768
- { date: "22.12.21:", desc: "Move deb package install to first init to avoid overlayfs performance issues."}
6869
- { date: "13.12.21:", desc: "Rebase 64 bit containers to Focal."}
6970
- { date: "11.12.21:", desc: "Add java opts to mitigate CVE-2021-44228."}

root/defaults/system.properties

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
## system.properties
2+
#
3+
# each unifi instance requires a set of ports:
4+
#
5+
## device inform
6+
# unifi.http.port=8080
7+
## controller UI / API
8+
# unifi.https.port=8443
9+
## portal redirect port for HTTP
10+
# portal.http.port=8880
11+
## portal redirect port for HTTPs
12+
# portal.https.port=8843
13+
## local-bound port for DB server
14+
# unifi.db.port=27117
15+
## UDP port used for STUN
16+
# unifi.stun.port=3478
17+
#
18+
## the IP devices should be talking to for inform
19+
# system_ip=a.b.c.d
20+
## disable mongodb journaling
21+
# unifi.db.nojournal=false
22+
## extra mongod args
23+
# unifi.db.extraargs
24+
#
25+
## HTTPS options
26+
# unifi.https.ciphers=TLS_RSA_WITH_AES_256_CBC_SHA,TLS_RSA_WITH_AES_128_CBC_SHA
27+
# unifi.https.sslEnabledProtocols=TLSv1,SSLv2Hello
28+
# unifi.https.hsts=false
29+
# unifi.https.hsts.max_age=31536000
30+
# unifi.https.hsts.preload=false
31+
# unifi.https.hsts.subdomain=false
32+
#
33+
# Ports reserved for device redirector. There is no need to open
34+
# firewall for these ports on controller, however do NOT set
35+
# controller to use these ports.
36+
#
37+
# portal.redirector.port=8881
38+
# portal.redirector.port.wired=8882
39+
#
40+
# Port used for throughput measurement.
41+
# unifi.throughput.port=6789
42+
#

root/etc/cont-init.d/20-config

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,72 @@ do
1717
[[ ! -L "$i" ]] && ln -s /config/"$(basename "$i")" "$i"
1818
done
1919

20+
if [[ ! -e /config/data/system.properties ]]; then
21+
cp /defaults/system.properties /config/data
22+
fi
23+
24+
if grep -q "xmx" /config/data/system.properties && grep -q "xms" /config/data/system.properties; then
25+
26+
if [[ $MEM_LIMIT == "default" ]]; then
27+
echo "*** Setting Java memory limit to default ***"
28+
sed -i "/unifi.xmx=.*/d" /config/data/system.properties
29+
elif [[ -n $MEM_LIMIT ]]; then
30+
echo "*** Setting Java memory limit to $MEM_LIMIT ***"
31+
sed -i "s/unifi.xmx=.*/unifi.xmx=$MEM_LIMIT/" /config/data/system.properties
32+
fi
33+
34+
if [[ $MEM_STARTUP == "default" ]]; then
35+
echo "*** Setting Java memory minimum to default ***"
36+
sed -i "/unifi.xms=.*/d" /config/data/system.properties
37+
elif [[ -n $MEM_STARTUP ]]; then
38+
echo "*** Setting Java memory minimum to $MEM_STARTUP ***"
39+
sed -i "s/unifi.xms=.*/unifi.xms=$MEM_STARTUP/" /config/data/system.properties
40+
fi
41+
42+
elif grep -q "xmx" /config/data/system.properties; then
43+
44+
if [[ $MEM_LIMIT == "default" ]]; then
45+
echo "*** Setting Java memory limit to default ***"
46+
sed -i "/unifi.xmx=.*/d" /config/data/system.properties
47+
elif [[ -n $MEM_LIMIT ]]; then
48+
echo "*** Setting Java memory limit to $MEM_LIMIT ***"
49+
sed -i "s/unifi.xmx=.*/unifi.xmx=$MEM_LIMIT/" /config/data/system.properties
50+
fi
51+
52+
if [[ -n $MEM_STARTUP ]]; then
53+
echo "*** Setting Java memory minimum to $MEM_STARTUP ***"
54+
echo "unifi.xms=$MEM_STARTUP" >> /config/data/system.properties
55+
fi
56+
57+
elif grep -q "xms" /config/data/system.properties; then
58+
59+
if [[ $MEM_STARTUP == "default" ]]; then
60+
echo "*** Setting Java memory minimum to default ***"
61+
sed -i "/unifi.xms=.*/d" /config/data/system.properties
62+
elif [[ -n $MEM_STARTUP ]]; then
63+
echo "*** Setting Java memory minimum to $MEM_STARTUP ***"
64+
sed -i "s/unifi.xms=.*/unifi.xms=$MEM_STARTUP/" /config/data/system.properties
65+
fi
66+
67+
if [[ -n $MEM_LIMIT ]]; then
68+
echo "*** Setting Java memory limit to $MEM_LIMIT ***"
69+
echo "unifi.xmx=$MEM_LIMIT" >> /config/data/system.properties
70+
fi
71+
72+
else
73+
74+
if [[ -n $MEM_LIMIT ]]; then
75+
echo "*** Setting Java memory limit to $MEM_LIMIT ***"
76+
echo "unifi.xmx=$MEM_LIMIT" >> /config/data/system.properties
77+
fi
78+
79+
if [[ -n $MEM_STARTUP ]]; then
80+
echo "*** Setting Java memory minimum to $MEM_STARTUP ***"
81+
echo "unifi.xms=$MEM_STARTUP" >> /config/data/system.properties
82+
fi
83+
84+
fi
85+
2086
# permissions
2187
chown -R abc:abc \
2288
/config \

root/etc/services.d/unifi/run

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,5 @@
22

33
cd /config || exit
44

5-
if [ -z ${MEM_LIMIT+x} ]; then
6-
MEM_LIMIT="1024M"
7-
fi
8-
9-
if [ -z ${MEM_STARTUP+x} ]; then
10-
exec \
11-
s6-setuidgid abc java -Xmx"${MEM_LIMIT}" -Dlog4j2.formatMsgNoLookups=true -jar /usr/lib/unifi/lib/ace.jar start;
12-
else
13-
exec \
14-
s6-setuidgid abc java -Xms"${MEM_STARTUP}" -Xmx"${MEM_LIMIT}" -Dlog4j2.formatMsgNoLookups=true -jar /usr/lib/unifi/lib/ace.jar start;
15-
fi
5+
exec \
6+
s6-setuidgid abc java -Dlog4j2.formatMsgNoLookups=true -jar /usr/lib/unifi/lib/ace.jar start;

0 commit comments

Comments
 (0)