Skip to content

Commit

Permalink
modified setup_db.groovy and added bash aliases so you can use postgr…
Browse files Browse the repository at this point in the history
…es CLI tools without connection params or authorization, provide youre root. removed obsolete mysql devel tools
  • Loading branch information
Tom Werges committed Apr 20, 2012
1 parent 68cfca6 commit be2fb89
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 52 deletions.
26 changes: 26 additions & 0 deletions clc/modules/postgresql/conf/scripts/setup_db.groovy
Expand Up @@ -143,6 +143,10 @@ public class PostgresqlBootstrapper extends Bootstrapper.Simple implements Datab
throw new Exception("Unable to create the eucalyptus database tables");
}

if ( !createCliUser( ) ) {
throw new Exception("Unable to create the cli user");
}

Component dbComp = Components.lookup( Database.class );
dbComp.initService( );
prepareService( );
Expand Down Expand Up @@ -219,6 +223,7 @@ public class PostgresqlBootstrapper extends Bootstrapper.Simple implements Datab
File tmpPGHBA = new File(EUCA_DB_DIR + File.separator + "pg_hba.conf.org");
orgPGHBA.renameTo(tmpPGHBA);
File newPGHBA = new File(EUCA_DB_DIR + File.separator + "pg_hba.conf");
newPGHBA.append("local\tall\troot\tident\n");
newPGHBA.append("local\tall\tall\t\tpassword\n");
newPGHBA.append("host\tall\tall\t0.0.0.0/0\tpassword\n");
newPGHBA.append("host\tall\tall\t::1/128\tpassword\n");
Expand All @@ -245,6 +250,27 @@ public class PostgresqlBootstrapper extends Bootstrapper.Simple implements Datab
}
}

private boolean createCliUser() throws Exception {
if ( !isRunning( ) ) {
throw new Exception("The database must be running to create the cli user");
}
Connection conn = null;
try {
String url = String.format( "jdbc:%s", ServiceUris.remote( Database.class, Internets.localHostInetAddress( ), "postgres" ) );
conn = DriverManager.getConnection(url, Databases.getUserName(),Databases.getPassword());
Statement stmt = conn.createStatement();
String sqlCmd = "CREATE USER root WITH CREATEUSER";
stmt.execute(sqlCmd);
LOG.debug("executed successfully = CREATE USER root");
conn.close();
} catch (Exception e) {
LOG.error("Unable to create cli user", e);
return false;
}
return true;
}


private boolean createDBSql( ) throws Exception {

if ( !isRunning( ) ) {
Expand Down
23 changes: 23 additions & 0 deletions devel/aliases.sh
@@ -0,0 +1,23 @@

#
# This script allows you to run postgres CLI tools such as "psql"
# without providing authorization or connection parameters, provided
# you are root. After SOURCING this script, you should be able to run
# "psql -d database" as root. No further auth is required.
#
# NOTE: This file must be SOURCED, not executed: ". aliases.sh"
#
# author: tom.werges
#

if [ -z "$EUCALYPTUS" ]; then
echo "EUCALYPTUS must be set"
else
DATA_DIR=$EUCALYPTUS/var/lib/eucalyptus/db/data/
PORT=8777

alias psql="psql -h $DATA_DIR -p $PORT"
alias pg_dump="pg_dump -h $DATA_DIR -p $PORT"
alias pg_restore="pg_restore -h $DATA_DIR -p $PORT"
fi

13 changes: 0 additions & 13 deletions devel/db.sh

This file was deleted.

13 changes: 0 additions & 13 deletions devel/dbPass.sh

This file was deleted.

14 changes: 0 additions & 14 deletions devel/export_databases.sh

This file was deleted.

12 changes: 0 additions & 12 deletions devel/import_databases.sh

This file was deleted.

0 comments on commit be2fb89

Please sign in to comment.