1616// under the License.
1717package com .cloud .servlet ;
1818
19- import java .util . Map ;
19+ import java .io . File ;
2020
2121import javax .servlet .ServletContextEvent ;
2222import javax .servlet .ServletContextListener ;
2323import javax .servlet .ServletException ;
2424import javax .servlet .http .HttpServlet ;
2525
2626import org .apache .log4j .Logger ;
27+ import org .apache .log4j .PropertyConfigurator ;
28+ import org .apache .log4j .xml .DOMConfigurator ;
2729
2830import com .cloud .api .ApiServer ;
2931import com .cloud .exception .InvalidParameterValueException ;
3032import com .cloud .server .ConfigurationServer ;
3133import com .cloud .server .ManagementServer ;
34+ import com .cloud .utils .PropertiesUtil ;
3235import com .cloud .utils .SerialVersionUID ;
3336import com .cloud .utils .component .ComponentContext ;
34- import com .cloud .utils .component .ComponentLocator ;
35- import com .cloud .utils .component .SystemIntegrityChecker ;
36- import com .cloud .utils .db .GenericDaoBase ;
3737
3838public class CloudStartupServlet extends HttpServlet implements ServletContextListener {
3939 public static final Logger s_logger = Logger .getLogger (CloudStartupServlet .class .getName ());
4040
4141 static final long serialVersionUID = SerialVersionUID .CloudStartupServlet ;
4242
43- protected static ComponentLocator s_locator ;
44-
4543 @ Override
4644 public void init () throws ServletException {
47-
48- // Save Configuration Values
45+ initLog4j ();
46+
47+ // Save Configuration Values
4948 ConfigurationServer c = (ConfigurationServer )ComponentContext .getCompanent (ConfigurationServer .class );
5049 try {
5150 c .persistDefaultValues ();
5251 ManagementServer ms = (ManagementServer )ComponentContext .getCompanent (ManagementServer .class );
52+ ms .startup ();
5353 ApiServer .initApiServer (ms .getApiConfig ());
5454 } catch (InvalidParameterValueException ipve ) {
5555 s_logger .error ("Exception starting management server " , ipve );
@@ -73,50 +73,18 @@ public void contextInitialized(ServletContextEvent sce) {
7373 @ Override
7474 public void contextDestroyed (ServletContextEvent sce ) {
7575 }
76-
77- //
78- // following should be moved to CloudStackServer component later to encapsulate business logic in one place
79- //
80- private void initCloudStackComponents () {
81- runCheckers ();
82- startDaos (); // daos should not be using managers and adapters.
83-
84- /*
85- configureManagers();
86- configureAdapters();
87- startManagers();
88- startAdapters();
89- */
90- }
91-
92- private void runCheckers () {
93- Map <String , SystemIntegrityChecker > checkers = ComponentContext .getApplicationContext ().getBeansOfType (
94- SystemIntegrityChecker .class );
95-
96- for (SystemIntegrityChecker checker : checkers .values ()) {
97- try {
98- checker .check ();
99- } catch (Exception e ) {
100- s_logger .error ("Problems with running checker:" + checker .getClass ().getName (), e );
101- System .exit (1 );
102- }
103- }
104- }
105-
106- private void startDaos () {
107- @ SuppressWarnings ("rawtypes" )
108- Map <String , GenericDaoBase > daos = ComponentContext .getApplicationContext ().getBeansOfType (
109- GenericDaoBase .class );
110-
111- for (GenericDaoBase dao : daos .values ()) {
112- try {
113-
114- // dao.configure(dao.getClass().getSimpleName(), params);
115- } catch (Exception e ) {
116- s_logger .error ("Problems with running checker:" + dao .getClass ().getName (), e );
117- System .exit (1 );
118- }
119- }
120- }
12176
77+ private void initLog4j () {
78+ File file = PropertiesUtil .findConfigFile ("log4j-cloud.xml" );
79+ if (file != null ) {
80+ s_logger .info ("log4j configuration found at " + file .getAbsolutePath ());
81+ DOMConfigurator .configureAndWatch (file .getAbsolutePath ());
82+ } else {
83+ file = PropertiesUtil .findConfigFile ("log4j-cloud.properties" );
84+ if (file != null ) {
85+ s_logger .info ("log4j configuration found at " + file .getAbsolutePath ());
86+ PropertyConfigurator .configureAndWatch (file .getAbsolutePath ());
87+ }
88+ }
89+ }
12290}
0 commit comments