protected static String cdAndRun(String targetDirectory, String command) { return BashCommands.chain("mkdir -p "+targetDirectory, "cd "+targetDirectory, command); }
", may fail subsequently")); if (optionalCommandToRunIfNone != null) lastCommand = chain(lastCommand, optionalCommandToRunIfNone); commands.add(lastCommand);
protected static String cdAndRun(String targetDirectory, String command) { return BashCommands.chain("mkdir -p "+targetDirectory, "cd "+targetDirectory, command); }
protected static String cdAndRun(String targetDirectory, String command) { return BashCommands.chain("mkdir -p '"+targetDirectory+"'", "cd '"+targetDirectory+"'", command); }
protected static String cdAndRun(String targetDirectory, String command) { return BashCommands.chain("mkdir -p '"+targetDirectory+"'", "cd '"+targetDirectory+"'", command); }
/** * Returns the command that adds firewalld direct rule. * * @return Returns the command that adds firewalld direct rule. */ public static String addFirewalldRule(Chain chain, Optional<String> networkInterface, org.apache.brooklyn.util.net.Protocol protocol, int port, Policy policy) { String command = new String("/usr/bin/firewall-cmd"); String commandPermanent = new String("/usr/bin/firewall-cmd --permanent"); String interfaceParameter = String.format("%s", networkInterface.isPresent() ? " -i " + networkInterface.get() : ""); String commandParameters = String.format(" --direct --add-rule ipv4 filter %s 0 %s -p %s --dport %d -j %s", chain, interfaceParameter, protocol, port, policy); return sudo(chain(command + commandParameters, commandPermanent + commandParameters)); } }
public static String commandToDownloadUrlsAs(List<String> urls, String saveAs) { return chain(INSTALL_CURL, require(simpleDownloadUrlAs(urls, saveAs), "Could not retrieve "+saveAs+". Tried: " + Joiner.on(", ").join(urls), 9)); } public static String commandToDownloadUrlAs(String url, String saveAs) {
/** * Returns command to download the URL, sending the output to stdout -- * suitable for redirect by appending " | tar xvf". * Will try each URL in turn until one is successful */ public static String downloadToStdout(List<String> urls) { return chain( INSTALL_CURL + " > /dev/null", require(simpleDownloadUrlAs(urls, null), "Could not retrieve file. Tried: " + Joiner.on(", ").join(urls), 9)); }
public static String commandToDownloadUrlAs(String url, String saveAs) { return chain(INSTALL_CURL, require(simpleDownloadUrlAs(Arrays.asList(url), saveAs), "Could not retrieve "+saveAs+" from " + url, 9)); }
private String getUnpackCommand(String tmpLocation) { if (tmpLocation.endsWith("tar")) { return sudo(format("tar xvf %s -C %s", tmpLocation, stackResourceLocation())); } else if (tmpLocation.endsWith("tar.gz")) { return sudo(format("tar zxvf %s -C %s", tmpLocation, stackResourceLocation())); } else if (tmpLocation.endsWith("zip")) { return BashCommands.chain( BashCommands.INSTALL_UNZIP, sudo(unzip(tmpLocation, stackResourceLocation()))); } throw new IllegalStateException("Stack locations must be of type tar, tar.gz, zip"); }
private void insertCallback(Entity entity, ConfigKey<String> commandKey, String callback) { String command = entity.config().get(commandKey); if (Strings.isNonBlank(command)) { command = BashCommands.chain(String.format("( %s )", command), callback); } else { command = callback; } entity.config().set(commandKey, command); }
/** * 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"))); }
private boolean checkFileExistsOnEntity(Entity entity, String path) { String cmd = BashCommands.chain( BashCommands.requireTest(String.format("-f \"%s\"", path), "File " + path + " doesn't exist.")); String summary = "Check if file " + path + " exists"; return DynamicTasks.queue(execSshTask(entity, cmd, summary).allowingNonZeroExitCode()).asTask().getUnchecked() == 0; }
@Override public void launch() { InetAddress address = getEntity().sensors().get(WeaveRouter.SDN_AGENT_ADDRESS); Boolean firstMember = getEntity().sensors().get(AbstractGroup.FIRST_MEMBER); Entity first = getEntity().sensors().get(AbstractGroup.FIRST); LOG.info("Launching {} Weave service at {}", Boolean.TRUE.equals(firstMember) ? "first" : "next", address.getHostAddress()); newScript(MutableMap.of(USE_PID_FILE, false), LAUNCHING) .body.append( chain( BashCommands.sudo(String.format("%s launch-router --ipalloc-range %s %s", getWeaveCommand(), entity.config().get(SdnProvider.CONTAINER_NETWORK_CIDR), Boolean.TRUE.equals(firstMember) ? "" : first.sensors().get(Attributes.SUBNET_ADDRESS))), BashCommands.sudo(String.format("%s launch-plugin", getWeaveCommand())))) .failOnNonZeroResultCode() .uniqueSshConnection() .execute(); }
/** task which returns 0 if pid in the given file is running; * method accepts wildcards so long as they match a single file on the remote end * <p> * returns 1 if no matching file, * 1 if matching file but no matching process, * and 2 if 2+ matching files */ public static SshEffectorTaskFactory<Integer> codePidFromFileRunning(final String pidFile) { return ssh(BashCommands.chain( // this fails, but isn't an error BashCommands.requireTest("-f "+pidFile, "The PID file "+pidFile+" does not exist."), // this fails and logs an error picked up later BashCommands.requireTest("`ls "+pidFile+" | wc -w` -eq 1", "ERROR: there are multiple matching PID files"), // this fails and logs an error picked up later BashCommands.require("cat "+pidFile, "ERROR: the PID file "+pidFile+" cannot be read (permissions?)."), // finally check the process "ps -p `cat "+pidFile+"`")).summary("PID file "+pidFile+" is-running check (exit code)") .allowingNonZeroExitCode() .addCompletionListener(new Function<ProcessTaskWrapper<?>,Void>() { @Override public Void apply(ProcessTaskWrapper<?> input) { if (input.getStderr().contains("ERROR:")) throw new IllegalStateException("Invalid or inaccessible PID filespec: "+pidFile); return null; } }); }
private boolean fileExists(MySqlNode node, String binLogName) { String dataDir = Strings.nullToEmpty(node.getConfig(MySqlNode.DATA_DIR)); String path = Os.mergePathsUnix(dataDir, binLogName); String cmd = BashCommands.chain( "cd $RUN_DIR", BashCommands.requireTest(String.format("-f \"%s\"", path), "File " + path + " doesn't exist.")); String summary = "Check if file " + path + " exists"; SshMachineLocation machine = EffectorTasks.getSshMachine(node); return Entities.submit(node, SshTasks.newSshExecTaskFactory(machine, cmd) .allowingNonZeroExitCode() .environmentVariable("RUN_DIR", node.getAttribute(SoftwareProcess.RUN_DIR)) .summary(summary) .allowingNonZeroExitCode()).asTask().getUnchecked() == 0; } private void cleanData() {
@Override public void install() { LOG.info("Installing Node.JS {}", getVersion()); List<String> commands = MutableList.<String>builder() .add(BashCommands.INSTALL_CURL) .add(BashCommands.ifExecutableElse0("apt-get", BashCommands.chain( BashCommands.installPackage("software-properties-common python-software-properties python g++ make"), BashCommands.sudo("add-apt-repository ppa:chris-lea/node.js")))) .add(BashCommands.installPackage(MutableMap.of("yum", "git nodejs npm", "apt", "git-core nodejs npm"), null)) .add("mkdir -p \"$HOME/.npm\"") .add(BashCommands.sudo("npm install -g n")) .add(BashCommands.sudo("n " + getVersion())) .build(); newScript(INSTALLING) .body.append(commands) .execute(); }
false, null, destName).newTask()); String installCmd = BashCommands.chain( "cd "+privateTmpDirContainingUnpackedCookbook, "COOKBOOK_EXPANDED_DIR=`ls`",
false, null, destName).newTask()); String installCmd = BashCommands.chain( "cd "+privateTmpDirContainingUnpackedCookbook, "COOKBOOK_EXPANDED_DIR=`ls`",
.newTask(); ProcessTaskWrapper<Integer> installServiceTask = SshTasks.newSshExecTaskFactory(sshMachine, BashCommands.chain( BashCommands.sudo("mv " + tmpServicePath + " " + servicePath), BashCommands.sudo("chmod 0755 " + servicePath),