Exemplo n.º 1
0
Arquivo: appenv.py Projeto: wosc/batou
    def configure(self):
        with open("requirements.lock", "r") as f:
            lockfile = f.read()
        with open(__file__, "r") as f:
            hash_content = lockfile + self.python_version + f.read()
        hash_content = hash_content.encode("utf-8")
        self.env_hash = hashlib.new("sha256", hash_content).hexdigest()[:8]
        self.env_dir = os.path.join(".appenv", self.env_hash)
        self.env_ready = os.path.join(self.env_dir, "appenv.ready")

        self += VirtualEnv(self.python_version)
        self += File(os.path.join(self.env_dir, "requirements.lock"),
                     content=lockfile)
        self += LockedRequirements()

        # If we got here, then we can place the ready marker
        self += File(os.path.join(self.env_dir, "appenv.ready"),
                     content="Ready or not, here I come, you can't hide\n")

        # Save current to skip it in cleanup
        self.last_env_hash = None
        if os.path.exists(os.path.join(self.workdir, ".appenv/current")):
            self.last_env_hash = os.path.basename(
                os.readlink(os.path.join(self.workdir, ".appenv/current")))

        # Shim
        self += Symlink(".appenv/current", source=self.env_dir)
        for p in ["bin", "lib", "pyvenv.cfg"]:
            self += Symlink(p, source=".appenv/current/" + p)

        self += CleanupUnused()
Exemplo n.º 2
0
    def configure(self):
        self += Package('exim4-daemon-heavy')

        if self.exim_user:  # Handle case "package is not installed yet"
            self += File('/etc/exim4/schema.sql')
            schema = self._
            self += ServiceDatabase(
                self.db_name,
                username=self.db_username, password=self.db_password,
                schema=schema.path)
            self += Service('exim4', action='restart', deps=schema)

        self += DisableDebconf()

        self += File('/etc/exim4/domains', ensure='directory')

        self += Symlink(
            '/etc/exim4/system-filter',
            source='/home/wosc/.dot/mail/.filter-system')
        if os.path.exists('/var/mail/[email protected]'):
            self += Symlink('/var/mail/[email protected]/filter',
                            source='/home/wosc/.dot/mail/.filter')

        self += File('/etc/aliases', is_template=False)
        self += File('/etc/email-addresses', content='wosc: [email protected]')

        self += File('/etc/default/exim4', source='exim4.default',
                     is_template=False)
        self += Service('exim4', action='restart', deps=self._)
        self += File('/etc/exim4/exim4.conf')
        self += Service('exim4', action='reload', deps=self._)

        self += File('/var/mail', ensure='directory', group='Debian-exim')
Exemplo n.º 3
0
    def configure(self):
        lockfile = open('requirements.lock', 'r').read()

        hash_content = (
            lockfile +
            self.python_version +
            open(__file__, 'r').read())
        hash_content = hash_content.encode('utf-8')
        self.env_hash = hashlib.new('sha256', hash_content).hexdigest()
        self.env_dir = os.path.join('.appenv', self.env_hash)
        self.env_ready = os.path.join(self.env_dir, 'appenv.ready')

        self += VirtualEnv(self.python_version)
        self += File(
            os.path.join(self.env_dir, 'requirements.lock'),
            content=lockfile)
        self += LockedRequirements()

        # If we got here, then we can place the ready marker
        self += File(
            os.path.join(self.env_dir, 'appenv.ready'),
            content="Ready or not, here I come, you can\'t hide\n")

        # Shim
        self += Symlink(
            '.appenv/current',
            source=self.env_dir)
        for p in ['bin', 'lib', 'pyvenv.cfg']:
            self += Symlink(p, source='.appenv/current/' + p)

        self += CleanupUnused(self.env_dir)
Exemplo n.º 4
0
def test_symlink_updates_existing_link(root):
    link = "path"
    link_to = "link_to"
    # Create an initial link
    symlink = Symlink(link, source=link_to)
    root.component += symlink
    root.component.deploy()
    # Update link with other target
    link_to2 = "link_to2"
    symlink.source = link_to2
    root.component.deploy()
    assert os.readlink("work/mycomponent/" + link) == link_to2
Exemplo n.º 5
0
def test_symlink_updates_existing_link(root):
    link = 'path'
    link_to = 'link_to'
    # Create an initial link
    symlink = Symlink(link, source=link_to)
    root.component += symlink
    root.component.deploy()
    # Update link with other target
    link_to2 = 'link_to2'
    symlink.source = link_to2
    root.component.deploy()
    assert os.readlink('work/mycomponent/' + link) == link_to2
Exemplo n.º 6
0
def test_symlink_creates_new_link(root):
    link = "path"
    link_to = "link_to"
    symlink = Symlink(link, source=link_to)
    root.component += symlink
    root.component.deploy()
    assert os.readlink("work/mycomponent/" + link) == symlink.source
Exemplo n.º 7
0
def test_symlink_creates_new_link(root):
    link = 'path'
    link_to = 'link_to'
    symlink = Symlink(link, source=link_to)
    root.component += symlink
    root.component.deploy()
    assert os.readlink('work/mycomponent/' + link) == symlink.source
Exemplo n.º 8
0
    def configure(self):
        for name in self.packages:
            self += Package(name)

        for name in ['backup', 'restore']:
            self += File('/usr/local/bin/mysql-%s' % name,
                         is_template=False,
                         mode=0o755)
        self += Symlink('/etc/cron.daily/mysql-backup',
                        source='/usr/local/bin/mysql-backup')
Exemplo n.º 9
0
    def configure(self):
        self.require_one('nginx', host=self.host)
        if not isinstance(self.dependencies, (list, tuple)):
            self.dependencies = [self.dependencies]

        if self.site_enable:
            config = self.dependencies[0]
            self += Symlink('/etc/nginx/sites-enabled/%s' %
                            os.path.basename(config.path),
                            source=config.path)
            self.dependencies.append(self._)
Exemplo n.º 10
0
    def configure(self):
        self.provide('supervisor', self)

        self += Package('supervisor')
        self += Symlink('/usr/local/bin/sv', source='/usr/bin/supervisorctl')
        self += File(
            '/usr/lib/tmpfiles.d/supervisor.conf',
            content='# Generated by batou\nd /run/supervisor 0755 root root')
        self += Group('supervisor')

        self += File('/etc/supervisor/supervisord.conf',
                     is_template=False,
                     source=here + 'supervisord.conf')
Exemplo n.º 11
0
    def configure(self):
        for name in self.packages:
            self += Package(name)

        self += Download(self.url.format(version=self.version),
                         checksum=self.checksum)
        self += Extract(self._.target, strip=2, create_target_dir=False)
        self += Symlink('/usr/local/bin/soundjack',
                        source=self.map('SJC%s' % self.version))

        self += File('/lib/systemd/system/soundjack.service',
                     source='soundjack.conf',
                     is_template=False)
        self += SystemdConfig(self._)
Exemplo n.º 12
0
    def configure(self):
        # Allow reading accesslogs
        self += GroupMember('adm', user='******')
        self += Download(self.url.format(version=self.version),
                         checksum=self.checksum)
        self.download = self._
        self += Symlink('/srv/prometheus/bin/nginx_exporter',
                        source=self._.target)

        self.logfiles = glob('/var/log/nginx/*-access.log')
        self += File('/srv/prometheus/nginx.yml')
        self += Program('prometheus-nginx',
                        command='/srv/prometheus/bin/nginx_exporter '
                        '-config-file /srv/prometheus/nginx.yml',
                        user='******',
                        dependencies=[self._])
Exemplo n.º 13
0
    def configure(self):
        # Allow running `mailq`
        self += GroupMember('Debian-exim', user='******')
        self += File('/srv/prometheus/bin/node_exporter-mailq',
                     source='mailq.sh',
                     is_template=False,
                     mode=0o755)
        self += CronJob('/srv/prometheus/bin/node_exporter-mailq',
                        user='******',
                        timing='* * * * *')

        # Allow reading exim mainlog
        self += GroupMember('adm', user='******')
        self += File('/srv/prometheus/bin/node_exporter-eximstats',
                     source='eximstats.sh',
                     is_template=False,
                     mode=0o755)
        self += CronJob('/srv/prometheus/bin/node_exporter-eximstats',
                        user='******',
                        timing='*/5 * * * *')

        self += VirtualEnv()
        self._ += Requirements(source='mailcheck.txt')

        for name in ['mail', 'caldav']:
            self += Symlink('/srv/prometheus/bin/%s-check-roundtrip' % name,
                            source=self.map('bin/%s-check-roundtrip' % name))
            self += File('/srv/prometheus/%scheck.conf' % name,
                         owner='prometheus',
                         group='prometheus',
                         mode=0o640)

        self += File('/srv/prometheus/bin/node_exporter-mailcheck',
                     source='mailcheck.sh',
                     is_template=False,
                     mode=0o755)
        self += CronJob('/srv/prometheus/bin/node_exporter-mailcheck',
                        user='******',
                        timing='*/5 * * * *')

        self += File('/srv/prometheus/conf.d/alert-mailcheck.yml',
                     is_template=False)
        self.provide('prom:rule', self._)
Exemplo n.º 14
0
 def configure(self):
     self += VirtualEnv()
     self._ += batou.lib.python.Package(
         'youtube-dl', version=self.version, check_package_is_module=False)
     self += Symlink('/usr/local/bin/yt', source=self.map('bin/youtube-dl'))
Exemplo n.º 15
0
 def add_symlinks_to(self, other):
     other += Directory(other.sources_dir)
     for name in self.source_names:
         other += Symlink(os.path.join(other.sources_dir, name),
                          source=os.path.join(self.workdir, name))
Exemplo n.º 16
0
 def configure(self):
     self += Download(self.url, checksum=self.checksum)
     self += Extract(self._.target, strip=1, create_target_dir=False)
     for name in self.names:
         self += Symlink('/srv/prometheus/bin/%s' % name,
                         source=self.map(name))