1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.common.deploy.appserver;
17
18 import java.util.List;
19 import java.util.Properties;
20
21 import org.kuali.common.deploy.DeployUtils;
22 import org.kuali.common.deploy.Deployable;
23 import org.kuali.common.util.FormatUtils;
24 import org.kuali.common.util.PropertyUtils;
25 import org.kuali.common.util.execute.Executable;
26 import org.kuali.common.util.log.LoggerLevel;
27 import org.kuali.common.util.secure.channel.Result;
28 import org.kuali.common.util.secure.channel.SecureChannel;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31
32 public class TomcatApplicationServer implements ApplicationServer {
33
34 private static final Logger logger = LoggerFactory.getLogger(TomcatApplicationServer.class);
35
36 SecureChannel channel;
37 boolean validateShutdownExitValue = false;
38 String username;
39 String group;
40 String shutdown;
41 String startup;
42
43 List<String> pathsToDelete;
44
45 List<String> dirsToCreate;
46
47 List<String> pathsToChown;
48
49 List<Deployable> deployables;
50
51 Properties filterProperties;
52
53 boolean skipFiles;
54
55 Executable httpWait;
56
57 @Override
58 public void stop() {
59 long start = System.currentTimeMillis();
60 logger.info("[tomcat:stopping]");
61 Result result = DeployUtils.runscript(channel, username, shutdown, false);
62 if (result.getExitValue() != 0) {
63 DeployUtils.logResult(result, logger, LoggerLevel.WARN);
64 }
65 logger.info("[tomcat:stopped] - {}", FormatUtils.getTime(System.currentTimeMillis() - start));
66 }
67
68 @Override
69 public void prepare() {
70 long start = System.currentTimeMillis();
71 logger.info("[tomcat:preparing]");
72
73 DeployUtils.delete(channel, pathsToDelete);
74
75 DeployUtils.mkdirs(channel, dirsToCreate);
76
77 if (!skipFiles) {
78
79
80 Properties properties = PropertyUtils.getGlobalProperties(filterProperties);
81 DeployUtils.copyFiles(channel, deployables, properties);
82 }
83
84 DeployUtils.chown(channel, username, group, pathsToChown);
85 logger.info("[tomcat:prepared] - {}", FormatUtils.getTime(System.currentTimeMillis() - start));
86 }
87
88 @Override
89 public void start() {
90 long start = System.currentTimeMillis();
91 logger.info("[tomcat:start]");
92 DeployUtils.runscript(channel, username, startup);
93 httpWait.execute();
94 logger.info("[tomcat:started] - {}", FormatUtils.getTime(System.currentTimeMillis() - start));
95 }
96
97 public boolean isValidateShutdownExitValue() {
98 return validateShutdownExitValue;
99 }
100
101 public void setValidateShutdownExitValue(boolean validateShutdownExitValue) {
102 this.validateShutdownExitValue = validateShutdownExitValue;
103 }
104
105 public SecureChannel getChannel() {
106 return channel;
107 }
108
109 public void setChannel(SecureChannel channel) {
110 this.channel = channel;
111 }
112
113 public String getUsername() {
114 return username;
115 }
116
117 public void setUsername(String username) {
118 this.username = username;
119 }
120
121 public String getShutdown() {
122 return shutdown;
123 }
124
125 public void setShutdown(String shutdown) {
126 this.shutdown = shutdown;
127 }
128
129 public String getStartup() {
130 return startup;
131 }
132
133 public void setStartup(String startup) {
134 this.startup = startup;
135 }
136
137 public String getGroup() {
138 return group;
139 }
140
141 public void setGroup(String group) {
142 this.group = group;
143 }
144
145 public List<String> getPathsToDelete() {
146 return pathsToDelete;
147 }
148
149 public void setPathsToDelete(List<String> pathsToDelete) {
150 this.pathsToDelete = pathsToDelete;
151 }
152
153 public List<String> getDirsToCreate() {
154 return dirsToCreate;
155 }
156
157 public void setDirsToCreate(List<String> dirsToCreate) {
158 this.dirsToCreate = dirsToCreate;
159 }
160
161 public List<String> getPathsToChown() {
162 return pathsToChown;
163 }
164
165 public void setPathsToChown(List<String> pathsToChown) {
166 this.pathsToChown = pathsToChown;
167 }
168
169 public List<Deployable> getDeployables() {
170 return deployables;
171 }
172
173 public void setDeployables(List<Deployable> deployables) {
174 this.deployables = deployables;
175 }
176
177 public boolean isSkipFiles() {
178 return skipFiles;
179 }
180
181 public void setSkipFiles(boolean skipFiles) {
182 this.skipFiles = skipFiles;
183 }
184
185 public Properties getFilterProperties() {
186 return filterProperties;
187 }
188
189 public void setFilterProperties(Properties filterProperties) {
190 this.filterProperties = filterProperties;
191 }
192
193 public Executable getHttpWait() {
194 return httpWait;
195 }
196
197 public void setHttpWait(Executable httpWait) {
198 this.httpWait = httpWait;
199 }
200
201 }