List of usage examples for org.apache.commons.daemon DaemonContext getArguments
public String[] getArguments();
String
arguments supplied by the environment. From source file:org.jcronjob.agent.AgentBootstrap.java
/** * init start......../* w w w .j a v a 2 s .com*/ * * @param context * @throws Exception */ @Override public void init(DaemonContext context) throws Exception { String[] args = context.getArguments(); Options options = new Options(); options.addOption("port", "port", true, "start port"); options.addOption("pass", "password", true, "input password!"); CommandLineParser parser = new BasicParser(); CommandLine cmd = parser.parse(options, args); port = Integer.valueOf(Integer.parseInt(cmd.getOptionValue("port").toString())); String inputPwd = cmd.getOptionValue("pass"); File passfile = new File(System.getProperty("cronjob.home")); if (!passfile.exists()) { passfile.mkdirs(); } passfile = new File(passfile.getAbsolutePath() + File.separator + ".password"); if (notEmpty(inputPwd)) { this.password = DigestUtils.md5Hex(inputPwd).toLowerCase(); passfile.delete(); IOUtils.writeFile(passfile, this.password, CHARSET); } else { if (!passfile.exists()) { this.password = DigestUtils.md5Hex(this.password).toLowerCase(); IOUtils.writeFile(passfile, this.password, CHARSET); } else { password = IOUtils.readFile(passfile, CHARSET).trim().toLowerCase(); } } }
From source file:org.mortbay.jetty.start.daemon.Bootstrap.java
public void init(DaemonContext context) { main.init(context.getArguments()); }
From source file:org.nodel.nodelhost.Service.java
/** * On initialisation (or pre-start), captures the process args. *//*w ww . ja v a 2 s .c o m*/ @Override public void init(DaemonContext context) throws DaemonInitException, Exception { _context = context; _processArgs = context.getArguments(); }
From source file:org.onebusaway.siri.repeater.SiriRepeaterDaemon.java
@Override public void init(DaemonContext context) throws DaemonInitException, Exception { String[] args = context.getArguments(); SiriRepeaterCommandLineConfiguration config = new SiriRepeaterCommandLineConfiguration(); Injector injector = config.configure(args); _lifecycleService = injector.getInstance(LifecycleService.class); }
From source file:org.xenmaster.App.java
@Override public void init(DaemonContext context) throws DaemonInitException, Exception { Logger root = Logger.getRootLogger(); root.setLevel(Level.INFO);/*from w ww. j a va 2s . com*/ root.addAppender(new ConsoleAppender(new EnhancedPatternLayout(CONSOLE_LOGPATTERN))); if (context != null) { Logger.getLogger(getClass()).info("Starting XenMaster service"); if (context.getArguments() != null && context.getArguments()[0] != null) { Settings.loadFromFile(context.getArguments()[0]); } } // Reconfigure logging with correct settings root.setLevel(Level.toLevel(Settings.getInstance().getString("Logging.Level"))); if (Settings.getInstance().keyExists("Logging.File")) { root.addAppender(new DailyRollingFileAppender(new EnhancedPatternLayout(FILE_LOGPATTERN), Settings.getInstance().getString("Logging.File"), "'.'yyyy-MM-dd")); } if (context == null) { Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { @Override public void run() { try { stop(); } catch (Exception ex) { Logger.getLogger(App.class).error("Failed to shut down", ex); } } })); } }
From source file:quarks.freeautomaticbridg.CommunicationServer.java
@Override public void init(DaemonContext dc) throws DaemonInitException, Exception { config = new Properties(); config.load(new FileInputStream(dc.getArguments()[0])); PropertyConfigurator.configure(config); log.info("Start as Programm"); CommunicationServer server = new CommunicationServer(); server.startServer(666);/*w ww . j a v a 2 s. co m*/ }
From source file:ua.com.kerriline.location.daemon.SpringBootDaemon.java
public void init(DaemonContext context) throws Exception { System.out.println("Daemon initialized with arguments [" + Arrays.toString(context.getArguments()) + "]"); // TODO/*from w w w . j a v a 2 s.com*/ this.springBootApp = ClassUtils.resolveClassName(context.getArguments()[0], null); }
From source file:uk.co.unitycoders.pircbotx.BotService.java
@Override public void init(DaemonContext daemonContext) throws Exception { String[] args = daemonContext.getArguments(); String configPath = ConfigurationManager.JSON_FILE_NAME; if (args.length != 0) { configPath = args[0];/* ww w . j a v a 2s . co m*/ } botThread = new Thread(new BotRunnable(ConfigurationManager.loadConfig(configPath))); }
From source file:yatftps.Yatftps.java
/** * main method listen to 69 port UDP./*from w ww. ja v a2s .c o m*/ * After receiving connection creates new thread for processing request. * @param args the command line arguments */ //public static void main(String[] args) { @Override public void init(DaemonContext daemonContext) throws DaemonInitException, Exception { String[] args = daemonContext.getArguments(); LogWriter.readConfig(); log = LogWriter.getLogger(); Config cfg; /* * Accordingly RFC 1350 the data field is from zero to 512 bytes long. https://tools.ietf.org/html/rfc1350 * Respectively (Data Field) + (Block Field) + (Opcode Field) = 512 + 2 + 2 = 516 bytes */ datagramLength = 516; /* * Reading config file and getting application settings */ cfg = Config.getConfig(); /* * Checking for start arguments */ if (args.length >= 1) { for (String s : args) { switch (s) { case "--debug": LogWriter.setDebug(true); break; case "--check-config": Config.checkConfig(); System.exit(0); } } } yatftpsThread = new Thread() { @Override public synchronized void start() { Yatftps.this.stopped = false; super.start(); } @Override public void run() { while (!stopped) { log.info("Server started"); // trying to listen port 69 try (DatagramSocket socket = new DatagramSocket(69)) { // receive first packet from client DatagramPacket datapacket = new DatagramPacket(new byte[datagramLength], 0, datagramLength); socket.receive(datapacket); // create new thread for handling TFTP request TftpHandler tftphandler = new TftpHandler(socket, datapacket); Thread thread = new Thread(tftphandler); thread.setDaemon(true); thread.start(); } catch (SocketException e) { log.severe( "SocketException: socket could not be opened, or the socket could not bind to the specified local port. " + e); log.info("Exiting"); System.exit(1); } catch (SecurityException e) { log.severe( "SecurityException: security manager exists and its checkListen method doesn't allow the operation " + e); log.info("Exiting"); System.exit(1); } catch (IOException e) { log.info("I/O error occurs" + e); } } } }; }