|
38 | 38 |
|
39 | 39 | import javax.naming.ConfigurationException; |
40 | 40 |
|
| 41 | +import org.apache.commons.daemon.Daemon; |
| 42 | +import org.apache.commons.daemon.DaemonContext; |
| 43 | +import org.apache.commons.daemon.DaemonInitException; |
41 | 44 | import org.apache.commons.httpclient.HttpClient; |
42 | 45 | import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; |
43 | 46 | import org.apache.commons.httpclient.methods.GetMethod; |
|
58 | 61 | import com.cloud.utils.exception.CloudRuntimeException; |
59 | 62 | import com.cloud.utils.script.Script; |
60 | 63 |
|
61 | | -public class AgentShell implements IAgentShell { |
| 64 | +public class AgentShell implements IAgentShell, Daemon { |
62 | 65 | private static final Logger s_logger = Logger.getLogger(AgentShell.class |
63 | 66 | .getName()); |
64 | 67 | private static final MultiThreadedHttpConnectionManager s_httpClientManager = new MultiThreadedHttpConnectionManager(); |
@@ -376,7 +379,17 @@ protected boolean parseCommand(final String[] args) |
376 | 379 |
|
377 | 380 | return true; |
378 | 381 | } |
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 | + |
380 | 393 | public void init(String[] args) throws ConfigurationException { |
381 | 394 |
|
382 | 395 | // PropertiesUtil is used both in management server and agent packages, |
@@ -629,11 +642,13 @@ public void destroy() { |
629 | 642 |
|
630 | 643 | public static void main(String[] args) { |
631 | 644 | try { |
| 645 | + s_logger.debug("Initializing AgentShell from main"); |
632 | 646 | AgentShell shell = new AgentShell(); |
633 | 647 | shell.init(args); |
634 | 648 | shell.start(); |
635 | 649 | } catch (ConfigurationException e) { |
636 | 650 | System.out.println(e.getMessage()); |
637 | 651 | } |
638 | 652 | } |
| 653 | + |
639 | 654 | } |
0 commit comments