protected String callPgctl(String command, boolean waitForIt) { return sudoAsUser("postgres", getInstallDir() + "/bin/pg_ctl -D " + getDataDir() + " -l " + getLogFile() + (waitForIt ? " -w " : " ") + command); }
@Override public String call(ConfigBag parameters) { return DynamicTasks.queue(SshEffectorTasks.ssh( BashCommands.pipeTextTo( parameters.get(SCRIPT), BashCommands.sudoAsUser("postgres", "psql --file -"))) .requiringExitCodeZero()).getStdout(); } }
BashCommands.sudoAsUser(processOwner, "test -f "+pidFile) + " || exit 1", "ps -p $(" + BashCommands.sudoAsUser(processOwner, "cat "+pidFile) + ")" ); } else { "rm -f " + pidFile); if (processOwner != null) { s.body.append(BashCommands.sudoAsUser(processOwner, stopCommand)); } else { s.body.append(stopCommand); if (processOwner != null) { s.body.append( "export PID=$(" + BashCommands.sudoAsUser(processOwner, "cat "+pidFile) + ")", "test -n \"$PID\" || exit 0", BashCommands.sudoAsUser(processOwner, "kill -9 $PID"), BashCommands.sudoAsUser(processOwner, "rm -f "+pidFile) ); } else { if (processOwner != null) { s.footer.prepend( BashCommands.sudoAsUser(processOwner, "test -f "+pidFile) + " || exit 1", "ps -p $(" + BashCommands.sudoAsUser(processOwner, "cat "+pidFile) + ") || exit 1" ); } else {
public ProcessTaskWrapper<Integer> executeScriptFromInstalledFileAsync(String filenameAlreadyInstalledAtServer) { return DynamicTasks.queue( SshEffectorTasks.ssh( "cd "+getRunDir(), sudoAsUser("postgres", getInstallDir() + "/bin/psql -p " + entity.getAttribute(PostgreSqlNode.POSTGRESQL_PORT) + " -v ON_ERROR_STOP=1 --file " + filenameAlreadyInstalledAtServer)) .requiringExitCodeZero() .summary("executing datastore script "+filenameAlreadyInstalledAtServer)); }
private void initializeNewDatabase() { String createUserCommand = String.format( "\"CREATE USER %s WITH PASSWORD '%s'; \"", StringEscapes.escapeSql(getUsername()), StringEscapes.escapeSql(getUserPassword()) ); String createDatabaseCommand = String.format( "\"CREATE DATABASE %s OWNER %s\"", StringEscapes.escapeSql(getDatabaseName()), StringEscapes.escapeSql(getUsername())); String createRolesAdditionalCommand = ""; if (entity.getConfig(PostgreSqlNode.ROLES) != null && !entity.getConfig(PostgreSqlNode.ROLES).isEmpty()) { String createRolesQuery = buildCreateRolesQuery(); createRolesAdditionalCommand = sudoAsUser("postgres", getInstallDir() + "/bin/psql -p " + entity.getAttribute(PostgreSqlNode.POSTGRESQL_PORT) + " --command="+ createRolesQuery); } newScript("initializing user and database") .body.append( "cd " + getInstallDir(), callPgctl("start", true), sudoAsUser("postgres", getInstallDir() + "/bin/psql -p " + entity.getAttribute(PostgreSqlNode.POSTGRESQL_PORT) + " --command="+ createUserCommand), sudoAsUser("postgres", getInstallDir() + "/bin/psql -p " + entity.getAttribute(PostgreSqlNode.POSTGRESQL_PORT) + " --command="+ createDatabaseCommand), createRolesAdditionalCommand, callPgctl("stop", true)) .failOnNonZeroResultCode().execute(); }
protected void executeDatabaseCreationScript() { if (copyDatabaseCreationScript()) { newScript("running postgres creation script") .body.append( "cd " + getInstallDir(), callPgctl("start", true), sudoAsUser("postgres", getInstallDir() + "/bin/psql -p " + entity.getAttribute(PostgreSqlNode.POSTGRESQL_PORT) + " --file " + getRunDir() + "/creation-script.sql"), callPgctl("stop", true)) .failOnNonZeroResultCode() .execute(); } }
SshMachineLocation.STDERR.getName(), stderrStream), "checkState", ImmutableList.of(BashCommands.sudoAsUser("postgres", installDir + "/bin/psql -p " + port + " --command \"\\du\""))); String stdout = new String(stdoutStream.toByteArray()); String stderr = new String(stderrStream.toByteArray());
if (DynamicTasks.queue(SshEffectorTasks.ssh(sudoAsUser("postgres", "ls "+getInstallDir())).allowingNonZeroExitCode() .summary("check postgres user can access install dir")).asTask().getUnchecked()!=0) { log.info("Postgres install dir "+getInstallDir()+" for "+getEntity()+" is not accessible to user 'postgres'; " + "using "+altInstallDir+" instead");
@Override public void customize() { DynamicTasks.queue(SshEffectorTasks.ssh(sudoAsUser("postgres", "/etc/init.d/postgresql stop")).allowingNonZeroExitCode()).get(); alternativesGroup( chainGroup(format("test -e %s", getInstallDir() + "/bin/initdb"), sudoAsUser("postgres", getInstallDir() + "/bin/initdb -D " + getDataDir())), callPgctl("initdb", true))) .failOnNonZeroResultCode() DynamicTasks.queue( SshEffectorTasks.put("/tmp/postgresql.conf").contents(contents), SshEffectorTasks.ssh(sudoAsUser("postgres", "cp /tmp/postgresql.conf " + getDataDir() + "/postgresql.conf"))); DynamicTasks.queue( SshEffectorTasks.put("/tmp/pg_hba.conf").contents(contents), SshEffectorTasks.ssh(sudoAsUser("postgres", "cp /tmp/pg_hba.conf " + getDataDir() + "/pg_hba.conf")));