@Override public void launch() { VanillaJavaApp entity = getEntity(); String clazz = entity.getMainClass(); String args = getArgs(); Map flags = new HashMap(); flags.put("usePidFile", true); newScript(flags, LAUNCHING). body.append( format("echo \"launching: java $JAVA_OPTS -cp \'lib/*\' %s %s\"",clazz,args), format("java $JAVA_OPTS -cp \"lib/*\" %s %s >> %s/console 2>&1 </dev/null &",clazz, args, getRunDir()) ).execute(); }
@Override public void customize() { newScript(CUSTOMIZING). failOnNonZeroResultCode(). body.append(format("mkdir -p %s/lib", getRunDir())). execute(); SshMachineLocation machine = getMachine(); VanillaJavaApp entity = getEntity(); for (String f : entity.getClasspath()) { int result = machine.installTo(resource, toinstall, getRunDir() + "/" + "lib" + "/"); if (result != 0) throw new IllegalStateException(format("unable to install classpath entry %s for %s at %s",f,entity,machine)); result = machine.execCommands("unzipping", ImmutableList.of(format("cd %s/lib && unzip %s",getRunDir(),destName))); } else if (destName.toLowerCase().endsWith(".tgz") || destName.toLowerCase().endsWith(".tar.gz")) { result = machine.execCommands("untarring gz", ImmutableList.of(format("cd %s/lib && tar xvfz %s",getRunDir(),destName))); } else if (destName.toLowerCase().endsWith(".tar")) { result = machine.execCommands("untarring", ImmutableList.of(format("cd %s/lib && tar xvfz %s",getRunDir(),destName)));
@Override public void stop() { Map flags = new HashMap(); flags.put("usePidFile", true); newScript(flags, STOPPING).execute(); }
@Override protected Map getCustomJavaSystemProperties() { VanillaJavaApp entity = getEntity(); Map result = new HashMap(); result.putAll(super.getCustomJavaSystemProperties()); result.putAll(entity.getJvmDefines()); return result; }
protected String getLogFileLocation() { return format("%s/console", getRunDir()); }
@Override public boolean isRunning() { Map flags = new HashMap(); flags.put("usePidFile", true); int result = newScript(flags, CHECK_RUNNING).execute(); return result == 0; }
@Override protected List<String> getCustomJavaConfigOptions() { VanillaJavaApp entity = getEntity(); List<String> result = new LinkedList<String>(); result.addAll(super.getCustomJavaConfigOptions()); result.addAll(entity.getJvmXArgs()); return result; } }
public String getRunDir() { // FIXME Make this an attribute; don't assume it hsa to be ssh? What uses this? VanillaJavaAppSshDriver driver = (VanillaJavaAppSshDriver) getDriver(); return (driver != null) ? driver.getRunDir() : null; } }
@Override public void install() { newScript(INSTALLING). failOnNonZeroResultCode(). execute(); }
@Override public void kill() { newScript(MutableMap.of("usePidFile", true), KILLING).execute(); }