zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 1 | # lib/apache |
| 2 | # Functions to control configuration and operation of apache web server |
| 3 | |
| 4 | # Dependencies: |
| 5 | # ``functions`` file |
| 6 | # is_apache_enabled_service |
zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 7 | # install_apache_wsgi |
| 8 | # config_apache_wsgi |
| 9 | # start_apache_server |
| 10 | # stop_apache_server |
| 11 | # restart_apache_server |
| 12 | |
| 13 | # Save trace setting |
| 14 | XTRACE=$(set +o | grep xtrace) |
| 15 | set +o xtrace |
| 16 | |
| 17 | # Allow overriding the default Apache user and group, default to |
| 18 | # current user and his default group. |
| 19 | APACHE_USER=${APACHE_USER:-$USER} |
| 20 | APACHE_GROUP=${APACHE_GROUP:-$(id -gn $APACHE_USER)} |
| 21 | |
| 22 | |
| 23 | # Set up apache name and configuration directory |
| 24 | if is_ubuntu; then |
| 25 | APACHE_NAME=apache2 |
| 26 | APACHE_CONF_DIR=sites-available |
| 27 | elif is_fedora; then |
| 28 | APACHE_NAME=httpd |
| 29 | APACHE_CONF_DIR=conf.d |
| 30 | elif is_suse; then |
| 31 | APACHE_NAME=apache2 |
| 32 | APACHE_CONF_DIR=vhosts.d |
| 33 | fi |
| 34 | |
| 35 | # Functions |
| 36 | # --------- |
| 37 | |
| 38 | # is_apache_enabled_service() checks if the service(s) specified as arguments are |
| 39 | # apache enabled by the user in ``APACHE_ENABLED_SERVICES`` as web front end. |
| 40 | # |
| 41 | # Multiple services specified as arguments are ``OR``'ed together; the test |
| 42 | # is a short-circuit boolean, i.e it returns on the first match. |
| 43 | # |
| 44 | # Uses global ``APACHE_ENABLED_SERVICES`` |
| 45 | # APACHE_ENABLED_SERVICES service [service ...] |
| 46 | function is_apache_enabled_service() { |
| 47 | services=$@ |
| 48 | for service in ${services}; do |
| 49 | [[ ,${APACHE_ENABLED_SERVICES}, =~ ,${service}, ]] && return 0 |
| 50 | done |
| 51 | return 1 |
| 52 | } |
| 53 | |
zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 54 | # install_apache_wsgi() - Install Apache server and wsgi module |
| 55 | function install_apache_wsgi() { |
| 56 | # Apache installation, because we mark it NOPRIME |
| 57 | if is_ubuntu; then |
| 58 | # Install apache2, which is NOPRIME'd |
| 59 | install_package apache2 libapache2-mod-wsgi |
| 60 | elif is_fedora; then |
| 61 | sudo rm -f /etc/httpd/conf.d/000-* |
| 62 | install_package httpd mod_wsgi |
| 63 | elif is_suse; then |
| 64 | install_package apache2 apache2-mod_wsgi |
| 65 | else |
| 66 | exit_distro_not_supported "apache installation" |
| 67 | fi |
| 68 | } |
| 69 | |
| 70 | # start_apache_server() - Start running apache server |
| 71 | function start_apache_server() { |
| 72 | start_service $APACHE_NAME |
| 73 | } |
| 74 | |
| 75 | # stop_apache_server() - Stop running apache server |
| 76 | function stop_apache_server() { |
| 77 | if [ -n "$APACHE_NAME" ]; then |
| 78 | stop_service $APACHE_NAME |
| 79 | else |
| 80 | exit_distro_not_supported "apache configuration" |
| 81 | fi |
| 82 | } |
| 83 | |
| 84 | # restart_apache_server |
| 85 | function restart_apache_server() { |
| 86 | restart_service $APACHE_NAME |
| 87 | } |
| 88 | |
| 89 | # Restore xtrace |
| 90 | $XTRACE |
| 91 | |
| 92 | # Local variables: |
| 93 | # mode: shell-script |
| 94 | # End: |