| 1 | #!/bin/bash |
| 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"). |
| 5 | # You may not use this file except in compliance with the License. |
| 6 | # A copy of the License is located at |
| 7 | # |
| 8 | # http://aws.amazon.com/apache2.0 |
| 9 | # |
| 10 | # or in the "license" file accompanying this file. This file is distributed |
| 11 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 12 | # express or implied. See the License for the specific language governing |
| 13 | # permissions and limitations under the License. |
| 14 | # |
| 15 | |
| 16 | set -eu |
| 17 | |
| 18 | apache2_config() { |
| 19 | cert_dir="$1" |
| 20 | command="$2" |
| 21 | echo "apache2: ${command}" |
| 22 | |
| 23 | APACHE_SERVER_ROOT="$APACHE2_INSTALL_DIR" \ |
| 24 | APACHE_RUN_USER=www-data \ |
| 25 | APACHE_RUN_GROUP=www-data \ |
| 26 | APACHE_PID_FILE="${APACHE2_INSTALL_DIR}/run/apache2.pid" \ |
| 27 | APACHE_RUN_DIR="${APACHE2_INSTALL_DIR}/run" \ |
| 28 | APACHE_LOCK_DIR="${APACHE2_INSTALL_DIR}/lock" \ |
| 29 | APACHE_LOG_DIR="${APACHE2_INSTALL_DIR}/log" \ |
| 30 | APACHE_CERT_DIR="${cert_dir}" \ |
| 31 | apache2 -k "${command}" -f "${APACHE2_INSTALL_DIR}/apache2.conf" |
| 32 | } |
| 33 | |
| 34 | apache2_stop() { |
| 35 | cert_dir="$1" |
| 36 | apache2_config "${cert_dir}" stop |
| 37 | } |
| 38 | |
| 39 | apache2_start() { |
| 40 | if [[ ! -f "$APACHE2_INSTALL_DIR/apache2.conf" ]]; then |
| 41 | echo "apache2 not installed" |
| 42 | exit 1 |
| 43 | fi |
| 44 | |
| 45 | cert_dir="$1" |
| 46 | apache2_config "${cert_dir}" start |
| 47 | |
| 48 | # Stop the apache server after tests finish, even if an error occurs |
| 49 | trap 'apache2_stop "${cert_dir}"' ERR EXIT |
| 50 | } |