deployer-script.xml
9.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
<?xml version="1.0" encoding="UTF-8"?>
<project basedir="." default="help" name="Deployer">
<!-- @author m.veroni
@version 1.1
@release 02/05/2013 -->
<target name="help">
<echo message="Help" />
<echo message=" " />
<echo message="uploadAndDeploy Esegue la copia remota del file e il deploy sui nodi specificati" />
<echo message="copySftp Esegue la copia di un file su un server remoto" />
<echo message="deploy Esegue il deploy sui nodi specificati" />
<echo message="refresh Esegue un refresh di Eclipse" />
<echo message=" " />
<echo message="Lanciare i target senza parametri per scoprire quelli obbligatori" />
</target>
<target name="remote.exec">
<echo message="Esegue comando ssh: ${command}" />
<if>
<not>
<isset property="public.key"/>
</not>
<then>
<sshexec password="${remote.password}" username="${remote.username}" host="${remote.host}"
verbose="${verbose}"
knownhosts="${project.dist}/ssh/known_hosts." trust="true"
command="${command}">
</sshexec>
</then>
<else>
<echo message="Cancello il contenuto della cartella" />
<sshexec keyfile="${public.key}" username="${remote.username}" host="${remote.host}"
verbose="${verbose}"
knownhosts="${project.dist}/ssh/known_hosts." trust="true"
command="${command}">
</sshexec>
</else>
</if>
</target>
<target name="remote.copy">
<echo message="Copia del file in ${remote.file} in corso con username/password" />
<if>
<not>
<isset property="public.key"/>
</not>
<then>
<!--
Attenzione, Load up puttygen and “Export” the key in ‘openssh’ format. Try using this key instead.
-->
<scp password="${remote.password}" sftp="true"
verbose="${verbose}"
knownhosts="${project.dist}/ssh/known_hosts." trust="true"
file="${source}"
todir="${target}">
</scp>
</then>
<else>
<scp keyfile="${public.key}"
verbose="${verbose}"
knownhosts="${project.dist}/ssh/known_hosts." trust="true"
file="${source}"
todir="${target}">
</scp>
</else>
</if>
</target>
<!-- Include -->
<target name="sub-include-AntContrib">
<echo>Include ANT-contrib JAR</echo>
<!-- Include le librerie ant-contrib-0.6.jar
http://ant-contrib.sourceforge.net/ -->
<taskdef resource="net/sf/antcontrib/antcontrib.properties">
<classpath>
<pathelement location="${basedir}/lib/ant/ant-contrib-0.6.jar"/>
</classpath>
</taskdef>
</target>
<target name="copySftp" if="remote.host" description="Routine di trasferimento file via SFTP">
<antcall target="sub-checkMandatory">
<param name="param.list" value="local.path,local.file,remote.host.list,remote.path,remote.username"/>
<!--
<param name="param.list" value="local.path,local.file,remote.host.list,remote.path,remote.username,remote.password"/>
-->
</antcall>
<property name="to.upload" value="${local.path}/${local.file}" />
<echo message="Caricamento del file ${to.upload} sul server remoto ${remote.host}" />
<!-- Setup accesso -->
<property name="remote.file" value="${remote.path}/${local.file}" />
<property name="remote.file.tmp" value="${remote.path}/${local.file}.tmp" />
<property name="tofile" value="${remote.username}@${remote.host}:${remote.file.tmp}" />
<!-- Copia del file -->
<property name="verbose" value="false" />
<antcall target="remote.exec">
<param name="command" value="rm -f ${remote.path}/*.war*" />
</antcall>
<antcall target="remote.copy">
<param name="source" value="${to.upload}" />
<param name="target" value="${tofile}" />
</antcall>
<antcall target="remote.exec">
<param name="command" value="mv ${remote.file.tmp} ${remote.file}" />
</antcall>
<echo message="File ${to.upload} copiato correttamente" />
<echo message="Upload completato" />
</target>
<!-- Check dei parametri obbligatori -->
<target name="sub-checkMandatory" if="param.list">
<for param="element" list="${param.list}" trim="true">
<sequential>
<if>
<not>
<isset property="@{element}"/>
</not>
<then>
<echo message="[ERROR] Parametro obbligatorio non valorizzato: '@{element}'" />
<property name="do.abort" value="true" />
</then>
</if>
</sequential>
</for>
<fail if="do.abort" message="Parametri obbligatori non valorizzati" />
</target>
<target name="uploadAndDeploy" depends="sub-include-AntContrib">
<antcall target="sub-checkMandatory">
<param name="param.list" value="local.path,warfile.name,remote.host.list,remote.path"/>
</antcall>
<!-- Richiesta di conferma -->
<input message="Vuoi eseguire l'upload del file ${warfile.name} sui nodi: ${remote.host.list}?"
validargs="S,n"
addproperty="input.response"
defaultvalue="S"/>
<condition property="do.abort">
<not>
<equals arg1="S" arg2="${input.response}" />
</not>
</condition>
<fail if="do.abort">Operazione annullata dall'utente</fail>
<!-- Richiesta user e password per accesso SSH
Questa fase può essere omessa se sono passate come param 'remote.username' e 'remote.password'
-->
<echo message="Verifica credenziali accesso cluster" />
<if>
<not>
<isset property="remote.username"/>
</not>
<then>
<input message="Utente:" addproperty="remote.username" />
<condition property="do.abort">
<equals arg1="" arg2="${remote.username}" />
</condition>
<fail if="do.abort">Utente nullo, operazione annullata</fail>
</then>
</if>
<!-- La password la verifico solo se non uso la chiave pubblica -->
<if>
<not>
<isset property="public.key"/>
</not>
<then>
<if>
<not>
<isset property="remote.password"/>
</not>
<then>
<input message="Password:" addproperty="remote.password" />
<condition property="do.abort">
<equals arg1="" arg2="${remote.password}" />
</condition>
<fail if="do.abort">Password nulla, operazione annullata</fail>
</then>
</if>
</then>
</if>
<!-- Ciclo sulla lista dei nodi per eseguire l'upload del file sui server remoti -->
<for param="element" list="${remote.host.list}">
<sequential>
<property name="remote.host" value="@{element}" />
<if>
<isset property="remote.host" />
<then>
<antcall target="copySftp">
<param name="local.file" value="${warfile.name}" />
<!-- Gli altri parametri sono ereditati -->
</antcall>
</then>
</if>
</sequential>
</for>
<echo message="Deployment application" />
<for param="element" list="${remote.host.list}">
<sequential>
<echo message="Host '${remote.host}'" />
<echo message="War '${remote.path}/${warfile.name}'" />
<antcall target="deploy">
<!-- Gli altri parametri sono ereditati -->
</antcall>
</sequential>
</for>
</target>
<!-- Operazione di deploy (locale) -->
<target name="deploy">
<antcall target="sub-checkMandatory">
<param name="param.list" value="remote.host,remote.path,warfile.name,context"/>
</antcall>
<!-- Richiesta di conferma -->
<input message="Vuoi eseguire il deploy della nuova versione su tutti i nodi?"
validargs="S,n"
addproperty="input.response2"
defaultvalue="S"/>
<condition property="do.abort">
<not>
<equals arg1="S" arg2="${input.response2}" />
</not>
</condition>
<fail if="do.abort">Operazione annullata dall'utente</fail>
<!-- Deploy -->
<echo>Deploy della nuova versione sui nodi</echo>
<echo>* context = ${context}</echo>
<echo>* war (locale) = ${warfile.name}</echo>
<!-- Workaround per web150 -->
<echo message="Undeploy di sicurezza automatico" />
<antcall target="remote.exec">
<param name="command">cd ${remote.path} && tomcat-deploy -u -f</param>
</antcall>
<echo message="Deploy automatico" />
<antcall target="remote.exec">
<param name="command">cd ${remote.path} && tomcat-deploy -f</param>
</antcall>
<echo>Deploy completato su tutti i nodi</echo>
</target>
<!-- Esegue un comando 'refresh' di Eclipse -->
<target name="refresh" depends="sub-include-AntContrib" description="REFRESH di Eclipse" >
<trycatch reference="exception_ref">
<try>
<echo>Eclipse refresh in progress...</echo>
<!-- Refresh del progetto
Per funzionare deve essere impostato il seguente flag in "External tool configuration"
JRE > Run in the same JRE as the workspace
-->
<eclipse.refreshLocal resource="${project.name}" depth="infinite"/>
<echo>Eclipse refreshed!</echo>
</try>
<catch>
<echo>Per funzionare deve essere impostato il seguente flag in "External tool configuration"
JRE > Run in the same JRE as the workspace</echo>
</catch>
<finally>
<!-- <echo>Finally</echo> -->
</finally>
</trycatch>
</target>
</project>