List of usage examples for org.apache.commons.daemon DaemonInitException DaemonInitException
public DaemonInitException(String message)
From source file:fi.ilmoeuro.membertrack.elock.ElockDaemon.java
public void init(String... args) throws DaemonInitException, Exception { final ElockSystemParameters params = new ElockSystemParameters(); final CmdLineParser argParser = new CmdLineParser(params); try {/* w w w .ja v a2 s .c om*/ argParser.parseArgument(args); params.validate(); system = new ElockSystem(params); } catch (CmdLineException | InvalidArgumentsException | InitializationException ex) { throw new DaemonInitException(String.format("%s%nusage: membertrack-elock [options]%n%s", ex.getMessage(), getUsage(argParser))); } }
From source file:com.devti.JavaXMPPBot.JavaXMPPBot.java
@Override public void init(DaemonContext context) throws DaemonInitException, Exception { // Get paths/*w w w .ja va2 s.c o m*/ String[] args = context.getArguments(); Path configsDir, logsDir; if (args.length > 0) { configsDir = Paths.get(args[0]); } else { configsDir = Paths.get(System.getProperty("user.home"), "JavaXMPPBot", "conf.d"); } if (args.length > 1) { logsDir = Paths.get(args[1]); } else { logsDir = Paths.get(System.getProperty("user.home"), "JavaXMPPBot", "log.d"); } if (!logsDir.toFile().exists()) { throw new DaemonInitException("Logs directory '" + logsDir + "' doesn't exist."); } // Get bot configs List<Path> botConfigs = new ArrayList<>(); try (DirectoryStream<Path> stream = Files.newDirectoryStream(configsDir, "*.conf")) { for (Path entry : stream) { botConfigs.add(entry); } } catch (DirectoryIteratorException e) { throw new DaemonInitException( "Can't list configs directory '" + configsDir + "': " + e.getLocalizedMessage()); } if (botConfigs.size() <= 0) { throw new DaemonInitException("There is no .conf files in '" + configsDir + "' directory."); } // Load bots for (Path config : botConfigs) { String id = config.getFileName().toString().replaceFirst(".conf$", ""); Path log = Paths.get(logsDir.toString(), id + ".log"); try { bots.add(new XMPPBot(id, config, new Log(log))); } catch (Exception e) { throw new DaemonInitException( "Can't load a bot with config file '" + config + "': " + e.getLocalizedMessage()); } } }
From source file:com.envirover.spl.SPLDaemon.java
@Override public void init(DaemonContext context) throws DaemonInitException, Exception { if (!config.init(context.getArguments())) throw new DaemonInitException("Invalid configuration."); ClassLoader loader = SPLDaemon.class.getClassLoader(); InputStream params = loader.getResourceAsStream(DEFAULT_PARAMS_FILE); if (params != null) { MAVLinkShadow.getInstance().loadParams(params); params.close();// w w w . ja v a2s . c om } else { logger.warn("File 'default.params' with initial parameters values not found."); } MAVLinkMessageQueue mtMessageQueue = new MAVLinkMessageQueue(config.getQueueSize()); tcpServer = new MAVLinkTcpServer(config.getMAVLinkPort(), mtMessageQueue); MAVLinkMessageQueue moMessageQueue = new MAVLinkMessageQueue(config.getQueueSize()); MOMessageHandler moHandler = new MOMessageHandler(moMessageQueue); httpServer = HttpServer.create(new InetSocketAddress(config.getRockblockPort()), 0); httpServer.createContext(config.getHttpContext(), new RockBlockHttpHandler(moHandler, config.getRockBlockIMEI())); httpServer.setExecutor(null); // TODO: Broadcast MO messages to all the connected clients. RockBlockClient rockblock = new RockBlockClient(config.getRockBlockIMEI(), config.getRockBlockUsername(), config.getRockBlockPassword(), config.getRockBlockURL()); MTMessagePump mtMsgPump = new MTMessagePump(mtMessageQueue, rockblock); mtMsgPumpThread = new Thread(mtMsgPump, "mt-message-pump"); WSEndpoint.setMTQueue(mtMessageQueue); wsServer = new Server("localhost", config.getWSPort(), "/gcs", WSEndpoint.class); }
From source file:com.msp.jsvc.JRubyDaemon.java
private void loadScript() throws DaemonInitException { if (debug)/* ww w. ja v a 2s .c om*/ log("Executing script from: " + rubyConfig.getScriptFileName()); // boot her up. The script should yield control back to us so we // can give control back to jsvc once try { runtime.runFromMain(rubyConfig.getScriptSource(), rubyConfig.getScriptFileName()); } catch (RaiseException e) { RubyException re = e.getException(); if (re.getType().getName().equals("JSVC::DaemonInitError")) { throw new DaemonInitException(re.message.toString()); } else { log("Script raised an error: " + e); throw e; } } catch (RuntimeException e) { log("Error executing script: " + e); throw e; } appModule = runtime.getModule(appModuleName); if (appModule == null) { throw new RuntimeException("Couldn't get module '" + appModuleName + "' from JRuby runtime"); } daemon = (RubyModule) appModule.getConstantAt(DAEMON); if (daemon == null) { throw new RuntimeException("Couldn't get " + DAEMON + " module from " + appModuleName); } }
From source file:com.cws.esolutions.agent.AgentDaemon.java
public void init(final DaemonContext dContext) throws DaemonInitException { final String methodName = AgentDaemon.CNAME + "#init(final DaemonContext dContext) throws DaemonInitException"; if (DEBUG) {//www . j a v a 2s . co m DEBUGGER.debug(methodName); DEBUGGER.debug("DaemonContext: {}", dContext); } JAXBContext context = null; Unmarshaller marshaller = null; final File xmlFile = new File( AgentConstants.CURRENT_DIRECTORY + System.getProperty(AgentDaemon.APP_CONFIG)); if (DEBUG) { DEBUGGER.debug("xmlFile: {}", xmlFile); } try { if (!(xmlFile.canRead())) { throw new DaemonInitException("No configuration file was located. Shutting down !"); } // set the app configuration context = JAXBContext.newInstance(ConfigurationData.class); marshaller = context.createUnmarshaller(); ConfigurationData configData = (ConfigurationData) marshaller.unmarshal(xmlFile); if (DEBUG) { DEBUGGER.debug("ConfigurationData: {}", configData); } String osName = System.getProperty("os.name").toLowerCase(); if (DEBUG) { DEBUGGER.debug("osName: {}", osName); } if (osName.indexOf("win") >= 0) { AgentDaemon.agentBean.setOsType(OSType.WINDOWS); } else if (osName.indexOf("mac") >= 0) { AgentDaemon.agentBean.setOsType(OSType.MAC); } else if ((osName.indexOf("nix") >= 0) || (osName.indexOf("sunos") >= 0) || (osName.indexOf("aix") >= 0)) { AgentDaemon.agentBean.setOsType(OSType.UNIX); } AgentDaemon.agentBean.setHostName(InetAddress.getLocalHost().getHostName()); AgentDaemon.agentBean.setConfigData(configData); } catch (JAXBException jx) { ERROR_RECORDER.error(jx.getMessage(), jx); this.exitCode = 1; stop(); } catch (UnknownHostException uhx) { ERROR_RECORDER.error(uhx.getMessage(), uhx); this.exitCode = 1; stop(); } }
From source file:ca.brood.softlogger.Softlogger.java
@Override public void init(DaemonContext arg) throws DaemonInitException, Exception { //TODO: get an xml config file from the command line log.info("Linux daemon received init"); for (String s : arg.getArguments()) { log.debug("Got argument: " + s); }/*from ww w . java 2s .c o m*/ if (!this.configure(DEFAULT_CONFIG_FILE)) { throw new DaemonInitException("Error configuring logger with file: " + DEFAULT_CONFIG_FILE); } }
From source file:org.codekaizen.daemon.play.PlayDaemon.java
@Override public void init(final DaemonContext context) throws DaemonInitException { if (context.getArguments() != null) { args = context.getArguments();/* w w w . j ava 2 s . co m*/ } if (args.length > 0) { applicationHome = new File(args[0]); } if (args.length > 1) { final String port = args[1]; if (DISABLED.equals(port)) { httpPort = Option.empty(); } else { try { httpPort = Option.apply((Object) Integer.valueOf(port)); } catch (final NumberFormatException cause) { throw new DaemonInitException("specified port [" + port + "] is invalid"); } } } if (args.length > 2) { final String port = args[2]; if (DISABLED.equals(port)) { httpsPort = Option.empty(); } else { try { httpsPort = Option.apply((Object) Integer.valueOf(port)); } catch (final NumberFormatException cause) { throw new DaemonInitException("specified port [" + port + "] is invalid"); } } } if (args.length > 3) { address = args[3]; } if (!applicationHome.isDirectory()) { throw new DaemonInitException( "specified application home [" + applicationHome + "] is not a directory"); } }
From source file:org.iobserve.analysis.service.AnalysisDaemon.java
@Override public void init(final DaemonContext context) throws DaemonInitException, MalformedURLException { final String[] args = context.getArguments(); final CommandLineParser parser = new DefaultParser(); try {//from w ww.ja v a 2s . c o m CommandLine commandLine = parser.parse(AnalysisDaemon.createHelpOptions(), args); if (commandLine.hasOption("h")) { final HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("iobserve-service", AnalysisDaemon.createOptions()); } else { commandLine = parser.parse(AnalysisDaemon.createOptions(), args); /** get configuration parameter. */ final int listenPort = Integer.parseInt(commandLine.getOptionValue("i")); final String outputHostname = commandLine.getOptionValues("o")[0]; final String outputPort = commandLine.getOptionValues("o")[1]; final File pcmModelsDirectory = new File(commandLine.getOptionValue("p")); final int varianceOfUserGroups = Integer .parseInt(commandLine.getOptionValue(AnalysisDaemon.VARIANCE_OF_USER_GROUPS)); final int thinkTime = Integer.parseInt(commandLine.getOptionValue(AnalysisDaemon.THINK_TIME)); final boolean closedWorkload = commandLine.hasOption(AnalysisDaemon.CLOSED_WORKLOAD); final String systemId = commandLine.getOptionValue("s"); /** process parameter. */ if (pcmModelsDirectory.exists()) { if (pcmModelsDirectory.isDirectory()) { final InitializeModelProviders modelProvider = new InitializeModelProviders( pcmModelsDirectory); final ICorrespondence correspondenceModel = modelProvider.getCorrespondenceModel(); final UsageModelProvider usageModelProvider = modelProvider.getUsageModelProvider(); final RepositoryModelProvider repositoryModelProvider = modelProvider .getRepositoryModelProvider(); final ResourceEnvironmentModelProvider resourceEvnironmentModelProvider = modelProvider .getResourceEnvironmentModelProvider(); final AllocationModelProvider allocationModelProvider = modelProvider .getAllocationModelProvider(); final SystemModelProvider systemModelProvider = modelProvider.getSystemModelProvider(); final Configuration configuration = new ServiceConfiguration(listenPort, outputHostname, outputPort, systemId, varianceOfUserGroups, thinkTime, closedWorkload, correspondenceModel, usageModelProvider, repositoryModelProvider, resourceEvnironmentModelProvider, allocationModelProvider, systemModelProvider); this.thread = new AnalysisThread(this, configuration); } else { throw new DaemonInitException("CLI error: PCM directory " + pcmModelsDirectory.getPath() + " is not a directory."); } } else { throw new DaemonInitException( "CLI error: PCM directory " + pcmModelsDirectory.getPath() + " does not exist."); } } } catch (final ParseException exp) { final HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("iobserve-analysis", AnalysisDaemon.createOptions()); throw new DaemonInitException("CLI error: " + exp.getMessage()); } }