summaryrefslogtreecommitdiffstats
path: root/adei/files/opt/scripts/run-apache.sh
diff options
context:
space:
mode:
authorSuren A. Chilingaryan <csa@suren.me>2019-10-01 19:30:54 +0200
committerSuren A. Chilingaryan <csa@suren.me>2019-10-01 19:30:54 +0200
commit79c76eaef5039276bb3a8725ac8c9f05f89ef0de (patch)
tree1bde68d36ce44d75fafc6dfb41f5f6d2b555815f /adei/files/opt/scripts/run-apache.sh
parentbc1b77dc912adfd040d432972e2d3256c9ea2065 (diff)
downloadadei-79c76eaef5039276bb3a8725ac8c9f05f89ef0de.tar.gz
adei-79c76eaef5039276bb3a8725ac8c9f05f89ef0de.tar.bz2
adei-79c76eaef5039276bb3a8725ac8c9f05f89ef0de.tar.xz
adei-79c76eaef5039276bb3a8725ac8c9f05f89ef0de.zip
Optimize Dockerfile
Diffstat (limited to 'adei/files/opt/scripts/run-apache.sh')
-rwxr-xr-xadei/files/opt/scripts/run-apache.sh66
1 files changed, 66 insertions, 0 deletions
diff --git a/adei/files/opt/scripts/run-apache.sh b/adei/files/opt/scripts/run-apache.sh
new file mode 100755
index 0000000..202df62
--- /dev/null
+++ b/adei/files/opt/scripts/run-apache.sh
@@ -0,0 +1,66 @@
+#! /bin/bash
+
+LOCK_FILE=.lock
+(
+ flock -x 10
+ if [ ! -f /adei/cfg/apache.conf ]; then
+ cp -a /opt/configs/apache* /adei/cfg
+ fi
+) 10> /adei/cfg/$LOCK_FILE
+
+
+function ised {
+#Creates temporary file in the file folder
+# sed -i'' "$@"
+
+ tmp=$(mktemp)
+ fn="${@: -1}"
+ echo $fn
+ sed "$@" > "$tmp"
+ cat "$tmp" > "$fn"
+
+ rm -f "$tmp"
+}
+
+#Keep 80 & 443
+#ised -re '/Listen/ { /(80|443)/!d }' /etc/apache2/listen.conf
+#if [ -n "$ADEI_PORTS" ]; then
+# for port in $ADEI_PORTS; do
+# [ $port -eq 80 ] && continue
+# [ $port -eq 443 ] && continue
+# echo "Listen $port" >> /etc/apache2/listen.conf
+# done
+#fi
+
+if [ -n "$ADEI_PORTS" ]; then
+ echo -n "" > /etc/apache2/listen.conf
+ for port in $ADEI_PORTS; do
+ echo "Listen $port" >> /etc/apache2/listen.conf
+ done
+fi
+
+if [ -n "$APACHE_SERVERS" -a "$APACHE_SERVERS" -ne 0 ]; then
+ if [ $APACHE_SERVERS -eq 1 ]; then
+ start=1
+ limit=1
+ min_spare=1
+ max_spare=1
+ elif [ $APACHE_SERVERS -lt 10 ]; then
+ start=$(($APACHE_SERVERS / 2))
+ limit=$APACHE_SERVERS
+ min_spare=$start
+ max_spare=$limit
+ else
+ start=0
+ limit=$APACHE_SERVERS
+ min_spare=0
+ max_spare=0
+ fi
+ [ $start -eq 0 ] || ised -re "s/StartServers(.*)/StartServers $start/" /etc/apache2/server-tuning.conf
+ [ $limit -eq 0 ] || ised -re "s/MaxClients(.*)/MaxClients $limit/" /etc/apache2/server-tuning.conf
+ [ $min_spare -eq 0 ] || ised -re "s/MinSpareServers(.*)/MinSpareServers $min_spare/" /etc/apache2/server-tuning.conf
+ [ $max_spare -eq 0 ] || ised -re "s/MaxSpareServers(.*)/MaxSpareServers $max_spare/" /etc/apache2/server-tuning.conf
+fi
+
+rm -f /tmp/httpd.pid
+/usr/sbin/apache2ctl start -D FOREGROUND