@Override protected String buildKnifeCommand(int knifeCommandIndex) { String result = super.buildKnifeCommand(knifeCommandIndex); if (Boolean.TRUE.equals(runTwice)) result = BashCommands.alternatives(result, result); return result; }
@Override protected String buildKnifeCommand(int knifeCommandIndex) { String result = super.buildKnifeCommand(knifeCommandIndex); if (Boolean.TRUE.equals(runTwice)) result = BashCommands.alternatives(result, result); return result; }
@Beta // implementation not portable across distros public static String iptablesService(String cmd) { return sudo(alternatives( BashCommands.ifExecutableElse1("service", "service iptables " + cmd), "/sbin/service iptables " + cmd)); }
@Beta // implementation not portable across distros public static String firewalldService(String cmd) { return sudo(alternatives( BashCommands.ifExecutableElse1("systemctl", "systemctl " + cmd + " firewalld"), "/usr/bin/systemctl " + cmd + " firewalld")); }
private String useYum(String osVersion, String arch, String epelRelease) { String osMajorVersion = osVersion.substring(0, osVersion.lastIndexOf(".")); return chainGroup( alternatives( sudo("rpm -qa | grep epel-release"), sudo(format("rpm -Uvh http://dl.fedoraproject.org/pub/epel/%s/%s/epel-release-%s.noarch.rpm", osMajorVersion, arch, epelRelease)))); }
public static String installJava6OrFail() { return alternatives(installJava6(), fail("java 6 install failed", 9)); } public static String installJava7OrFail() {
public static String installJava7OrFail() { return alternatives(installJava7(), fail("java 7 install failed", 9)); } public static String installJava7Or6OrFail() {
public static String installJava7Or6OrFail() { return alternatives(installJava7(), installJava6(), fail("java install failed", 9)); } public static String installJavaLatestOrFail() {
public static TaskFactory<?> installChef(String chefDirectory, boolean force) { // TODO check on entity whether it is chef _server_ String installCmd = cdAndRun(chefDirectory, ChefBashCommands.INSTALL_FROM_OPSCODE); if (!force) installCmd = BashCommands.alternatives("which chef-solo", installCmd); return SshEffectorTasks.ssh(installCmd).summary("install chef"); }
private String createCommandToAddAmbariToRepositoriesList(SshMachineLocation sshMachineLocation) { return alternatives(setupAptRepo(sshMachineLocation), setupYumRepo(sshMachineLocation), setupZypperRepo()); }
public static TaskFactory<?> installChef(String chefDirectory, boolean force) { // TODO check on entity whether it is chef _server_ String installCmd = cdAndRun(chefDirectory, ChefBashCommands.INSTALL_FROM_OPSCODE); if (!force) installCmd = BashCommands.alternatives("which chef-solo", installCmd); return SshEffectorTasks.ssh(installCmd).summary("install chef"); }
public static TaskFactory<?> installChef(String chefDirectory, boolean force) { // TODO check on entity whether it is chef _server_ String installCmd = cdAndRun(chefDirectory, ChefBashCommands.INSTALL_FROM_OPSCODE); if (!force) installCmd = BashCommands.alternatives("which chef-solo", installCmd); return SshEffectorTasks.ssh(installCmd).summary("install chef"); }
public static TaskFactory<?> installChef(String chefDirectory, boolean force) { // TODO check on entity whether it is chef _server_ String installCmd = cdAndRun(chefDirectory, ChefBashCommands.INSTALL_FROM_OPSCODE); if (!force) installCmd = BashCommands.alternatives("which chef-solo", installCmd); return SshEffectorTasks.ssh(installCmd).summary("install chef"); }
/** 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(); }
public static String installJavaLatestOrWarn() { return alternatives(installJava8(), installJava7(), installJava6(), warn("java latest install failed, entity may subsequently fail")); }
/** 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(); }
/** * Returns the command that saves iptables rules on file. * * @return Returns the command that saves iptables rules on file. * */ public static String saveIptablesRules() { return alternatives(sudo("service iptables save"), chain(installPackage("iptables-persistent"), sudo("/etc/init.d/iptables-persistent save"))); }
public String installAmbariRequirements(SshMachineLocation machine) { return BashCommands.chainGroup(BashCommands.INSTALL_CURL, installExecutable("ntp"), BashCommands.alternatives(sudo("service ntpd start"), sudo("service ntp start")), createCommandToAddAmbariToRepositoriesList(machine)); }
@Test(groups="Integration") public void testAlternatives() throws Exception { ProcessTaskWrapper<Integer> t = SshTasks.newSshExecTaskFactory(loc) .add(BashCommands.alternatives(Arrays.asList("asdfj_no_such_command_1", "exit 88"))) .newTask(); Integer returnCode = exec.submit(t).get(); log.info("alternatives for bad commands gave: "+returnCode+"; err="+new String(t.getStderr())+"; out="+new String(t.getStdout())); assertEquals(returnCode, (Integer)88); }
@Test(groups="Integration") public void testAlternativesWhereFirstSucceeds() throws Exception { ProcessTaskWrapper<Integer> t = SshTasks.newSshExecTaskFactory(loc) .add(BashCommands.alternatives(Arrays.asList("echo first", "exit 88"))) .newTask(); Integer returnCode = exec.submit(t).get(); String stdout = t.getStdout(); String stderr = t.getStderr(); log.info("alternatives for good first command gave: "+returnCode+"; err="+stderr+"; out="+stdout); assertTrue(stdout.contains("first"), "errcode="+returnCode+"; stdout="+stdout+"; stderr="+stderr); assertEquals(returnCode, (Integer)0); }