summaryrefslogtreecommitdiffstats
path: root/Services/apache/sx-httpd.sh
blob: ad7b995995fe84a88295de9a4b39b5a13d5a91e8 (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
#!/bin/bash

function check_httpd_environment {
    if [ ! -v SERVER_NAME ]; then
        export SERVER_NAME=$CONTAINER_NAME
    fi
}

# Begin configuration before starting daemonized process
# and start generating host keys
function begin_config {
    echo "=> BEGIN APACHE CONFIGURATION"
    mkdir -p /var/run/httpd
    if [ -v DOCROOT ]; then
        echo "=> Changing document root to $DOCROOT"
        ${DOCROOT=/data/www}
        echo "DocumentRoot \"$DOCROOT\"" >> $HTTPDCONF
    fi
}

# End configuration process just before starting daemon
function end_config {
    stop_server
    echo "=> END APACHE CONFIGURATION"
}

# Start the httpd server in background. Used to perform config
# against the database structure such as user creation
function start_server {
    echo "=> Starting httpd server"
    /usr/sbin/apachectl &
    sleep 2
}

# Stop the httpd server running in background. 
function stop_server {
    echo "=> Stopping httpd server ..."
    killall httpd
    rm -rf /run/httpd/*
    sleep 2
}

# Start the httpd server as a deamon and execute it inside 
# the running shell
function start_daemon {
    echo "=> Starting httpd daemon ..."
    exec /usr/sbin/apachectl -D FOREGROUND
}