001
014
015 package com.liferay.portal.events;
016
017 import com.liferay.portal.jericho.CachedLoggerProvider;
018 import com.liferay.portal.kernel.bean.PortalBeanLocatorUtil;
019 import com.liferay.portal.kernel.cluster.ClusterExecutorUtil;
020 import com.liferay.portal.kernel.events.ActionException;
021 import com.liferay.portal.kernel.events.SimpleAction;
022 import com.liferay.portal.kernel.freemarker.FreeMarkerEngineUtil;
023 import com.liferay.portal.kernel.log.Log;
024 import com.liferay.portal.kernel.log.LogFactoryUtil;
025 import com.liferay.portal.kernel.messaging.MessageBus;
026 import com.liferay.portal.kernel.messaging.MessageBusUtil;
027 import com.liferay.portal.kernel.messaging.sender.MessageSender;
028 import com.liferay.portal.kernel.messaging.sender.SynchronousMessageSender;
029 import com.liferay.portal.kernel.scheduler.SchedulerEngineUtil;
030 import com.liferay.portal.kernel.search.IndexerRegistryUtil;
031 import com.liferay.portal.kernel.servlet.JspFactorySwapper;
032 import com.liferay.portal.kernel.util.ReleaseInfo;
033 import com.liferay.portal.kernel.util.ServerDetector;
034 import com.liferay.portal.kernel.velocity.VelocityEngineUtil;
035 import com.liferay.portal.plugin.PluginPackageIndexer;
036 import com.liferay.portal.security.lang.PortalSecurityManager;
037 import com.liferay.portal.service.LockLocalServiceUtil;
038 import com.liferay.portal.tools.DBUpgrader;
039 import com.liferay.portal.util.PropsValues;
040 import com.liferay.portlet.messageboards.util.MBIndexer;
041
042
047 public class StartupAction extends SimpleAction {
048
049 @Override
050 public void run(String[] ids) throws ActionException {
051 try {
052 doRun(ids);
053 }
054 catch (RuntimeException re) {
055 throw re;
056 }
057 catch (Exception e) {
058 throw new ActionException(e);
059 }
060 }
061
062 protected void doRun(String[] ids) throws Exception {
063
064
065
066 System.out.println("Starting " + ReleaseInfo.getReleaseInfo());
067
068
069
070 if (_log.isDebugEnabled()) {
071 _log.debug("Clear locks");
072 }
073
074 try {
075 LockLocalServiceUtil.clear();
076 }
077 catch (Exception e) {
078 if (_log.isWarnEnabled()) {
079 _log.warn(
080 "Unable to clear locks because Lock table does not exist");
081 }
082 }
083
084
085
086 if (_log.isDebugEnabled()) {
087 _log.debug("Add shutdown hook");
088 }
089
090 Runtime runtime = Runtime.getRuntime();
091
092 runtime.addShutdownHook(new Thread(new ShutdownHook()));
093
094
095
096 String portalSecurityManagerStrategy =
097 PropsValues.PORTAL_SECURITY_MANAGER_STRATEGY;
098
099 if (portalSecurityManagerStrategy.equals("smart")) {
100 if (ServerDetector.isWebSphere()) {
101 portalSecurityManagerStrategy = "none";
102 }
103 else {
104 portalSecurityManagerStrategy = "default";
105 }
106 }
107
108 if (portalSecurityManagerStrategy.equals("liferay")) {
109 if (System.getSecurityManager() == null) {
110 System.setSecurityManager(new PortalSecurityManager());
111 }
112 }
113 else if (portalSecurityManagerStrategy.equals("none")) {
114 System.setSecurityManager(null);
115 }
116
117
118
119 if (_log.isDebugEnabled()) {
120 _log.debug("Initialize FreeMarker engine");
121 }
122
123 FreeMarkerEngineUtil.init();
124
125
126
127 if (_log.isDebugEnabled()) {
128 _log.debug("Initialize Velocity engine");
129 }
130
131 VelocityEngineUtil.init();
132
133
134
135 IndexerRegistryUtil.register(new MBIndexer());
136 IndexerRegistryUtil.register(new PluginPackageIndexer());
137
138
139
140 if (_log.isDebugEnabled()) {
141 _log.debug("Upgrade database");
142 }
143
144 DBUpgrader.upgrade();
145
146
147
148 if (_log.isDebugEnabled()) {
149 _log.debug("Initialize message bus");
150 }
151
152 MessageBus messageBus = (MessageBus)PortalBeanLocatorUtil.locate(
153 MessageBus.class.getName());
154 MessageSender messageSender =
155 (MessageSender)PortalBeanLocatorUtil.locate(
156 MessageSender.class.getName());
157 SynchronousMessageSender synchronousMessageSender =
158 (SynchronousMessageSender)PortalBeanLocatorUtil.locate(
159 SynchronousMessageSender.class.getName());
160
161 MessageBusUtil.init(
162 messageBus, messageSender, synchronousMessageSender);
163
164
165
166 ClusterExecutorUtil.initialize();
167
168
169
170 if (_log.isDebugEnabled()) {
171 _log.debug("Initialize scheduler engine lifecycle");
172 }
173
174 SchedulerEngineUtil.initialize();
175
176
177
178 if (_log.isDebugEnabled()) {
179 _log.debug("Verify database");
180 }
181
182 DBUpgrader.verify();
183
184
185
186 JspFactorySwapper.swap();
187
188
189
190 CachedLoggerProvider.install();
191 }
192
193 private static Log _log = LogFactoryUtil.getLog(StartupAction.class);
194
195 }