/** as {@link #codePidFromFileRunning(String)} but returning boolean */ public static SshEffectorTaskFactory<Boolean> isPidFromFileRunning(String pidFile) { return codePidFromFileRunning(pidFile).summary("PID file "+pidFile+" is-running check (boolean)"). returning(new Function<ProcessTaskWrapper<?>, Boolean>() { @Override public Boolean apply(@Nullable ProcessTaskWrapper<?> input) { return ((Integer)0).equals(input.getExitCode()); } }); }
/** task which fails if the pid in the given file is not running (or if there is no such PID file); * method accepts wildcards so long as they match a single file on the remote end (fails if 0 or 2+ matching files) */ public static SshEffectorTaskFactory<?> requirePidFromFileRunning(String pidFile) { return codePidFromFileRunning(pidFile) .summary("PID file "+pidFile+" is-running check (required)") .requiringExitCodeZero("Process with PID from file "+pidFile+" is required to be running"); }
@Test(groups="Integration") public void testRunningPidFromFile() throws IOException { File f = File.createTempFile("testBrooklynPid", ".pid"); Files.write( (""+getMyPid()).getBytes(), f ); ProcessTaskWrapper<Integer> t = submit(SshEffectorTasks.codePidFromFileRunning(f.getPath())); Assert.assertEquals(t.getTask().getUnchecked(), (Integer)0); ProcessTaskWrapper<Boolean> t2 = submit(SshEffectorTasks.isPidFromFileRunning(f.getPath())); Assert.assertTrue(t2.getTask().getUnchecked()); }