Exemplo n.º 1
0
    def render_plugin_configs(self, plugin, context, **overides):
        if not env.task_context.get(env.host_string + 'pdir'):
            sudo('mkdir -p {0}'.format(self.plugin_configs))
            env.task_context[env.host_string + 'pdir'] = True

        plugin_context = self._plugin_context(plugin)
        plugin_context.update(overides)
        local_context = dict(context)
        local_context[plugin] = plugin_context

        plugin_path = None
        threshold_path = None
        try:
            template = plugin_context.get("template",
                            "collectd/{0}.conf".format(plugin))
            plugin_path = functions.render_template(template,
                                     context=local_context)
        except TemplateNotFound:
            pass

        try:
            template = plugin_context.get("threshold_template",
                                    "collectd/threshold-{0}.conf").format(plugin)
            threshold_path = functions.render_template(template,
                                     context=local_context)
        except TemplateNotFound:
            pass

        if plugin_path:
            sudo('ln -sf {0} {1}'.format(plugin_path, self.plugin_configs))

        if threshold_path:
            path = os.path.join(self.plugin_configs, 'thresholds.conf')
            sudo("echo '\n<Plugin \"threshold\">' > {0} && find {1}collectd/ -name threshold-* -exec cat {{}} \; >> {0} && echo '\n</Plugin>\n' >> {0}".format(path, env.configs_path))
Exemplo n.º 2
0
    def upload_templates(self):
        context = super(Gunicorn, self).upload_templates()
        functions.render_template(
            "gunicorn/{0}.conf".format(self.upstart_name),
            os.path.join(
                env.configs_path,
                "gunicorn/{0}.conf".format(self.upstart_name)),
            context=self.get_template_context())

        return context
Exemplo n.º 3
0
 def _setup_hba_config(self):
     """
     enable postgres access without password from localhost
     """
     hba_conf = os.path.join(self.config_dir, 'pg_hba.conf')
     if exists(hba_conf, use_sudo=True):
         context = self.get_template_context()
         functions.render_template("postgresql/pg_hba.conf", hba_conf,
                                   context=context, use_sudo=True)
         sudo('chown {0}:{1} {2}'.format(self.user, self.group, hba_conf))
     else:
         print ('Could not find file %s. Please make sure postgresql was '
                'installed and data dir was created correctly.'% hba_conf)
         sys.exit(1)
Exemplo n.º 4
0
    def _setup_config(self, template=None, directory=None):
        if not template:
            template = self.template

        name = template.split('/')[-1]
        if directory:
            remote_config_path = os.path.join(directory, name)
        else:
            remote_config_path = self.remote_config_path

        context = self.get_template_context()
        mime_path = functions.render_template(self.mime_template, context=context)
        context['nginx']['mime_types_file'] = mime_path
        nginx_config = functions.render_template(template, context=context)
        sudo('ln -sf %s %s' % (nginx_config, remote_config_path))
Exemplo n.º 5
0
    def install_rrd_receiver(self):
        context = self.get_template_context()
        self._install_plugin('rrdtool', context)

        context['network'] = self._plugin_context('network')
        auth_file = functions.render_template("collectd/auth.conf", context=context)
        self._install_plugin('network', context, auth_file=auth_file)
Exemplo n.º 6
0
    def _build_settings(self, code_dir):
        """ Construct a new settings file.

        Notes
        -----
        To ensure an idempotent outcome, the rendered settings template
        is appended to a "pristine" copy of the settings/__init__.py file
        (grabbed here from /srv/updating/project/settings/__init__.py).
        The existing __init__.py file is then clobbered.

        Parameters
        ----------
        code_dir : str
            Path to the code directory.

        """
        template_name = 'django/base_settings'
        role = env.host_roles.get(env.host_string)
        if os.path.exists(os.path.join(env.deploy_path, 'templates',
                        'django', role)):
            template_name = "django/{0}".format(role)

        pristine_location = os.path.join(env.base_remote_path, 'updating',
                'project', 'settings', '__init__.py')

        template_location = functions.render_template(template_name, context=self._get_context(role))
        run('cat {0} {1} > {2}'.format(pristine_location, template_location,
                        os.path.join(code_dir, 'project',
                                    'settings', '__init__.py')
                        )
        )
Exemplo n.º 7
0
 def run(self):
     self._add_package()
     context = self.get_template_context()
     template = context[self.context_name].get('template', self.template)
     dest_path = functions.render_template(template, self.template,
                                           context=context)
     sudo("ln -sf {0} {1}".format(dest_path, self.remote_config_path))
     self._restart_service()
Exemplo n.º 8
0
    def _setup_config(self, template=None,):
        if not template:
            template = self.template

        context = self.get_template_context()
        self._setup_logging()
        config = functions.render_template(template, context=context)
        sudo('ln -sf %s %s' % (config, self.remote_config_path))
Exemplo n.º 9
0
    def setup(self, *args, **kwargs):
        self._add_package(self.package_name)
        context = self.get_template_context()

        template = context[self.context_name].get('template', self.template)
        for plugin in self.base_plugins:
            self._install_plugin(plugin, context)

        context['connection'] = re.sub(r'[^a-zA-Z0-9-]', '-', env.host_string)
        context['role'] = env.host_roles.get(env.host_string)
        dest_path = functions.render_template(template, self.template,
                                              context=context)
        sudo("ln -sf {0} {1}".format(dest_path, self.remote_config_path))
Exemplo n.º 10
0
    def _setup_recovery_conf(self, master_ip):
        context = self.get_template_context()

        psql_bin = ''
        if self.binary_path:
            psql_bin = self.binary_path

        wal_dir = os.path.join(self.data_dir, 'wal_archive')
        recovery_conf = os.path.join(self.data_dir, 'recovery.conf')

        if psql_bin:
            pg_archive = '{0}pg_archivecleanup'.format(psql_bin)
        else:
            pg_archive = run('which pg_archivecleanup')

        context[self.context_name]['wal_dir'] = wal_dir
        context[self.context_name]['pg_archive'] = pg_archive
        context['master_ip'] = master_ip
        context['replication_pw'] = self._get_replicator_pass()

        functions.render_template("postgresql/recovery.conf", recovery_conf,
                                  context=context, use_sudo=True)
        sudo('chown {0}:{1} {2}'.format(self.user, self.group, recovery_conf))
Exemplo n.º 11
0
 def upload_templates(self):
     context = super(Gunicorn, self).upload_templates()
     functions.render_template("gunicorn/gunicorn.xml",
                     self.get_service_path(),
                     context=context)
     return context
Exemplo n.º 12
0
 def upload_templates(self):
     context = super(Gunicorn, self).upload_templates()
     functions.render_template("gunicorn/supervisor_gunicorn.conf",
                     os.path.join(env.configs_path, "gunicorn/supervisor_{0}.conf".format(self.gunicorn_name)),
                     context=context)
     return context
Exemplo n.º 13
0
 def upload_templates(self):
     context = super(Gunicorn, self).upload_templates()
     functions.render_template("gunicorn/gunicorn.xml",
                               self.get_service_path(),
                               context=context)
     return context
Exemplo n.º 14
0
 def upload_templates(self):
     context = self.get_template_context()
     script = functions.render_template(self.template, context=context)
     run('chmod +x {}'.format(script))
     return script
Exemplo n.º 15
0
 def run(self):
     context = self.get_template_context()
     file_loc = functions.render_template(self.template, context=context)
     sudo('ln -sf {0} {1}'.format(file_loc, self.conf_location))
     functions.execute_on_host('utils.start_or_restart_service', name='iptables')
Exemplo n.º 16
0
 def upload_templates(self):
     context = self.get_template_context()
     script = functions.render_template(self.template, context=context)
     run('chmod +x {}'.format(script))
     return script
Exemplo n.º 17
0
 def upload_templates(self):
     context = super(Celeryd, self).upload_templates()
     conf = functions.render_template("celery/{0}.conf".format(self.upstart_name),
                                      context[self.context_name]['config_file'],
                                      context=context)
     return context
Exemplo n.º 18
0
 def upload_templates(self):
     context = self.get_template_context()
     functions.render_template("gunicorn/gunicorn.pt", context[self.context_name]['config_location'], context=context)
     script = functions.render_template("gunicorn/start_gunicorn.sh", context[self.context_name]['start_script'], context=context)
     sudo('chmod +x {}'.format(script))
     return context
Exemplo n.º 19
0
 def upload_templates(self):
     context = self.get_template_context()
     script = functions.render_template("celery/start_celeryd.sh", context[self.context_name]['start_script'], context=context)
     sudo('chmod +x {}'.format(script))
     return context
Exemplo n.º 20
0
 def upload_templates(self):
     context = super(Celeryd, self).upload_templates()
     functions.render_template("celery/celeryd.xml",
                     self.get_service_path(),
                     context=context)
     return context
Exemplo n.º 21
0
 def upload_templates(self):
     context = super(Celeryd, self).upload_templates()
     functions.render_template("celery/supervisor_celeryd.conf",
                     os.path.join(env.configs_path, "celery/supervisor_{0}.conf".format(self.name)),
                     context=context)
     return context
Exemplo n.º 22
0
 def run(self):
     context = self.get_template_context()
     file_loc = functions.render_template(self.template, context=context)
     sudo('ln -sf {0} {1}'.format(file_loc, self.conf_location))
     functions.execute_on_host('utils.start_or_restart_service',
                               name='iptables')