private int kill() throws CommandException { File prevPid = null; String pids = null; try { prevPid = new File(getServerDirs().getPidFile().getPath() + ".prev"); if (!prevPid.canRead()) throw new CommandException(Strings.get("StopInstance.nopidprev", prevPid)); pids = FileUtils.readSmallFile(prevPid).trim(); String s = ProcessUtils.kill(Integer.parseInt(pids)); if (s != null) logger.finer(s); } catch (CommandException ce) { throw ce; } catch (Exception ex) { throw new CommandException( Strings.get("StopInstance.pidprevreaderror", prevPid, ex.getMessage())); } return 0; }
@Override public void execute(AdminCommandContext context) { Target targetUtil = habitat.getComponent(Target.class); Config newConfig = targetUtil.getConfig(target); if (newConfig != null) { config = newConfig; } report = context.getActionReport(); try { final Protocols protocols = config.getNetworkConfig().getProtocols(); final Protocol protocol = protocols.findProtocol(protocolName); validate( protocol, "create.http.fail.protocolnotfound", "The specified protocol {0} is not yet configured", protocolName); final Class<?> filterClass = Thread.currentThread().getContextClassLoader().loadClass(classname); if (!com.sun.grizzly.ProtocolFilter.class.isAssignableFrom(filterClass)) { report.setMessage( localStrings.getLocalString( "create.portunif.fail.notfilter", "{0} create failed. Given class is not a ProtocolFilter: {1}", name, classname)); report.setActionExitCode(ActionReport.ExitCode.FAILURE); return; } ProtocolChainInstanceHandler handler = getHandler(protocol); ProtocolChain chain = getChain(handler); ConfigSupport.apply( new SingleConfigCode<ProtocolChain>() { @Override public Object run(ProtocolChain param) throws PropertyVetoException, TransactionFailure { final List<ProtocolFilter> list = param.getProtocolFilter(); for (ProtocolFilter filter : list) { if (name.equals(filter.getName())) { throw new TransactionFailure( String.format("A protocol filter named %s already exists.", name)); } } final ProtocolFilter filter = param.createChild(ProtocolFilter.class); filter.setName(name); filter.setClassname(classname); list.add(filter); return null; } }, chain); } catch (ValidationFailureException e) { return; } catch (Exception e) { e.printStackTrace(); report.setMessage( localStrings.getLocalString( "create.portunif.fail", "{0} create failed: {1}", name, e.getMessage() == null ? "No reason given" : e.getMessage())); report.setActionExitCode(ActionReport.ExitCode.FAILURE); report.setFailureCause(e); return; } }