public static ShellResult runAndReturn(String cmdsr) { return runAndReturn(cmdsr, null); }
public static String run(String cmdsr) { return run(cmdsr, null); }
public static String runVerbose(String cmdstr, String baseDir, boolean withSudo) { return doRun(cmdstr, baseDir, withSudo, true); }
public static ShellResult runAndReturn(String cmdsr, boolean withSudo) { return doRunAndReturn(cmdsr, null, withSudo); }
public static String runVerbose(String cmdstr) { return runVerbose(cmdstr, null); }
public static ShellResult runAndReturn(String cmdstr, String baseDir, boolean withSudo) { return doRunAndReturn(cmdstr, baseDir, withSudo); }
protected int setConsoleProxyOverridenIp(String newIp) { if (CoreGlobalProperty.UNIT_TEST_ON) { return 0; } ShellResult rst = ShellUtils.runAndReturn( "/usr/bin/zstack-ctl configure consoleProxyOverriddenIp=" + newIp ); return rst.getRetCode(); }
public static String run(String cmdsr, boolean withSudo) { return run(cmdsr, null, withSudo); }
public static String run(String cmdstr, String baseDir, boolean withSudo) { return doRun(cmdstr, baseDir, withSudo, false); }
public static ShellResult runAndReturn(String cmdstr, String baseDir) { return doRunAndReturn(cmdstr, baseDir, true); }
public static void appendRuleToFilterTable(String rule) { ShellResult ret = ShellUtils.runAndReturn(String.format("/sbin/iptables-save | grep -- '%s' > /dev/null", rule)); if (ret.getRetCode() == 0) { return; } ret = ShellUtils.runAndReturn(String.format("/sbin/iptables %s", rule)); ret.raiseExceptionIfFail(); }
void init() { if (CoreGlobalProperty.UNIT_TEST_ON) { return; } ShellUtils.run(String.format("mkdir -p %s", AgentConstant.SRC_ANSIBLE_ROOT), false); File srcFolder = PathUtil.findFolderOnClassPath(AgentConstant.ANSIBLE_MODULE_PATH, true); srcRootFolder = srcFolder.getAbsolutePath(); ShellUtils.run(String.format("yes | cp -r %s/server %s", srcRootFolder, AgentConstant.SRC_ANSIBLE_ROOT), false); }
public static String runVerbose(String cmdstr, String baseDir) { return doRun(cmdstr, baseDir, true); }
public static void insertRuleToFilterTable(String rule) { ShellResult ret = ShellUtils.runAndReturn(String.format("/sbin/iptables-save | grep -- '%s' > /dev/null", rule)); if (ret.getRetCode() == 0) { return; } ret = ShellUtils.runAndReturn(String.format("/sbin/iptables %s", rule.replace("-A", "-I"))); ret.raiseExceptionIfFail(); } }
private void placePip703() { File pip = PathUtil.findFileOnClassPath("tools/pip-7.0.3.tar.gz"); if (pip == null) { throw new CloudRuntimeException("cannot find tools/pip-7.0.3.tar.gz on classpath"); } File root = new File(filesDir); if (!root.exists()) { root.mkdirs(); } ShellUtils.run(String.format("yes | cp %s %s", pip.getAbsolutePath(), filesDir)); }
public static String run(String cmdstr, String baseDir) { return doRun(cmdstr, baseDir, false); }
public static boolean isIpRoutedByDefaultGateway(String ip) { ShellResult res = ShellUtils.runAndReturn(String.format("ip route get %s | grep -q \"via $(ip route | awk '/default/ {print $3}')\"", ip)); return res.isReturnCode(0); }
private void placeAnsible196() { File ansible = PathUtil.findFileOnClassPath("tools/ansible-1.9.6.tar.gz"); if (ansible == null) { throw new CloudRuntimeException("cannot find tools/ansible-1.9.6.tar.gz on classpath"); } File root = new File(filesDir); if (!root.exists()) { root.mkdirs(); } ShellUtils.run(String.format("yes | cp %s %s", ansible.getAbsolutePath(), filesDir)); }
private static String doRun(String cmdstr, String baseDir, boolean isVerbose) { return doRun(cmdstr, baseDir, true, isVerbose); }
public static boolean killProcess(int pid, Integer timeout) { timeout = timeout == null ? 30 : timeout; if (!TimeUtils.loopExecuteUntilTimeoutIgnoreExceptionAndReturn(timeout, 1, TimeUnit.SECONDS, () -> { ShellUtils.runAndReturn(String.format("kill %s", pid)); return !new ProcessFinder().processExists(pid); })) { logger.warn(String.format("cannot kill the process[PID:%s] after %s seconds, kill -9 it", pid, timeout)); ShellUtils.runAndReturn(String.format("kill -9 %s", pid)); } if (!TimeUtils.loopExecuteUntilTimeoutIgnoreExceptionAndReturn(5, 1, TimeUnit.SECONDS, () -> !new ProcessFinder().processExists(pid))) { logger.warn(String.format("FAILED TO KILL -9 THE PROCESS[PID:%s], THE KERNEL MUST HAVE SOMETHING RUN", pid)); return false; } else { return true; } }