From dcc288c8bebe3dae2511c062be29eee86310e18b Mon Sep 17 00:00:00 2001 From: Hugo Trippaers Date: Mon, 13 May 2013 16:53:27 +0200 Subject: [PATCH] Make the classes that get started by jsvc implement Daemon. Set the daemon version centrally in the pom --- agent/pom.xml | 5 +++++ agent/src/com/cloud/agent/AgentShell.java | 19 +++++++++++++++++-- pom.xml | 1 + usage/pom.xml | 2 +- 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/agent/pom.xml b/agent/pom.xml index 0f44c1aa297..c2b1502728f 100644 --- a/agent/pom.xml +++ b/agent/pom.xml @@ -36,6 +36,11 @@ cloud-utils ${project.version} + + commons-daemon + commons-daemon + ${cs.daemon.version} + install diff --git a/agent/src/com/cloud/agent/AgentShell.java b/agent/src/com/cloud/agent/AgentShell.java index 73b3950e7e4..3796f3b1f5f 100644 --- a/agent/src/com/cloud/agent/AgentShell.java +++ b/agent/src/com/cloud/agent/AgentShell.java @@ -38,6 +38,9 @@ import java.util.UUID; import javax.naming.ConfigurationException; +import org.apache.commons.daemon.Daemon; +import org.apache.commons.daemon.DaemonContext; +import org.apache.commons.daemon.DaemonInitException; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; import org.apache.commons.httpclient.methods.GetMethod; @@ -58,7 +61,7 @@ import com.cloud.utils.backoff.impl.ConstantTimeBackoff; import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.script.Script; -public class AgentShell implements IAgentShell { +public class AgentShell implements IAgentShell, Daemon { private static final Logger s_logger = Logger.getLogger(AgentShell.class .getName()); private static final MultiThreadedHttpConnectionManager s_httpClientManager = new MultiThreadedHttpConnectionManager(); @@ -376,7 +379,17 @@ public class AgentShell implements IAgentShell { return true; } - + + @Override + public void init(DaemonContext dc) throws DaemonInitException { + s_logger.debug("Initializing AgentShell from JSVC"); + try { + init(dc.getArguments()); + } catch (ConfigurationException ex) { + throw new DaemonInitException("Initialization failed", ex); + } + } + public void init(String[] args) throws ConfigurationException { // PropertiesUtil is used both in management server and agent packages, @@ -629,6 +642,7 @@ public class AgentShell implements IAgentShell { public static void main(String[] args) { try { + s_logger.debug("Initializing AgentShell from main"); AgentShell shell = new AgentShell(); shell.init(args); shell.start(); @@ -636,4 +650,5 @@ public class AgentShell implements IAgentShell { System.out.println(e.getMessage()); } } + } diff --git a/pom.xml b/pom.xml index e8fdb2f83ea..d7e80d64548 100644 --- a/pom.xml +++ b/pom.xml @@ -84,6 +84,7 @@ build/replace.properties 0.4.9 target + 1.0.10 diff --git a/usage/pom.xml b/usage/pom.xml index 0ad59b4cf70..e35d0ebf485 100644 --- a/usage/pom.xml +++ b/usage/pom.xml @@ -40,7 +40,7 @@ commons-daemon commons-daemon - 1.0.10 + ${cs.daemon.version}