@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()); }
protected boolean tryCheckStartPid() { if (getPidFile()==null) return false; // if it's still up after 5s assume we are good (default behaviour) Time.sleep(Duration.FIVE_SECONDS); if (!DynamicTasks.queue(SshEffectorTasks.isPidFromFileRunning(getPidFile()).runAsRoot()).get()) { throw new IllegalStateException("The process for "+entity()+" appears not to be running (pid file "+getPidFile()+")"); } // and set the PID entity().sensors().set(Attributes.PID, Integer.parseInt(DynamicTasks.queue(SshEffectorTasks.ssh("cat "+getPidFile()).runAsRoot()).block().getStdout().trim())); return true; }
protected boolean tryCheckStartPid() { if (getPidFile()==null) return false; // if it's still up after 5s assume we are good (default behaviour) Time.sleep(Duration.FIVE_SECONDS); if (!DynamicTasks.queue(SshEffectorTasks.isPidFromFileRunning(getPidFile()).runAsRoot()).get()) { throw new IllegalStateException("The process for "+entity()+" appears not to be running (pid file "+getPidFile()+")"); } // and set the PID entity().sensors().set(Attributes.PID, Integer.parseInt(DynamicTasks.queue(SshEffectorTasks.ssh("cat "+getPidFile()).runAsRoot()).block().getStdout().trim())); return true; }
@Override protected void postStartCustom() { // if it's still up after 5s assume we are good Time.sleep(Duration.FIVE_SECONDS); if (!DynamicTasks.queue(SshEffectorTasks.isPidFromFileRunning(dir(entity)+"/*/data/*.pid")).get()) { // but if it's not up add a bunch of other info log.warn("MySQL did not start: "+dir(entity)); ProcessTaskWrapper<Integer> info = DynamicTasks.queue(SshEffectorTasks.ssh( "cd "+dir(entity)+"/*", "cat out.log", "cat err.log > /dev/stderr")).block(); log.info("STDOUT:\n"+info.getStdout()); log.info("STDERR:\n"+info.getStderr()); BrooklynTaskTags.addTagsDynamically(Tasks.current(), BrooklynTaskTags.tagForStream("console (nohup stdout)", Suppliers.ofInstance(info.getStdout()), null), BrooklynTaskTags.tagForStream("console (nohup stderr)", Suppliers.ofInstance(info.getStderr()), null)); throw new IllegalStateException("MySQL appears not to be running"); } // and set the PID entity().sensors().set(Attributes.PID, Integer.parseInt(DynamicTasks.queue(SshEffectorTasks.ssh("cat "+dir(entity)+"/*/data/*.pid")).block().getStdout().trim())); // TODO Without this, tests fail because nothing else sets serviceUp! // Really should set this with a Feed that checks pid periodically. // Should this instead be using SERVICE_NOT_UP_INDICATORS? entity().sensors().set(Attributes.SERVICE_UP, true); super.postStartCustom(); }