Exemplo n.º 1
0
 def _fix_util_arch(self):
     """
     Edit ``$SGE_ROOT/util/`` to prevent ``Unexpected operator`` error to
     show up at shell login (SGE bug on Ubuntu).
     """
     misc.replace_string(
         self.app.path_resolver.sge_root +
         '/util/arch', "         libc_version=`echo $libc_string | tr ' ,' '\\n' | grep \"2\.\" | cut -f 2 -d \".\"`",
         "         libc_version=`echo $libc_string | tr ' ,' '\\n' | grep \"2\.\" | cut -f 2 -d \".\" | sort -u`")
     # Support 3.0, 3.2, 3.5 kernels in Ubuntu 11.10 & 12.04 & 12.10
     # Future proof it a bit to work with new 3.x kernels as they
     # come online
     misc.replace_string(
         self.app.path_resolver.sge_root + '/util/arch', "   2.[46].*)",
         "   [23].[24567890].*)")
     misc.replace_string(
         self.app.path_resolver.sge_root + '/util/arch', "      2.6.*)",
         "      [23].[24567890].*)")
     misc.run("sed -i.bak 's/sort -u/sort -u | head -1/g' %s/util/arch" % self.app.path_resolver.sge_root, "Error modifying %s/util/arch" %
              self.app.path_resolver.sge_root, "Modified %s/util/arch" % self.app.path_resolver.sge_root)
     misc.run("chmod +rx %s/util/arch" % self.app.path_resolver.sge_root, "Error chmod %s/util/arch" %
              self.app.path_resolver.sge_root, "Successfully chmod %s/util/arch" % self.app.path_resolver.sge_root)
     # Ensure lines starting with 127.0.1. are not included in /etc/hosts
     # because SGE fails to install if that's the case. This line is added
     # to /etc/hosts by cloud-init
     # (http://www.cs.nott.ac.uk/~aas/Software%2520Installation%2520and%2520Development%2520Problems.html)
     misc.run(
         "sed -i.bak '/^127.0.1./s/^/# (Commented by CloudMan) /' /etc/hosts")
Exemplo n.º 2
0
 def _fix_util_arch(self):
     """
     Edit ``$SGE_ROOT/util/`` to prevent ``Unexpected operator`` error to
     show up at shell login (SGE bug on Ubuntu).
     """
     misc.replace_string(
         self.app.path_resolver.sge_root + '/util/arch',
         "         libc_version=`echo $libc_string | tr ' ,' '\\n' | grep \"2\.\" | cut -f 2 -d \".\"`",
         "         libc_version=`echo $libc_string | tr ' ,' '\\n' | grep \"2\.\" | cut -f 2 -d \".\" | sort -u`"
     )
     # Support 3.0, 3.2, 3.5 kernels in Ubuntu 11.10 & 12.04 & 12.10
     # Future proof it a bit to work with new 3.x kernels as they
     # come online
     misc.replace_string(self.app.path_resolver.sge_root + '/util/arch',
                         "   2.[46].*)", "   [23].[24567890].*)")
     misc.replace_string(self.app.path_resolver.sge_root + '/util/arch',
                         "      2.6.*)", "      [23].[24567890].*)")
     misc.run(
         "sed -i.bak 's/sort -u/sort -u | head -1/g' %s/util/arch" %
         self.app.path_resolver.sge_root,
         "Error modifying %s/util/arch" % self.app.path_resolver.sge_root,
         "Modified %s/util/arch" % self.app.path_resolver.sge_root)
     misc.run(
         "chmod +rx %s/util/arch" % self.app.path_resolver.sge_root,
         "Error chmod %s/util/arch" % self.app.path_resolver.sge_root,
         "Successfully chmod %s/util/arch" %
         self.app.path_resolver.sge_root)
     # Ensure lines starting with 127.0.1. are not included in /etc/hosts
     # because SGE fails to install if that's the case. This line is added
     # to /etc/hosts by cloud-init
     # (http://www.cs.nott.ac.uk/~aas/Software%2520Installation%2520and%2520Development%2520Problems.html)
     misc.run(
         "sed -i.bak '/^127.0.1./s/^/# (Commented by CloudMan) /' /etc/hosts"
     )
Exemplo n.º 3
0
 def configure_proftpd(self):
     """
     Configure environment for running ProFTPd service.
     """
     # In the config, set the port on which postgres is running
     log.debug("Configuring ProFTPd")
     # This is a bit dodgy but ports are hardcoded in CBL so shoudl be a pretty
     # safe bet for the time being
     misc.replace_string('/usr/proftpd/etc/proftpd.conf',
                         'galaxy@localhost:5840',
                         'galaxy@localhost:{0}'.format(paths.C_PSQL_PORT))
     misc.replace_string('/usr/proftpd/etc/proftpd.conf',
                         '/mnt/galaxyData',
                         self.app.path_resolver.galaxy_data)
     # Verify that the expected config path exists.  This is expected to be
     # /mnt/galaxy/tools/proftpd
     # TODO just use /usr/proftpd.  Should be a simple update to the init.d
     expected_config_path = os.path.join(self.app.path_resolver.galaxy_data, 'tools', 'proftpd')
     if not os.path.exists(expected_config_path):
         misc.run('ln -s /usr/profpd %s' % expected_config_path)
     # Setup the data dir for FTP
     ftp_data_dir = '%s/tmp/ftp' % self.app.path_resolver.galaxy_data
     if not os.path.exists(ftp_data_dir):
         os.makedirs(ftp_data_dir)
     attempt_chown_galaxy(ftp_data_dir)
     # Some images have vsFTPd server included so stop it first
     vsFTPd_exists = misc.run('status vsftpd', quiet=True)
     if vsFTPd_exists and 'start/running' in vsFTPd_exists:
         log.debug("Stopping vsFTPd")
         misc.run('stop vsftpd')
     # Start the server now
     if misc.run('/etc/init.d/proftpd start'):
         self.state = service_states.RUNNING
         return True
     else:
         log.debug("Trouble starting ProFTPd")
         return False
Exemplo n.º 4
0
 def _fix_util_arch(self):
     # Prevent 'Unexpected operator' to show up at shell login (SGE bug on Ubuntu)
     misc.replace_string(paths.P_SGE_ROOT + '/util/arch', "         libc_version=`echo $libc_string | tr ' ,' '\\n' | grep \"2\.\" | cut -f 2 -d \".\"`", "         libc_version=`echo $libc_string | tr ' ,' '\\n' | grep \"2\.\" | cut -f 2 -d \".\" | sort -u`")
     # Support 3.0 & 3.2 kernels in Ubuntu 11.10 & 12.04
     misc.replace_string(paths.P_SGE_ROOT + '/util/arch', "   2.[46].*)",
                                                          "   [23].[2460].*)")
     misc.replace_string(paths.P_SGE_ROOT + '/util/arch', "      2.6.*)",
                                                          "      [23].[260].*)")
     misc.run("sed -i.bak 's/sort -u/sort -u | head -1/g' %s/util/arch" % paths.P_SGE_ROOT, "Error modifying %s/util/arch" % paths.P_SGE_ROOT, "Modified %s/util/arch" % paths.P_SGE_ROOT)
     misc.run("chmod +rx %s/util/arch" % paths.P_SGE_ROOT, "Error chmod %s/util/arch" % paths.P_SGE_ROOT, "Successfully chmod %s/util/arch" % paths.P_SGE_ROOT)
     # Ensure lines starting with 127.0.1. are not included in /etc/hosts 
     # because SGE fails to install if that's the case. This line is added
     # to /etc/hosts by cloud-init
     # (http://www.cs.nott.ac.uk/~aas/Software%2520Installation%2520and%2520Development%2520Problems.html)
     misc.run("sed -i.bak '/^127.0.1./s/^/# (Commented by CloudMan) /' /etc/hosts")
Exemplo n.º 5
0
    def manage_postgres( self, to_be_started=True ):
        if self.app.TESTFLAG is True:
            log.debug( "Attempted to manage Postgres, but TESTFLAG is set." )
            return
        psql_data_dir = paths.P_PSQL_DIR
        # Make sure postgres is owner of its directory before any operations
        if os.path.exists(os.path.split(paths.P_PSQL_DIR)[0]):
            misc.run("%s --recursive postgres:postgres %s" % (paths.P_CHOWN, os.path.split(paths.P_PSQL_DIR)[0]), "Error changing ownership of just created directory", "Successfully set ownership of Postgres data directory")
        # Check on the status of PostgreSQL server
        self.status()
        if to_be_started and not self.state==service_states.RUNNING:
            to_be_configured = False

            # Check if 'psql_data_dir' exists first; it not, configure PostgreSQL
            if not os.path.exists( psql_data_dir ):
                log.debug("{0} dir does not exist; will be configuring Postgres".format(psql_data_dir))
                to_be_configured = True

            if to_be_configured:
                log.info( "Configuring PostgreSQL with a database for Galaxy..." )
                cont = True # Flag to indicate if previous operation completed successfully 
                # Make Galaxy database directory
                if os.path.exists(paths.P_GALAXY_DATA) and not os.path.exists(psql_data_dir):
                    cont = misc.run('mkdir -p %s' % psql_data_dir, "Error creating Galaxy database cluster dir", "Successfully created Galaxy database cluster dir")
                else:
                    log.error( "'%s' directory doesn't exist yet; will configure PostgreSQL later." % paths.P_GALAXY_DATA )
                    return False
                # Change ownership of just created directory
                if cont:
                    cont = misc.run( '%s -R postgres:postgres %s/pgsql' % ( paths.P_CHOWN, paths.P_GALAXY_DATA ), "Error changing ownership of just created directory", "Successfully changed ownership of just created directory" )
                # Initialize/configure database cluster
                if cont:
                    log.debug( "Initializing PostgreSQL database for Galaxy..." )
                    cont = misc.run( '%s - postgres -c "%s/initdb -D %s"' % (paths.P_SU, paths.P_PG_HOME, psql_data_dir), "Error initializing Galaxy database", "Successfully initialized Galaxy database")
                    if cont:
                        misc.replace_string('%s/postgresql.conf' % psql_data_dir, '#port = 5432', 'port = %s' % self.psql_port)
                        os.chown('%s/postgresql.conf' % psql_data_dir, pwd.getpwnam( "postgres" )[2], grp.getgrnam( "postgres" )[2] )
                # Start PostgreSQL server so a role for Galaxy user can be created
                if cont:
                    log.debug( "Starting PostgreSQL as part of the initial setup..." )
                    cont = misc.run( '%s - postgres -c "%s/pg_ctl -w -D %s -l /tmp/pgSQL.log -o \\\"-p %s\\\" start"' % (paths.P_SU, paths.P_PG_HOME, psql_data_dir, self.psql_port), "Error starting postgres server as part of the initial configuration", "Successfully started postgres server as part of the initial configuration." )
                # Create role for galaxy user
                if cont:
                    log.debug( "PostgreSQL started OK (log available at /tmp/pgSQL.log).")
                    log.debug( "Creating role for 'galaxy' user in PostgreSQL..." )
                    cont = misc.run('%s - postgres -c "%s/psql -p %s -c \\\"CREATE ROLE galaxy LOGIN CREATEDB\\\" "' % (paths.P_SU, paths.P_PG_HOME, self.psql_port), "Error creating role for 'galaxy' user", "Successfully created role for 'galaxy' user" )
                # Create database for Galaxy, as galaxy user
                if cont:
                    log.debug( "Creating PostgreSQL database as 'galaxy' user..." )
                    cont = misc.run('%s - galaxy -c "%s/createdb -p %s galaxy"' % (paths.P_SU, paths.P_PG_HOME, self.psql_port), "Error creating 'galaxy' database", "Successfully created 'galaxy' database")
                # Now create role and permissons for galaxyftp user on the created 'galaxy' database
                if cont: 
                    log.debug( "Creating role for 'galaxyftp' user in PostgreSQL..." )
                    cont = misc.run('%s - postgres -c "%s/psql -p %s -c \\\"CREATE ROLE galaxyftp LOGIN PASSWORD \'fu5yOj2sn\'\\\" "' % (paths.P_SU, paths.P_PG_HOME, self.psql_port), "Error creating role for 'galaxyftp' user", "Successfully created role for 'galaxyftp' user" )
                else:
                    log.error("Setting up Postgres did not go smoothly.")
                    self.state = service_states.ERROR
                    return False

            # Check on the status of PostgreSQL server
            self.status()
            if to_be_started and not self.state==service_states.RUNNING:
                # Start PostgreSQL database
                log.info( "Starting PostgreSQL..." )
                misc.run( '%s -R postgres:postgres %s' % (paths.P_CHOWN, paths.P_GALAXY_DATA+'/pgsql'), "Error changing owner of postgres data dir", "Successfully changed owner of postgres data dir" )
                if misc.run( '%s - postgres -c "%s/pg_ctl -w -D %s -l /tmp/pgSQL.log -o\\\"-p %s\\\" start"' % (paths.P_SU, paths.P_PG_HOME, psql_data_dir, self.psql_port), "Error starting PostgreSQL server", "Successfully started PostgreSQL server"):
                    self.status()
                    if self.state==service_states.RUNNING:
                        log.info( "Successfully started PostgreSQL." )
                    else:
                        log.warning("Successfully started PosgreSQL but did it start and is it accessible?")
            else:
                log.debug("PostgreSQL already running (%s, %s)" % (to_be_started, self.state))
        elif not to_be_started:
            # Stop PostgreSQL database
            log.info( "Stopping PostgreSQL..." )
            self.state = service_states.SHUTTING_DOWN
            if misc.run('%s - postgres -c "%s/pg_ctl -w -D %s -o\\\"-p %s\\\" stop"' % (paths.P_SU, paths.P_PG_HOME, psql_data_dir, self.psql_port), "Encountered problem while stopping PostgreSQL", "Successfully stopped PostgreSQL"):
                self.state = service_states.SHUT_DOWN
            else:
                self.state = service_states.ERROR
                return False
                
        return True
Exemplo n.º 6
0
    def manage_postgres(self, to_be_started=True):
        psql_data_dir = self.app.path_resolver.psql_dir
        # Make sure postgres is owner of its directory before any operations
        if os.path.exists(self.app.path_resolver.psql_dir):
            misc.run(
                "%s --recursive postgres:postgres %s" % (
                    paths.P_CHOWN, psql_data_dir),
                "Error setting ownership of Postgres data directory %s" % psql_data_dir,
                "Successfully set ownership of Postgres data directory %s" % psql_data_dir)
        # Check on the status of PostgreSQL server
        self.status()
        if to_be_started and self.state is not service_states.RUNNING:
            to_be_configured = False

            # Check if 'psql_data_dir' exists first; it not, configure
            # PostgreSQL
            if not os.path.exists(psql_data_dir):
                log.debug("{0} dir does not exist; will be configuring Postgres".format(
                    psql_data_dir))
                to_be_configured = True

            if to_be_configured:
                log.debug(
                    "Configuring PostgreSQL with a database for Galaxy...")
                cont = True  # Flag to indicate if previous operation completed successfully
                # Make Galaxy database directory
                if os.path.exists(self.app.path_resolver.galaxy_data) and not os.path.exists(psql_data_dir):
                    cont = misc.run('mkdir -p %s' % psql_data_dir,
                                    "Error creating Galaxy database cluster dir",
                                    "Successfully created Galaxy database cluster dir")
                else:
                    log.error("'%s' directory doesn't exist yet; will configure PostgreSQL later." %
                              self.app.path_resolver.galaxy_data)
                    return False
                # Change ownership of just created directory
                if cont:
                    cont = misc.run(
                        '%s -R postgres:postgres %s' % (
                            paths.P_CHOWN, psql_data_dir),
                        "Error changing ownership of just created directory",
                        "Successfully changed ownership of just created directory")
                # Initialize/configure database cluster
                if cont:
                    log.debug(
                        "Initializing PostgreSQL database for Galaxy...")
                    cont = misc.run('%s - postgres -c "%s/initdb -D %s"' % (
                        paths.P_SU, self.app.path_resolver.pg_home, psql_data_dir),
                        "Error initializing Galaxy database.",
                        "Successfully initialized Galaxy database.")
                    if cont:
                        misc.replace_string(
                            '%s/postgresql.conf' % psql_data_dir,
                            '#port = 5432', 'port = %s' % self.psql_port)
                        os.chown('%s/postgresql.conf' % psql_data_dir, pwd.getpwnam(
                            "postgres")[2], grp.getgrnam("postgres")[2])
                # Start PostgreSQL server so a role for Galaxy user can be
                # created
                if cont:
                    log.debug(
                        "Starting PostgreSQL on port {0} as part of the initial setup..."
                        .format(self.psql_port))
                    cmd = ('%s - postgres -c "%s/pg_ctl -w -D %s -l /tmp/pgSQL.log -o \\\"-p %s\\\" start"'
                           % (paths.P_SU, self.app.path_resolver.pg_home, psql_data_dir, self.psql_port))
                    cont = misc.run(
                        cmd,
                        "Error starting postgres server as part of the initial configuration",
                        "Successfully started Postgres on port {0} as part of the initial configuration."
                        .format(self.psql_port))
                # Create role for galaxy user
                if cont:
                    log.debug(
                        "PostgreSQL started OK (log available at /tmp/pgSQL.log).")
                    log.debug(
                        "Creating role for 'galaxy' user in PostgreSQL...")
                    cont = misc.run(
                        '%s - postgres -c "%s/psql -p %s -c \\\"CREATE ROLE galaxy LOGIN CREATEDB\\\" "' % (
                            paths.P_SU, self.app.path_resolver.pg_home, self.psql_port),
                        "Error creating role for 'galaxy' user",
                        "Successfully created role for 'galaxy' user")
                # Create database for Galaxy, as galaxy user
                if cont:
                    log.debug(
                        "Creating PostgreSQL database as 'galaxy' user...")
                    cont = misc.run('%s - galaxy -c "%s/createdb -p %s galaxy"' % (
                        paths.P_SU, self.app.path_resolver.pg_home, self.psql_port),
                        "Error creating 'galaxy' database", "Successfully created 'galaxy' database")
                # Now create role and permissons for galaxyftp user on the
                # created 'galaxy' database
                if cont:
                    log.debug(
                        "Creating role for 'galaxyftp' user in PostgreSQL...")
                    cont = misc.run(
                        '%s - postgres -c "%s/psql -p %s -c \\\"CREATE ROLE galaxyftp LOGIN PASSWORD \'fu5yOj2sn\'\\\" "' % (
                            paths.P_SU, self.app.path_resolver.pg_home, self.psql_port),
                        "Error creating role for 'galaxyftp' user",
                        "Successfully created role for 'galaxyftp' user")
                else:
                    log.error("Setting up Postgres did not go smoothly.")
                    self.state = service_states.ERROR
                    return False

            # Check on the status of PostgreSQL server
            self.status()
            if to_be_started and self.state is not service_states.RUNNING:
                # Start PostgreSQL database
                log.debug("Starting PostgreSQL...")
                if misc.run('%s - postgres -c "%s/pg_ctl -w -D %s -l /tmp/pgSQL.log -o\\\"-p %s\\\" start"' %
                            (paths.P_SU, self.app.path_resolver.pg_home, psql_data_dir, self.psql_port)):
                    self.status()
            else:
                log.debug("PostgreSQL already running (%s, %s)" % (
                    to_be_started, self.state))
        elif not to_be_started:
            # Stop PostgreSQL database
            log.info("Stopping PostgreSQL from {0} on port {1}...".format(
                psql_data_dir, self.psql_port))
            self.state = service_states.SHUTTING_DOWN
            if misc.run('%s - postgres -c "%s/pg_ctl -w -D %s -o\\\"-p %s\\\" stop"'
               % (paths.P_SU, self.app.path_resolver.pg_home, psql_data_dir, self.psql_port)):
                self.state = service_states.SHUT_DOWN
            else:
                self.state = service_states.ERROR
                return False
        return True