Source

sprintsite / components / nginx / component.py

Full commit
from batou.component import Component, platform
from batou.lib.file import File
from batou.utils import Address
import logging

logger = logging.getLogger(__name__)


class Nginx(Component):

    # Set via environment
    server_name = 'localhost'

    def configure(self):
        self.address = Address(self.server_name, 80)
        self.haproxy = self.require('haproxy')[0]
        self += File('sprintsite.conf', is_template=True)


@platform('gocept.net', Nginx)
class SystemwideNginx(Component):

    def configure(self):
        # copy all .conf files in workingdir to /etc/nginx/local
        # trigger sudo /etc/init.d/nginx reload
        for f in self.parent.sub_components:
            if not isinstance(f, File):
                continue
            if not f.path.endswith('.conf'):
                continue
            self += File(
                '/etc/nginx/local/%s' % os.path.basename(f.path),
                source=f.path)

    def verify(self):
        self.assert_no_subcomponent_changes()

    def update(self):
        stdout, stderr = self.cmd('sudo /etc/init.d/nginx reload')
        if 'failed, please correct errors above' in stderr:
            logger.error(stdout)
            logger.error(stderr)
            raise RuntimeError('nginx could not be reloaded')