@Test(groups="Integration") public void testWaitForFileContentsWhenAbortingOnFail() throws Exception { String fileContent = "mycontents"; String cmd = BashCommands.waitForFileContents(destFile.getAbsolutePath(), fileContent, Duration.ONE_SECOND, true); int exitcode = loc.execCommands("test", ImmutableList.of(cmd)); assertEquals(exitcode, 1); Files.write(fileContent, destFile, Charsets.UTF_8); int exitcode2 = loc.execCommands("test", ImmutableList.of(cmd)); assertEquals(exitcode2, 0); }
@Override public void launch() { newScript(MutableMap.of("usePidFile", false), LAUNCHING) .body.append( "mv console-out.log console-out-$(date +\"%Y%m%d.%H%M.%S\").log || true", "nohup ./sbin/rabbitmq-server > console-out.log 2> console-err.log &", "./sbin/rabbitmqctl wait ${RABBITMQ_PID_FILE}", BashCommands.waitForFileContents("console-out.log", "Starting broker... completed", Duration.ONE_MINUTE, true) ).execute(); }
@Test(groups="Integration") public void testWaitForFileContentsWhenNotAbortingOnFail() throws Exception { String fileContent = "mycontents"; String cmd = BashCommands.waitForFileContents(destFile.getAbsolutePath(), fileContent, Duration.ONE_SECOND, false); String output = execRequiringZeroAndReturningStdout(loc, cmd).get(); assertTrue(output.contains("Couldn't find"), "output="+output); Files.write(fileContent, destFile, Charsets.UTF_8); String output2 = execRequiringZeroAndReturningStdout(loc, cmd).get(); assertFalse(output2.contains("Couldn't find"), "output="+output2); }
@Test(groups="Integration") public void testWaitForFileContentsWhenContentsAppearAfterStart() throws Exception { String fileContent = "mycontents"; String cmd = BashCommands.waitForFileContents(destFile.getAbsolutePath(), fileContent, Duration.THIRTY_SECONDS, false); ProcessTaskWrapper<String> t = execRequiringZeroAndReturningStdout(loc, cmd); exec.submit(t); // sleep for long enough to ensure the ssh command is definitely executing Thread.sleep(5*1000); assertFalse(t.isDone()); Files.write(fileContent, destFile, Charsets.UTF_8); String output = t.get(); assertFalse(output.contains("Couldn't find"), "output="+output); }
@Override public void launch() { entity.sensors().set(JBoss7Server.PID_FILE, Os.mergePathsUnix(getRunDir(), PID_FILENAME)); // We wait for evidence of JBoss running because, using SshCliTool, // we saw the ssh session return before the JBoss process was fully running // so the process failed to start. newScript(MutableMap.of(USE_PID_FILE, false), LAUNCHING) .body.append( "export LAUNCH_JBOSS_IN_BACKGROUND=true", format("export JBOSS_HOME=%s", getExpandedInstallDir()), format("export JBOSS_PIDFILE=%s/%s", getRunDir(), PID_FILENAME), "mv "+getRunDir()+"/console "+getRunDir()+"/console-$(date +\"%Y%m%d.%H%M.%S\") || true", format("%s/bin/%s.sh ", getExpandedInstallDir(), SERVER_TYPE) + format("--server-config %s ", CONFIG_FILE) + format("-Djboss.server.base.dir=%s/%s ", getRunDir(), SERVER_TYPE) + format("\"-Djboss.server.base.url=file://%s/%s\" ", getRunDir(), SERVER_TYPE) + "-Djava.net.preferIPv4Stack=true " + "-Djava.net.preferIPv6Addresses=false " + format(" >> %s/console 2>&1 </dev/null &", getRunDir()), BashCommands.waitForFileContents("console", "starting", Duration.TEN_SECONDS, false) ) .execute(); }
@Override public void launch() { Map<String,Integer> ports = new HashMap<String, Integer>(); ports.put("httpPort",getHttpPort()); if (isJmxEnabled()) ports.put("jmxPort",getJmxPort()); Networking.checkPortsValid(ports); String clusterArg = isEmpty(getClusterName()) ? "":"-g "+getClusterName(); // run.sh must be backgrounded otherwise the script will never return. // Don't automatically create pid; instead set JBOSS_PIDFILE to create the pid file we need // We wait for evidence of tomcat running because, using SshCliTool, // we saw the ssh session return before the tomcat process was fully running // so the process failed to start. newScript(MutableMap.of(USE_PID_FILE, false), LAUNCHING) .body.append( format("export JBOSS_CLASSPATH=%s/lib/jboss-logmanager.jar",getExpandedInstallDir()), format("export JBOSS_PIDFILE=%s/%s", getRunDir(), PID_FILENAME), "mv "+getRunDir()+"/console "+getRunDir()+"/console-$(date +\"%Y%m%d.%H%M.%S\") || true", format("%s/bin/run.sh -Djboss.service.binding.set=%s -Djboss.server.base.dir=$RUN_DIR/server ",getExpandedInstallDir(),PORT_GROUP_NAME) + format("-Djboss.server.base.url=file://$RUN_DIR/server -Djboss.messaging.ServerPeerID=%s ",entity.getId())+ format("-Djboss.boot.server.log.dir=%s/server/%s/log ", getRunDir(), SERVER_TYPE) + format("-b %s %s -c %s ", getBindAddress(), clusterArg, SERVER_TYPE) + ">>$RUN_DIR/console 2>&1 </dev/null &", BashCommands.waitForFileContents(getRunDir()+"/console", "Starting", Duration.TEN_SECONDS, false) ) .execute(); }