Пример #1
0
 def start_webserver(self):
     """
     Start the Nginx web server. The process for Nginx is expected to be
     running already so basically get a handle to the process. If it's not
     running, start it.
     """
     # Remove the default server config that comes with Nginx system package
     nginx_default_server = os.path.join(self.conf_dir, 'sites-enabled', 'default')
     misc.delete_file(nginx_default_server)
     self.reconfigure(setup_ssl=self.ssl_is_on)
     # Get a handle on the server process
     if not self._check_daemon('nginx'):
         if misc.run(self.exe):
             self.state == service_states.RUNNING
Пример #2
0
 def start_webserver(self):
     """
     Start the Nginx web server. The process for Nginx is expected to be
     running already so basically get a handle to the process. If it's not
     running, start it.
     """
     # Remove the default server config that comes with Nginx system package
     nginx_default_server = os.path.join(self.conf_dir, 'sites-enabled',
                                         'default')
     misc.delete_file(nginx_default_server)
     self.reconfigure(setup_ssl=self.ssl_is_on)
     # Get a handle on the server process
     if not self._check_daemon('nginx'):
         if misc.run(self.exe):
             self.state == service_states.RUNNING
Пример #3
0
    def reconfigure(self, setup_ssl):
        """
        (Re)Generate Nginx configuration files and reload the server process.

        :type   setup_ssl: boolean
        :param  setup_ssl: if set, force HTTPS with a self-signed certificate.
        """
        if self.exe:
            log.debug("Updating Nginx config at {0}".format(self.conf_file))
            params = {}
            # Customize the appropriate nginx template
            if "1.4" in misc.getoutput("{0} -v".format(self.exe)):
                nginx_tmplt = conf_manager.NGINX_14_CONF_TEMPLATE
                params = {'galaxy_user_name': paths.GALAXY_USER_NAME,
                          'nginx_conf_dir': self.conf_dir}
                if setup_ssl:
                    log.debug("Using Nginx v1.4+ template w/ SSL")
                    # Generate a self-signed certificate
                    log.info("Generating self-signed certificate for SSL encryption")
                    cert_home = "/root/.ssh/"
                    certfile = os.path.join(cert_home, "instance_selfsigned_cert.pem")
                    keyfile = os.path.join(cert_home, "instance_selfsigned_key.pem")
                    misc.run("yes '' | openssl req -x509 -nodes -days 3650 -newkey "
                             "rsa:1024 -keyout " + keyfile + " -out " + certfile)
                    misc.run("chmod 440 " + keyfile)
                    server_tmplt = conf_manager.NGINX_SERVER_SSL
                    self.ssl_is_on = True
                else:
                    log.debug("Using Nginx v1.4+ template")
                    server_tmplt = conf_manager.NGINX_SERVER
                    self.ssl_is_on = False
            else:
                server_tmplt = ""
                nginx_tmplt = conf_manager.NGINX_CONF_TEMPLATE
                self.ssl_is_on = False
                params = {
                    'galaxy_user_name': paths.GALAXY_USER_NAME,
                    'galaxy_home': paths.P_GALAXY_HOME,
                    'galaxy_data': self.app.path_resolver.galaxy_data,
                }
                log.debug("Using Nginx pre-v1.4 template")
            # Write out the main nginx.conf file
            self._write_template_file(nginx_tmplt, params, self.conf_file)
            # Write out the default server block file
            if server_tmplt:
                # This means we're dealing with Nginx v1.4+ & split conf files
                upstream_servers = self._define_upstream_servers()
                params = {
                    'upstream_servers': upstream_servers,
                    'nginx_conf_dir': self.conf_dir
                }
                conf_file = os.path.join(self.conf_dir, 'sites-enabled', 'default.server')
                self._write_template_file(server_tmplt, params, conf_file)
                # Pulsar has it's own server config
                pulsar_svc = self.app.manager.service_registry.get_active('Pulsar')
                if pulsar_svc:
                    pulsar_tmplt = conf_manager.NGINX_SERVER_PULSAR
                    params = {'pulsar_port': pulsar_svc.pulsar_port}
                    conf_file = os.path.join(self.conf_dir, 'sites-enabled', 'pulsar.server')
                    self._write_template_file(pulsar_tmplt, params, conf_file)
                # Write out the location blocks for hosted services
                # Always include default locations (CloudMan, VNC, error)
                default_tmplt = conf_manager.NGINX_DEFAULT
                conf_file = os.path.join(self.conf_dir, 'sites-enabled', 'default.locations')
                self._write_template_file(default_tmplt, {}, conf_file)
                # Now add running services
                # Galaxy Reports
                reports_svc = self.app.manager.service_registry.get_active('GalaxyReports')
                reports_conf_file = os.path.join(self.conf_dir, 'sites-enabled', 'reports.locations')
                if reports_svc:
                    reports_tmplt = conf_manager.NGINX_GALAXY_REPORTS
                    params = {'reports_port': reports_svc.reports_port}
                    self._write_template_file(reports_tmplt, params, reports_conf_file)
                else:
                    misc.delete_file(reports_conf_file)
                # Galaxy
                galaxy_svc = self.app.manager.service_registry.get_active('Galaxy')
                gxy_conf_file = os.path.join(self.conf_dir, 'sites-enabled', 'galaxy.locations')
                if galaxy_svc:
                    galaxy_tmplt = conf_manager.NGINX_GALAXY
                    params = {
                        'galaxy_home': paths.P_GALAXY_HOME,
                        'galaxy_data': self.app.path_resolver.galaxy_data
                    }
                    self._write_template_file(galaxy_tmplt, params, gxy_conf_file)
                else:
                    misc.delete_file(gxy_conf_file)
                # Cloudera Manager
                cmf_svc = self.app.manager.service_registry.get_active('ClouderaManager')
                cmf_conf_file = os.path.join(self.conf_dir, 'sites-enabled', 'cmf.locations')
                if cmf_svc:
                    cmf_tmplt = conf_manager.NGINX_CLOUDERA_MANAGER
                    self._write_template_file(cmf_tmplt, {}, cmf_conf_file)
                else:
                    misc.delete_file(cmf_conf_file)
                # Cloudgene
                cg_svc = self.app.manager.service_registry.get_active('Cloudgene')
                cg_conf_file = os.path.join(self.conf_dir, 'sites-enabled', 'cloudgene.locations')
                if cg_svc:
                    cg_tmplt = conf_manager.NGINX_CLOUDGENE
                    params = {'cg_port': cg_svc.port}
                    self._write_template_file(cg_tmplt, params, cg_conf_file)
                else:
                    misc.delete_file(cg_conf_file)
            self.reload()
        else:
            log.warning("Cannot find nginx executable to reload nginx config (got"
                        " '{0}')".format(self.exe))
Пример #4
0
    def reconfigure(self, setup_ssl):
        """
        (Re)Generate Nginx configuration files and reload the server process.

        :type   setup_ssl: boolean
        :param  setup_ssl: if set, force HTTPS with a self-signed certificate.
        """
        if self.exe:
            log.debug("Updating Nginx config at {0}".format(self.conf_file))
            params = {}
            # Customize the appropriate nginx template
            if "1.4" in misc.getoutput("{0} -v".format(self.exe)):
                nginx_tmplt = conf_manager.NGINX_14_CONF_TEMPLATE
                params = {
                    'galaxy_user_name': paths.GALAXY_USER_NAME,
                    'nginx_conf_dir': self.conf_dir
                }
                if setup_ssl:
                    log.debug("Using Nginx v1.4+ template w/ SSL")
                    # Generate a self-signed certificate
                    log.info(
                        "Generating self-signed certificate for SSL encryption"
                    )
                    cert_home = "/root/.ssh/"
                    certfile = os.path.join(cert_home,
                                            "instance_selfsigned_cert.pem")
                    keyfile = os.path.join(cert_home,
                                           "instance_selfsigned_key.pem")
                    misc.run(
                        "yes '' | openssl req -x509 -nodes -days 3650 -newkey "
                        "rsa:1024 -keyout " + keyfile + " -out " + certfile)
                    misc.run("chmod 440 " + keyfile)
                    server_tmplt = conf_manager.NGINX_SERVER_SSL
                    self.ssl_is_on = True
                else:
                    log.debug("Using Nginx v1.4+ template")
                    server_tmplt = conf_manager.NGINX_SERVER
                    self.ssl_is_on = False
            else:
                server_tmplt = ""
                nginx_tmplt = conf_manager.NGINX_CONF_TEMPLATE
                self.ssl_is_on = False
                params = {
                    'galaxy_user_name': paths.GALAXY_USER_NAME,
                    'galaxy_home': paths.P_GALAXY_HOME,
                    'galaxy_data': self.app.path_resolver.galaxy_data,
                }
                log.debug("Using Nginx pre-v1.4 template")
            # Write out the main nginx.conf file
            self._write_template_file(nginx_tmplt, params, self.conf_file)
            # Write out the default server block file
            if server_tmplt:
                # This means we're dealing with Nginx v1.4+ & split conf files
                upstream_servers = self._define_upstream_servers()
                params = {
                    'upstream_servers': upstream_servers,
                    'nginx_conf_dir': self.conf_dir
                }
                conf_file = os.path.join(self.conf_dir, 'sites-enabled',
                                         'default.server')
                self._write_template_file(server_tmplt, params, conf_file)
                # Pulsar has it's own server config
                pulsar_svc = self.app.manager.service_registry.get_active(
                    'Pulsar')
                if pulsar_svc:
                    pulsar_tmplt = conf_manager.NGINX_SERVER_PULSAR
                    params = {'pulsar_port': pulsar_svc.pulsar_port}
                    conf_file = os.path.join(self.conf_dir, 'sites-enabled',
                                             'pulsar.server')
                    self._write_template_file(pulsar_tmplt, params, conf_file)
                # Write out the location blocks for hosted services
                # Always include default locations (CloudMan, VNC, error)
                default_tmplt = conf_manager.NGINX_DEFAULT
                conf_file = os.path.join(self.conf_dir, 'sites-enabled',
                                         'default.locations')
                self._write_template_file(default_tmplt, {}, conf_file)
                # Now add running services
                # Galaxy Reports
                reports_svc = self.app.manager.service_registry.get_active(
                    'GalaxyReports')
                reports_conf_file = os.path.join(self.conf_dir,
                                                 'sites-enabled',
                                                 'reports.locations')
                if reports_svc:
                    reports_tmplt = conf_manager.NGINX_GALAXY_REPORTS
                    params = {'reports_port': reports_svc.reports_port}
                    self._write_template_file(reports_tmplt, params,
                                              reports_conf_file)
                else:
                    misc.delete_file(reports_conf_file)
                # Galaxy
                galaxy_svc = self.app.manager.service_registry.get_active(
                    'Galaxy')
                gxy_conf_file = os.path.join(self.conf_dir, 'sites-enabled',
                                             'galaxy.locations')
                if galaxy_svc:
                    galaxy_tmplt = conf_manager.NGINX_GALAXY
                    params = {
                        'galaxy_home': paths.P_GALAXY_HOME,
                        'galaxy_data': self.app.path_resolver.galaxy_data
                    }
                    self._write_template_file(galaxy_tmplt, params,
                                              gxy_conf_file)
                else:
                    misc.delete_file(gxy_conf_file)
                # Cloudera Manager
                cmf_svc = self.app.manager.service_registry.get_active(
                    'ClouderaManager')
                cmf_conf_file = os.path.join(self.conf_dir, 'sites-enabled',
                                             'cmf.locations')
                if cmf_svc:
                    cmf_tmplt = conf_manager.NGINX_CLOUDERA_MANAGER
                    self._write_template_file(cmf_tmplt, {}, cmf_conf_file)
                else:
                    misc.delete_file(cmf_conf_file)
                # Cloudgene
                cg_svc = self.app.manager.service_registry.get_active(
                    'Cloudgene')
                cg_conf_file = os.path.join(self.conf_dir, 'sites-enabled',
                                            'cloudgene.locations')
                if cg_svc:
                    cg_tmplt = conf_manager.NGINX_CLOUDGENE
                    params = {'cg_port': cg_svc.port}
                    self._write_template_file(cg_tmplt, params, cg_conf_file)
                else:
                    misc.delete_file(cg_conf_file)
            # Reload the configuration if the process is running
            if self._check_daemon('nginx'):
                self.reload()
            else:
                log.debug("nginx process not running; did not reload config.")
        else:
            log.warning(
                "Cannot find nginx executable to reload nginx config (got"
                " '{0}')".format(self.exe))