Files
@ 0ff8631f4dbc
Branch filter:
Location: rattail-project/rattail/rattail/fablib/apache.py
0ff8631f4dbc
3.7 KiB
text/x-python
Add some python3 awareness when installing mod_wsgi
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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | # -*- coding: utf-8 -*-
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2017 Lance Edgar
#
# This file is part of Rattail.
#
# Rattail is free software: you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# Rattail is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# Rattail. If not, see <http://www.gnu.org/licenses/>.
#
################################################################################
"""
Fabric library for Apache web server
"""
from __future__ import unicode_literals, absolute_import
import re
from fabric.api import sudo, abort
from rattail.fablib import apt
def install():
"""
Install the Apache web service
"""
apt.install('apache2')
def get_version():
"""
Fetch the version of Apache running on the target system
"""
result = sudo('apache2 -v')
if result.succeeded:
match = re.match(r'^Server version: Apache/(\d+\.\d+)\.\d+ \(.*\)', result)
if match:
return float(match.group(1))
def install_wsgi(python_home=None, python3=False):
"""
Install the mod_wsgi Apache module, with optional ``WSGIPythonHome`` value.
"""
if python3:
apt.install('libapache2-mod-wsgi-py3')
else:
apt.install('libapache2-mod-wsgi')
if python_home:
if get_version() == 2.2:
sudo('echo WSGIPythonHome {} > /etc/apache2/conf.d/wsgi'.format(python_home))
else: # assuming 2.4
sudo('echo WSGIPythonHome {} > /etc/apache2/conf-available/wsgi.conf'.format(python_home))
enable_conf('wsgi')
def enable_conf(*names):
"""
Enable the given Apache configurations
"""
for name in names:
sudo('a2enconf {}'.format(name))
def enable_mod(*names):
"""
Enable the given Apache modules
"""
for name in names:
sudo('a2enmod {}'.format(name))
def enable_site(*names):
"""
Enable the given Apache site(s)
"""
for name in names:
sudo('a2ensite {}'.format(name))
def deploy_conf(deployer, local_path, name, enable=False):
"""
Deploy a config snippet file to Apache
"""
version = get_version()
if version == 2.2:
deployer(local_path, '/etc/apache2/conf.d/{}.conf'.format(name))
else:
deployer(local_path, '/etc/apache2/conf-available/{}.conf'.format(name))
if enable:
enable_conf(name)
def deploy_site(deployer, local_path, name, enable=False, **kwargs):
"""
Deploy a file to Apache sites-available
"""
apache_version = get_version()
if apache_version == 2.2:
path = '/etc/apache2/sites-available/{}'.format(name)
else:
path = '/etc/apache2/sites-available/{}.conf'.format(
'000-default' if name == 'default' else name)
context = kwargs.pop('context', {})
context['apache_version'] = apache_version
deployer(local_path, path, context=context, **kwargs)
if enable and name != 'default':
enable_site(name)
def restart():
"""
Restart the Apache web service
"""
sudo('service apache2 restart')
def start():
"""
Start the Apache web service
"""
sudo('service apache2 start')
def stop():
"""
Stop the Apache web service
"""
sudo('service apache2 stop')
|