public static String run(String cmdsr, boolean withSudo) { return run(cmdsr, null, withSudo); }
public static String run(String cmdsr) { return run(cmdsr, null); }
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); }
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 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)); }
private void setupPublicKey() { File pubKeyFile = PathUtil.findFileOnClassPath(AnsibleConstant.RSA_PUBLIC_KEY); String script = PathUtil.findFileOnClassPath(AnsibleConstant.IMPORT_PUBLIC_KEY_SCRIPT_PATH, true).getAbsolutePath(); if (pubKeyFile != null) { ShellUtils.run(String.format("sh %s '%s'", script, pubKeyFile.getAbsolutePath())); } }
private void setupPublicKey() throws IOException { File pubKeyFile = PathUtil.findFileOnClassPath(AnsibleConstant.RSA_PUBLIC_KEY); String script = PathUtil.findFileOnClassPath(AnsibleConstant.IMPORT_PUBLIC_KEY_SCRIPT_PATH, true).getAbsolutePath(); if (localPublicKey) { ShellUtils.run(String.format("sh %s %s", script, pubKeyFile.getAbsolutePath())); } else { setupPublicKeyOnRemote(); } }
@Override public void registerAgent(AgentStruct struct) { Map<String, AgentStruct> m = agents.get(struct.getAgentOwner()); if (m == null) { m = new HashMap<String, AgentStruct>(); agents.put(struct.getAgentOwner(), m); } AgentStruct old = m.get(struct.getAgentId()); if (old != null) { throw new CloudRuntimeException(String.format("there has been an agent[id:%s] registered to the owner[%s]", struct.getAgentId(), struct.getAgentOwner())); } m.put(struct.getAgentId(), struct); ShellUtils.run(String.format("yes | cp -r %s %s", struct.getFileFolder(), AgentConstant.SRC_ANSIBLE_ROOT), false); } }
private void prepareSaltMaster() throws IOException { File srcMasterConf = rewriteMasterConfFile(); try { IptablesUtils.insertRuleToFilterTable("-A INPUT -p tcp -m state --state NEW -m tcp --dport 4505 -j ACCEPT"); IptablesUtils.insertRuleToFilterTable("-A INPUT -p tcp -m state --state NEW -m tcp --dport 4506 -j ACCEPT"); File dstMasterConf = new File(PathUtil.join(SaltConstant.SALT_CONF_HOME, SaltConstant.MASTER_CONF_NAME)); if (deployFile(srcMasterConf, dstMasterConf)) { ShellUtils.run("service salt-master restart"); } } finally { srcMasterConf.delete(); } }
placeAnsible196(); ShellUtils.run(String.format("if ! ansible --version | grep -q 1.9.6; then " + "if grep -i -s centos /etc/system-release; then " + "sudo yum remove -y ansible; " +
String output; if (AnsibleGlobalProperty.DEBUG_MODE2) { output = ShellUtils.run(String.format("PYTHONPATH=%s timeout %d %s %s -i %s -vvvv --private-key %s -e '%s' | tee -a %s", AnsibleConstant.ZSTACKLIB_ROOT, timeout, executable, playBookPath, AnsibleConstant.INVENTORY_FILE, msg.getPrivateKeyFile(), JSONObjectUtil.dumpPretty(arguments), AnsibleConstant.LOG_PATH), AnsibleConstant.ROOT_DIR); } else if (AnsibleGlobalProperty.DEBUG_MODE) { output = ShellUtils.run(String.format("PYTHONPATH=%s timeout %d %s %s -i %s -vvvv --private-key %s -e '%s'", AnsibleConstant.ZSTACKLIB_ROOT, timeout, executable, playBookPath, AnsibleConstant.INVENTORY_FILE, msg.getPrivateKeyFile(), JSONObjectUtil.dumpPretty(arguments)), AnsibleConstant.ROOT_DIR); } else { output = ShellUtils.run(String.format("PYTHONPATH=%s timeout %d %s %s -i %s --private-key %s -e '%s'", AnsibleConstant.ZSTACKLIB_ROOT, timeout, executable, playBookPath, AnsibleConstant.INVENTORY_FILE, msg.getPrivateKeyFile(), JSONObjectUtil.dumpPretty(arguments)), AnsibleConstant.ROOT_DIR);
ShellUtils.run(String.format("chmod 600 %s", privKeyFile.getAbsolutePath())); File pubKeyFile = PathUtil.findFileOnClassPath(AnsibleConstant.RSA_PUBLIC_KEY);
ShellUtils.run("rm -rf /var/lib/zstack/consoleProxy/ && mkdir -p /var/lib/zstack/consoleProxy/");