@Override public void customize(JcloudsLocation location, ComputeService computeService, JcloudsMachineLocation machine) { JcloudsSshMachineLocation ssh = (JcloudsSshMachineLocation) machine; String name = ssh.getOptionalNode().get().getName(); List<String> commands = ImmutableList.of( String.format("echo %s | ( %s )", name, BashCommands.sudo("tee /etc/hostname")), String.format("echo 127.0.0.1 localhost | ( %s )", BashCommands.sudo("tee /etc/hosts"))); DynamicTasks.queue(SshEffectorTasks.ssh(commands) .machine(ssh) .requiringExitCodeZero()).block(); LOG.debug("Set {} hostname to {}", new Object[] { ssh, name }); } }
@Override public void run() { String publicKey = tempKeyTask.getUnchecked(); DynamicTasks.queue(SshEffectorTasks.ssh(String.format( "cat >> ~/.ssh/authorized_keys <<EOF\n%s\nEOF", publicKey)) .machine(destMachine) .summary("Add key to authorized_keys") .requiringExitCodeZero()); } });
"echo BASE_DIR_RESULT':'`pwd`:BASE_DIR_RESULT") .environmentVariable("BASE_DIR", base) .requiringExitCodeZero() .summary("initializing on-box base dir "+base).newTask(); DynamicTasks.queueIfPossible(baseTask).orSubmitAsync(entity);
"ln -s "+altInstallDir+" "+getInstallDir(), "mkdir -p " + newRunDir, "chown -R postgres:postgres "+altTarget).runAsRoot().requiringExitCodeZero() .summary("move install dir from user to postgres owned space"));
tb.add(SshEffectorTasks.ssh(installCmd).summary("renaming cookbook dir").requiringExitCodeZero().newTask());
tb.add(SshEffectorTasks.ssh(installCmd).summary("renaming cookbook dir").requiringExitCodeZero().newTask());
@Test(groups="Live") public void testPostgresStartsAndStops() throws Exception { ChefLiveTestSupport.installBrooklynChefHostedConfig(app); psql = app.createAndManageChild(PostgreSqlSpecs.specChef()); app.start(ImmutableList.of(targetLocation)); Entities.submit(psql, SshEffectorTasks.ssh("ps aux | grep [p]ostgres").requiringExitCodeZero()); SshMachineLocation targetMachine = EffectorTasks.getSshMachine(psql); psql.stop(); try { // if host is still contactable ensure postgres is not running ProcessTaskWrapper<Integer> t = Entities.submit(app, SshEffectorTasks.ssh("ps aux | grep [p]ostgres").machine(targetMachine).allowingNonZeroExitCode()); t.getTask().blockUntilEnded(Duration.TEN_SECONDS); if (!t.isDone()) Assert.fail("Task not finished yet: "+t.getTask()); Assert.assertNotEquals(t.get(), 0, "Task ended with code "+t.get()+"; output: "+t.getStdout() ); } catch (Exception e) { // host has been killed, that is fine log.info("Machine "+targetMachine+" destroyed on stop (expected - "+e+")"); } }
private void deleteSnapshot(MySqlCluster cluster) { ReplicationSnapshot replicationSnapshot = cluster.getAttribute(MySqlCluster.REPLICATION_LAST_SLAVE_SNAPSHOT); Entity snapshotEntity = mgmt.getEntityManager().getEntity(replicationSnapshot.getEntityId()); SshMachineLocation machine = EffectorTasks.getSshMachine(snapshotEntity); Entities.submit(snapshotEntity, SshEffectorTasks.ssh( "cd $RUN_DIR", "rm " + replicationSnapshot.getSnapshotPath()) .summary("clear snapshot") .machine(machine) .environmentVariable("RUN_DIR", snapshotEntity.getAttribute(MySqlNode.RUN_DIR)) .requiringExitCodeZero()) .asTask() .getUnchecked(); }
public ProcessTaskWrapper<Integer> executeScriptFromInstalledFileAsync(String filenameAlreadyInstalledAtServer) { return DynamicTasks.queue( SshEffectorTasks.ssh( "cd "+getRunDir(), getBaseDir()+"/bin/mysql --defaults-file="+getConfigFile()+" < "+filenameAlreadyInstalledAtServer) .requiringExitCodeZero() .summary("executing datastore script "+filenameAlreadyInstalledAtServer)); }
public static TaskFactory<?> runChef(String runDir, String phase) { // TODO chef server return SshEffectorTasks.ssh(cdAndRun(runDir, "sudo chef-solo -c "+phase+".rb -j "+phase+".json -ldebug")). summary("run chef for "+phase).requiringExitCodeZero(); }
private boolean installFile(InputStream contents, String destName) { String uid = Identifiers.makeRandomId(8); // TODO currently put in /tmp for staging, since run dir may not be accessible to ssh user getMachine().copyTo(contents, "/tmp/"+destName+"_"+uid); DynamicTasks.queueIfPossible(SshEffectorTasks.ssh( "cd "+getRunDir(), "mv /tmp/"+destName+"_"+uid+" "+destName, "chown postgres:postgres "+destName, "chmod 644 "+destName) .runAsRoot().requiringExitCodeZero()) .orSubmitAndBlock(getEntity()).andWaitForSuccess(); return true; } private boolean copyDatabaseCreationScript() {
public static TaskFactory<?> runChef(String runDir, String phase) { // TODO chef server return SshEffectorTasks.ssh(cdAndRun(runDir, "sudo chef-solo -c "+phase+".rb -j "+phase+".json -ldebug")). summary("run chef for "+phase).requiringExitCodeZero(); }
/** see {@link ChefConfig#CHEF_RUN_CONVERGE_TWICE} for background on why 'twice' is available */ public static TaskFactory<?> runChef(String runDir, String phase, Boolean twice) { String cmd = "sudo chef-solo -c "+phase+".rb -j "+phase+".json -ldebug"; if (twice!=null && twice) cmd = BashCommands.alternatives(cmd, cmd); return SshEffectorTasks.ssh(cdAndRun(runDir, cmd)). summary("run chef for "+phase).requiringExitCodeZero(); }
@Override protected void createDirectory(String directoryName, String summaryForLogging) { DynamicTasks.queue(SshEffectorTasks.ssh("mkdir -p " + directoryName).summary(summaryForLogging) .requiringExitCodeZero()).get(); }
/** task which fails if the pid in the given file is not running (or if there is no such PID file); * method accepts wildcards so long as they match a single file on the remote end (fails if 0 or 2+ matching files) */ public static SshEffectorTaskFactory<?> requirePidFromFileRunning(String pidFile) { return codePidFromFileRunning(pidFile) .summary("PID file "+pidFile+" is-running check (required)") .requiringExitCodeZero("Process with PID from file "+pidFile+" is required to be running"); }
/** task which fails if the given PID is not running */ public static SshEffectorTaskFactory<?> requirePidRunning(Integer pid) { return codePidRunning(pid).summary("PID "+pid+" is-running check (required)").requiringExitCodeZero("Process with PID "+pid+" is required to be running"); }
/** see {@link ChefConfig#CHEF_RUN_CONVERGE_TWICE} for background on why 'twice' is available */ public static TaskFactory<?> runChef(String runDir, String phase, Boolean twice) { String cmd = "sudo chef-solo -c "+phase+".rb -j "+phase+".json -ldebug"; if (twice!=null && twice) cmd = BashCommands.alternatives(cmd, cmd); return SshEffectorTasks.ssh(cdAndRun(runDir, cmd)). summary("run chef for "+phase).requiringExitCodeZero(); }
@Override public void changePassword(String oldPass, String newPass) { DynamicTasks.queue( SshEffectorTasks.ssh( "cd "+getRunDir(), getBaseDir()+"/bin/mysqladmin --defaults-file="+getConfigFile()+" --password=" + oldPass + " password "+newPass) .summary("setting password") .requiringExitCodeZero()); }
@Override public String call(ConfigBag parameters) { return DynamicTasks.queue(SshEffectorTasks.ssh( BashCommands.pipeTextTo( parameters.get(SCRIPT), BashCommands.sudoAsUser("postgres", "psql --file -"))) .requiringExitCodeZero()).getStdout(); } }
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)); }