summaryrefslogtreecommitdiffstats
path: root/adei/scripts/run-apache.sh
blob: e7d894b833fe88551c9c17d1a318f98a73054820 (plain)
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
#! /bin/bash

LOCK_FILE=.lock
(
    flock -x 10
    if [ ! -d /adei/ovr/apache2 ]; then
        cp -ar /opt/apache2 /adei/ovr/ 
    fi
) 10> /adei/ovr/$LOCK_FILE

(
    flock -x 10
    if [ ! -f /adei/cfg/apache.conf ]; then
        cp -a /opt/configs/apache* /adei/cfg
    fi
) 10> /adei/cfg/$LOCK_FILE

#Keep 80 & 443
#sed -i'' -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 ] || sed -i'' -re "s/StartServers(.*)/StartServers $start/" /etc/apache2/server-tuning.conf
    [ $limit -eq 0 ] || sed -i'' -re "s/MaxClients(.*)/MaxClients $limit/" /etc/apache2/server-tuning.conf
    [ $min_spare -eq 0 ] || sed -i'' -re "s/MinSpareServers(.*)/MinSpareServers $min_spare/" /etc/apache2/server-tuning.conf
    [ $max_spare -eq 0 ] || sed -i'' -re "s/MaxSpareServers(.*)/MaxSpareServers $max_spare/" /etc/apache2/server-tuning.conf
fi

rm -f /tmp/httpd.pid
/usr/sbin/apache2ctl start -D FOREGROUND