Skip to content

Commit dcc288c

Browse files
committed
Make the classes that get started by jsvc implement Daemon.
Set the daemon version centrally in the pom
1 parent c211818 commit dcc288c

4 files changed

Lines changed: 24 additions & 3 deletions

File tree

agent/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@
3636
<artifactId>cloud-utils</artifactId>
3737
<version>${project.version}</version>
3838
</dependency>
39+
<dependency>
40+
<groupId>commons-daemon</groupId>
41+
<artifactId>commons-daemon</artifactId>
42+
<version>${cs.daemon.version}</version>
43+
</dependency>
3944
</dependencies>
4045
<build>
4146
<defaultGoal>install</defaultGoal>

agent/src/com/cloud/agent/AgentShell.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838

3939
import javax.naming.ConfigurationException;
4040

41+
import org.apache.commons.daemon.Daemon;
42+
import org.apache.commons.daemon.DaemonContext;
43+
import org.apache.commons.daemon.DaemonInitException;
4144
import org.apache.commons.httpclient.HttpClient;
4245
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
4346
import org.apache.commons.httpclient.methods.GetMethod;
@@ -58,7 +61,7 @@
5861
import com.cloud.utils.exception.CloudRuntimeException;
5962
import com.cloud.utils.script.Script;
6063

61-
public class AgentShell implements IAgentShell {
64+
public class AgentShell implements IAgentShell, Daemon {
6265
private static final Logger s_logger = Logger.getLogger(AgentShell.class
6366
.getName());
6467
private static final MultiThreadedHttpConnectionManager s_httpClientManager = new MultiThreadedHttpConnectionManager();
@@ -376,7 +379,17 @@ protected boolean parseCommand(final String[] args)
376379

377380
return true;
378381
}
379-
382+
383+
@Override
384+
public void init(DaemonContext dc) throws DaemonInitException {
385+
s_logger.debug("Initializing AgentShell from JSVC");
386+
try {
387+
init(dc.getArguments());
388+
} catch (ConfigurationException ex) {
389+
throw new DaemonInitException("Initialization failed", ex);
390+
}
391+
}
392+
380393
public void init(String[] args) throws ConfigurationException {
381394

382395
// PropertiesUtil is used both in management server and agent packages,
@@ -629,11 +642,13 @@ public void destroy() {
629642

630643
public static void main(String[] args) {
631644
try {
645+
s_logger.debug("Initializing AgentShell from main");
632646
AgentShell shell = new AgentShell();
633647
shell.init(args);
634648
shell.start();
635649
} catch (ConfigurationException e) {
636650
System.out.println(e.getMessage());
637651
}
638652
}
653+
639654
}

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
<cs.replace.properties>build/replace.properties</cs.replace.properties>
8585
<cs.libvirt-java.version>0.4.9</cs.libvirt-java.version>
8686
<cs.target.dir>target</cs.target.dir>
87+
<cs.daemon.version>1.0.10</cs.daemon.version>
8788
</properties>
8889

8990
<distributionManagement>

usage/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
<dependency>
4141
<groupId>commons-daemon</groupId>
4242
<artifactId>commons-daemon</artifactId>
43-
<version>1.0.10</version>
43+
<version>${cs.daemon.version}</version>
4444
</dependency>
4545
</dependencies>
4646
<build>

0 commit comments

Comments
 (0)