List of usage examples for org.apache.commons.daemon DaemonContext getArguments
public String[] getArguments();
String
arguments supplied by the environment. From source file:net.sf.ehcache.server.standalone.Server.java
/** * Invoked by Jsvc with a context which includes the arguments passed to Jsvc. The main() method * also calls through here so that the server can be started using either Jsvc or java -jar... * * @param daemonContext/*w w w . j a v a 2 s . c om*/ * @throws Exception */ public void init(DaemonContext daemonContext) throws Exception { String[] args = daemonContext.getArguments(); if (args.length < 1 || args.length > 2 || (args.length == 1 && args[0].matches("--help"))) { System.out.println("Usage: java -jar ... [http httpPort] warfile | wardir "); System.exit(0); } if (args.length == 1) { war = new File(args[0]); if (!war.exists()) { System.err.println("Error: War file or exploded directory " + war + " does not exist."); System.exit(1); } } if (args.length == 2) { httpPort = Integer.parseInt(args[0]); war = new File(args[1]); if (!war.exists()) { System.err.println("Error: War file or exploded directory " + war + " does not exist."); System.exit(1); } } /* Dump a message */ System.err.println("\nEhcache standalone server initializing..."); /* Set up this simple daemon */ this.controller = daemonContext.getController(); }
From source file:fathom.Boot.java
/** * Called by prunsrv (Windows) or jsvc (UNIX) before start(). * * @param context//w w w . ja v a 2 s . c o m * @throws Exception */ @Override public void init(DaemonContext context) throws Exception { log.debug("Fathom Daemon initialized"); settings.applyArgs(context.getArguments()); }
From source file:com.srotya.tau.api.ApplicationManager.java
@Override public void init(DaemonContext context) throws DaemonInitException, Exception { args = context.getArguments(); }
From source file:aphelion.server.ServerDaemon.java
@Override public void init(DaemonContext dc) throws DaemonInitException, Exception { // At this point we are running as root // Do priviliged stuff like opening a socket port < 1024 String[] args = dc.getArguments(); if (args.length < 1) { throw new IllegalArgumentException("The first argument should be the path to a yaml config file"); }/* w w w .jav a2 s. com*/ Yaml yaml = new Yaml(new SafeConstructor()); // might throw IOException, ClassCastException, etc this.config = (Map<String, Object>) yaml.load(new FileInputStream(args[0])); String address = config.containsKey("bind-address") ? (String) config.get("bind-address") : "0.0.0.0"; int port = config.containsKey("bind-port") ? (int) config.get("bind-port") : 80; InetSocketAddress listen = new InetSocketAddress(address, port); this.ssChannel = HttpServer.openServerChannel(listen); Deadlock.start(false, new Deadlock.DeadlockListener() { @Override public boolean deadlockDetected(TickedEventLoop eventLoop, Thread thread) { return true; // force stop of the offending thread } @Override public void deadlockAfterStop(TickedEventLoop eventLoop, Thread thread) { log.log(Level.INFO, "Exit"); System.exit(EX_SOFTWARE); } }); }
From source file:com.smartmarmot.dbforbix.DBforBix.java
@Override public void init(DaemonContext dc) throws Exception { String[] args = dc.getArguments(); if (args == null || args.length == 0) throw new IllegalStateException("BASEDIR missing"); Config.getInstance().setBasedir(args[0]); }
From source file:com.google.enterprise.adaptor.Daemon.java
@Override public synchronized void init(DaemonContext context) throws Exception { if (this.context != null) { throw new IllegalStateException("Already initialized"); }//from w w w.j av a 2 s. co m this.context = context; String[] args = context.getArguments(); if (args.length < 1) { throw new IllegalArgumentException("Missing argument: adaptor class name"); } Adaptor adaptor = Class.forName(args[0]).asSubclass(Adaptor.class).newInstance(); args = Arrays.copyOfRange(args, 1, args.length); app = Application.daemonMain(adaptor, args); app.daemonInit(); }
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); }//ww w. j a v a 2s . c om if (!this.configure(DEFAULT_CONFIG_FILE)) { throw new DaemonInitException("Error configuring logger with file: " + DEFAULT_CONFIG_FILE); } }
From source file:ca.brood.tunneller.Tunneller.java
@Override public void init(DaemonContext arg) throws DaemonInitException, Exception { /* I think if jsvc is configured correctly, then this method is * called as the root user. After it returns, then start is called * as the regular user./*from ww w . j a v a 2s .com*/ */ //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 source file:SimpleDaemon.java
/** * init and destroy were added in jakarta-tomcat-daemon. */// w w w .j a v a 2s . co m public void init(DaemonContext context) throws Exception { System.err.println("SimpleDaemon: instance " + this.hashCode() + " init"); int port = 1200; String[] a = context.getArguments(); try { if (a.length > 0) port = Integer.parseInt(a[0]); } catch (NumberFormatException ex) { throw new DaemonInitException("parsing port", ex); } if (a.length > 1) this.directory = a[1]; else this.directory = "/tmp"; /* Dump a message */ System.err.println("SimpleDaemon: loading on port " + port); /* Set up this simple daemon */ this.controller = context.getController(); this.server = new ServerSocket(port); this.thread = new Thread(this); }
From source file:catalina.startup.BootstrapService.java
/** * Load the Catalina Service./*from w w w. j a v a2 s .c o m*/ */ public void init(DaemonContext context) throws Exception { String arguments[] = null; /* Read the arguments from the Daemon context */ if (context != null) { arguments = context.getArguments(); if (arguments != null) { for (int i = 0; i < arguments.length; i++) { if (arguments[i].equals("-debug")) { debug = 1; } } } } log("Create Catalina server"); // Set Catalina path setCatalinaHome(); setCatalinaBase(); // Construct the class loaders we will need ClassLoader commonLoader = null; ClassLoader catalinaLoader = null; ClassLoader sharedLoader = null; try { File unpacked[] = new File[1]; File packed[] = new File[1]; File packed2[] = new File[2]; ClassLoaderFactory.setDebug(debug); unpacked[0] = new File(getCatalinaHome(), "common" + File.separator + "classes"); packed2[0] = new File(getCatalinaHome(), "common" + File.separator + "endorsed"); packed2[1] = new File(getCatalinaHome(), "common" + File.separator + "lib"); commonLoader = ClassLoaderFactory.createClassLoader(unpacked, packed2, null); unpacked[0] = new File(getCatalinaHome(), "server" + File.separator + "classes"); packed[0] = new File(getCatalinaHome(), "server" + File.separator + "lib"); catalinaLoader = ClassLoaderFactory.createClassLoader(unpacked, packed, commonLoader); System.err.println("Created catalinaLoader in: " + getCatalinaHome() + File.separator + "server" + File.separator + "lib"); unpacked[0] = new File(getCatalinaBase(), "shared" + File.separator + "classes"); packed[0] = new File(getCatalinaBase(), "shared" + File.separator + "lib"); sharedLoader = ClassLoaderFactory.createClassLoader(unpacked, packed, commonLoader); } catch (Throwable t) { log("Class loader creation threw exception", t); } Thread.currentThread().setContextClassLoader(catalinaLoader); SecurityClassLoad.securityClassLoad(catalinaLoader); // Load our startup class and call its process() method if (debug >= 1) log("Loading startup class"); Class startupClass = catalinaLoader.loadClass("org.apache.catalina.startup.CatalinaService"); Object startupInstance = startupClass.newInstance(); // Set the shared extensions class loader if (debug >= 1) log("Setting startup class properties"); String methodName = "setParentClassLoader"; Class paramTypes[] = new Class[1]; paramTypes[0] = Class.forName("java.lang.ClassLoader"); Object paramValues[] = new Object[1]; paramValues[0] = sharedLoader; Method method = startupInstance.getClass().getMethod(methodName, paramTypes); method.invoke(startupInstance, paramValues); catalinaService = startupInstance; // Call the load() method methodName = "load"; Object param[]; if (arguments == null || arguments.length == 0) { paramTypes = null; param = null; } else { paramTypes[0] = arguments.getClass(); param = new Object[1]; param[0] = arguments; } method = catalinaService.getClass().getMethod(methodName, paramTypes); if (debug >= 1) log("Calling startup class " + method); method.invoke(catalinaService, param); }