|
1 # == Define puppi::project::war |
|
2 # |
|
3 # This is a shortcut define to build a puppi project for the deploy of warfiles |
|
4 # It uses different "core" defines (puppi::project, puppi:deploy (many), |
|
5 # puppi::rollback (many)) to build a full featured template project for |
|
6 # automatic deployments. |
|
7 # If you need to customize it, either change the template defined here or |
|
8 # build up your own custom ones. |
|
9 # |
|
10 # == Variables: |
|
11 # |
|
12 # [*source*] |
|
13 # The full URL of the main file to retrieve. |
|
14 # Format should be in URI standard (http:// file:// ssh:// rsync://). |
|
15 # |
|
16 # [*deploy_root*] |
|
17 # The destination directory where the retrieved file(s) are deployed. |
|
18 # |
|
19 # [*init_source*] |
|
20 # (Optional) - The full URL to be used to retrieve, for the first time, |
|
21 # the project files. They are copied directly to the $deploy_root |
|
22 # Format should be in URI standard (http:// file:// ssh:// svn://). |
|
23 # |
|
24 # [*user*] |
|
25 # (Optional) - The user to be used for deploy operations. |
|
26 # |
|
27 # [*predeploy_customcommand*] |
|
28 # (Optional) - Full path with arguments of an eventual custom command to |
|
29 # execute before the deploy. The command is executed as $predeploy_user. |
|
30 # |
|
31 # [*predeploy_user*] |
|
32 # (Optional) - The user to be used to execute the $predeploy_customcommand. |
|
33 # By default is the same of $user. |
|
34 # |
|
35 # [*predeploy_priority*] |
|
36 # (Optional) - The priority (execution sequence number) that defines when, |
|
37 # during the deploy procedure, the $predeploy_customcommand is executed |
|
38 # Default: 39 (immediately before the copy of files on the deploy root). |
|
39 # |
|
40 # [*postdeploy_customcommand*] |
|
41 # (Optional) - Full path with arguments of an eventual custom command to |
|
42 # execute after the deploy. The command is executed as $postdeploy_user. |
|
43 # |
|
44 # [*postdeploy_user*] |
|
45 # (Optional) - The user to be used to execute the $postdeploy_customcommand. |
|
46 # By default is the same of $user. |
|
47 # |
|
48 # [*postdeploy_priority*] |
|
49 # (Optional) - The priority (execution sequence number) that defines when, |
|
50 # during the deploy procedure, the $postdeploy_customcommand is executed |
|
51 # Default: 41 (immediately after the copy of files on the deploy root). |
|
52 # |
|
53 # [*init_script*] |
|
54 # (Optional - Obsolete) - The name (ex: tomcat) of the init script of your |
|
55 # Application server. If you define it, the AS is stopped and then started |
|
56 # during deploy. This option is deprecated, you can use $disable_services |
|
57 # for the same functionality |
|
58 # |
|
59 # [*disable_services*] |
|
60 # (Optional) - The names (space separated) of the services you might want to |
|
61 # stop during deploy. By default is blank. Example: "apache puppet monit". |
|
62 # |
|
63 # [*firewall_src_ip*] |
|
64 # (Optional) - The IP address of a loadbalancer you might want to block out |
|
65 # during a deploy. |
|
66 # |
|
67 # [*firewall_dst_port*] |
|
68 # (Optional) - The local port to block from the loadbalancer during deploy |
|
69 # (Default all). |
|
70 # |
|
71 # [*firewall_delay*] |
|
72 # (Optional) - A delay time in seconds to wait after the block of |
|
73 # $firewall_src_ip. Should be at least as long as the loadbalancer check |
|
74 # interval for the services stopped during deploy (Default: 1). |
|
75 # |
|
76 # [*report_email*] |
|
77 # (Optional) - The (space separated) email(s) to notify of deploy/rollback |
|
78 # operations. If none is specified, no email is sent. |
|
79 # |
|
80 # [*clean_deploy*] |
|
81 # (Optional, default false) - If during the deploy procedure, all the |
|
82 # existing files that are not on the source have to be deleted. |
|
83 # (When true, a --delete option is added to the rsync command) |
|
84 # Do not set to true if source files are incremental. |
|
85 # |
|
86 # [*backup_enable*] |
|
87 # (Optional, default true) - If the backup of files in the deploy dir |
|
88 # is done (before deploy). If set to false, rollback is disabled. |
|
89 # |
|
90 # [*backup_rsync_options*] |
|
91 # (Optional) - The extra options to pass to rsync for backup operations. Use |
|
92 # it, for example, to exclude directories that you don't want to archive. |
|
93 # IE: "--exclude .snapshot --exclude cache --exclude www/cache". |
|
94 # |
|
95 # [*backup_retention*] |
|
96 # (Optional) - Number of backup archives to keep. (Default 5). |
|
97 # Lower the default value if your backups are too large and may fill up the |
|
98 # filesystem. |
|
99 # |
|
100 # [*run_checks*] |
|
101 # (Optional) - If you want to run local puppi checks before and after the |
|
102 # deploy procedure. Default: "true". |
|
103 # |
|
104 # [*always_deploy*] |
|
105 # (Optional) - If you always deploy what has been downloaded. Default="yes", |
|
106 # if set to "no" a checksum is made between the files previously downloaded |
|
107 # and the new files. If they are the same the deploy is not done. |
|
108 # |
|
109 # [*check_deploy*] |
|
110 # (Optional) - Checks if the war is deployed (Default yes). Set to no if |
|
111 # you deploy on Jboss or the deployed dir is different for the war filename |
|
112 # |
|
113 # [*auto_deploy*] |
|
114 # (Optional) - If you want to automatically run this puppi deploy when |
|
115 # Puppet runs. Default: 'false' |
|
116 # |
|
117 define puppi::project::war ( |
|
118 $source, |
|
119 $deploy_root, |
|
120 $init_source = '', |
|
121 $user = 'root', |
|
122 $predeploy_customcommand = '', |
|
123 $predeploy_user = '', |
|
124 $predeploy_priority = '39', |
|
125 $postdeploy_customcommand = '', |
|
126 $postdeploy_user = '', |
|
127 $postdeploy_priority = '41', |
|
128 $init_script = '', |
|
129 $disable_services = '', |
|
130 $firewall_src_ip = '', |
|
131 $firewall_dst_port = '0', |
|
132 $firewall_delay = '1', |
|
133 $report_email = '', |
|
134 $clean_deploy = false, |
|
135 $backup_enable = true, |
|
136 $backup_rsync_options = '--exclude .snapshot', |
|
137 $backup_retention = '5', |
|
138 $run_checks = true, |
|
139 $always_deploy = true, |
|
140 $check_deploy = true, |
|
141 $auto_deploy = false, |
|
142 $enable = true ) { |
|
143 |
|
144 require puppi |
|
145 require puppi::params |
|
146 |
|
147 # Set default values |
|
148 $predeploy_real_user = $predeploy_user ? { |
|
149 '' => $user, |
|
150 default => $predeploy_user, |
|
151 } |
|
152 |
|
153 $postdeploy_real_user = $postdeploy_user ? { |
|
154 '' => $user, |
|
155 default => $postdeploy_user, |
|
156 } |
|
157 |
|
158 # Unless explicitely defined, we assume that the WAR file to use |
|
159 # for initialization is the same to use for deploys |
|
160 $init_real_source = $init_source ? { |
|
161 '' => $source, |
|
162 default => $init_source, |
|
163 } |
|
164 |
|
165 $real_always_deploy = any2bool($always_deploy) ? { |
|
166 false => 'no', |
|
167 true => 'yes', |
|
168 } |
|
169 |
|
170 $bool_run_checks = any2bool($run_checks) |
|
171 $bool_clean_deploy = any2bool($clean_deploy) |
|
172 $bool_backup_enable = any2bool($backup_enable) |
|
173 $bool_check_deploy = any2bool($check_deploy) |
|
174 $bool_auto_deploy = any2bool($auto_deploy) |
|
175 |
|
176 $war_file = url_parse($source,'filename') |
|
177 |
|
178 |
|
179 ### CREATE PROJECT |
|
180 puppi::project { $name: |
|
181 enable => $enable , |
|
182 } |
|
183 |
|
184 |
|
185 ### INIT SEQUENCE |
|
186 if ($init_source != '') { |
|
187 puppi::initialize { "${name}-Deploy_Files": |
|
188 priority => '40' , |
|
189 command => 'get_file.sh' , |
|
190 arguments => "-s ${init_source} -d ${deploy_root}" , |
|
191 user => $user , |
|
192 project => $name , |
|
193 enable => $enable , |
|
194 } |
|
195 } |
|
196 |
|
197 |
|
198 ### DEPLOY SEQUENCE |
|
199 if ($bool_run_checks == true) { |
|
200 puppi::deploy { "${name}-Run_PRE-Checks": |
|
201 priority => '10' , |
|
202 command => 'check_project.sh' , |
|
203 arguments => $name , |
|
204 user => 'root' , |
|
205 project => $name , |
|
206 enable => $enable , |
|
207 } |
|
208 } |
|
209 |
|
210 # Here source file is retrieved |
|
211 puppi::deploy { "${name}-Retrieve_WAR": |
|
212 priority => '20' , |
|
213 command => 'get_file.sh' , |
|
214 arguments => "-s ${source} -a ${real_always_deploy}" , |
|
215 user => 'root' , |
|
216 project => $name , |
|
217 enable => $enable , |
|
218 } |
|
219 |
|
220 if ($firewall_src_ip != '') { |
|
221 puppi::deploy { "${name}-Load_Balancer_Block": |
|
222 priority => '25' , |
|
223 command => 'firewall.sh' , |
|
224 arguments => "${firewall_src_ip} ${firewall_dst_port} on ${firewall_delay}" , |
|
225 user => 'root', |
|
226 project => $name , |
|
227 enable => $enable , |
|
228 } |
|
229 } |
|
230 |
|
231 if ($bool_backup_enable == true) { |
|
232 puppi::deploy { "${name}-Backup_existing_WAR": |
|
233 priority => '30' , |
|
234 command => 'archive.sh' , |
|
235 arguments => "-b ${deploy_root} -t war -s move -m diff -o '${backup_rsync_options}' -n ${backup_retention}" , |
|
236 user => 'root' , |
|
237 project => $name , |
|
238 enable => $enable , |
|
239 } |
|
240 } |
|
241 |
|
242 if ($bool_check_deploy == true) { |
|
243 puppi::deploy { "${name}-Check_undeploy": |
|
244 priority => '32' , |
|
245 command => 'checkwardir.sh' , |
|
246 arguments => "-a ${deploy_root}/${war_file}" , |
|
247 user => $user , |
|
248 project => $name , |
|
249 enable => $enable , |
|
250 } |
|
251 } |
|
252 |
|
253 if ($disable_services != '') { |
|
254 puppi::deploy { "${name}-Disable_extra_services": |
|
255 priority => '36' , |
|
256 command => 'service.sh' , |
|
257 arguments => "stop ${disable_services}" , |
|
258 user => 'root', |
|
259 project => $name , |
|
260 enable => $enable , |
|
261 } |
|
262 } |
|
263 |
|
264 if ($init_script != '') { |
|
265 puppi::deploy { "${name}-Service_stop": |
|
266 priority => '38' , |
|
267 command => 'service.sh' , |
|
268 arguments => "stop ${init_script}" , |
|
269 user => 'root', |
|
270 project => $name , |
|
271 enable => $enable , |
|
272 } |
|
273 } |
|
274 |
|
275 if ($predeploy_customcommand != '') { |
|
276 puppi::deploy { "${name}-Run_Custom_PreDeploy_Script": |
|
277 priority => $predeploy_priority , |
|
278 command => 'execute.sh' , |
|
279 arguments => $predeploy_customcommand , |
|
280 user => $predeploy_real_user , |
|
281 project => $name , |
|
282 enable => $enable , |
|
283 } |
|
284 } |
|
285 |
|
286 # Here is done the deploy on $deploy_root |
|
287 puppi::deploy { "${name}-Deploy_WAR": |
|
288 priority => '40' , |
|
289 command => 'deploy_files.sh' , |
|
290 arguments => "-d ${deploy_root} -c ${bool_clean_deploy}", |
|
291 user => $user , |
|
292 project => $name , |
|
293 enable => $enable , |
|
294 } |
|
295 |
|
296 if ($postdeploy_customcommand != '') { |
|
297 puppi::deploy { "${name}-Run_Custom_PostDeploy_Script": |
|
298 priority => $postdeploy_priority , |
|
299 command => 'execute.sh' , |
|
300 arguments => $postdeploy_customcommand , |
|
301 user => $postdeploy_real_user , |
|
302 project => $name , |
|
303 enable => $enable , |
|
304 } |
|
305 } |
|
306 |
|
307 if ($init_script != '') { |
|
308 puppi::deploy { "${name}-Service_start": |
|
309 priority => '42' , |
|
310 command => 'service.sh' , |
|
311 arguments => "start ${init_script}" , |
|
312 user => 'root', |
|
313 project => $name , |
|
314 enable => $enable , |
|
315 } |
|
316 } |
|
317 |
|
318 if ($disable_services != '') { |
|
319 puppi::deploy { "${name}-Enable_extra_services": |
|
320 priority => '44' , |
|
321 command => 'service.sh' , |
|
322 arguments => "start ${disable_services}" , |
|
323 user => 'root', |
|
324 project => $name , |
|
325 enable => $enable , |
|
326 } |
|
327 } |
|
328 |
|
329 if ($bool_check_deploy == true) { |
|
330 puppi::deploy { "${name}-Check_deploy": |
|
331 priority => '45' , |
|
332 command => 'checkwardir.sh' , |
|
333 arguments => "-p ${deploy_root}/${war_file}" , |
|
334 user => $user , |
|
335 project => $name , |
|
336 enable => $enable , |
|
337 } |
|
338 } |
|
339 |
|
340 if ($firewall_src_ip != '') { |
|
341 puppi::deploy { "${name}-Load_Balancer_Unblock": |
|
342 priority => '46' , |
|
343 command => 'firewall.sh' , |
|
344 arguments => "${firewall_src_ip} ${firewall_dst_port} off 0" , |
|
345 user => 'root', |
|
346 project => $name , |
|
347 enable => $enable , |
|
348 } |
|
349 } |
|
350 |
|
351 if ($bool_run_checks == true) { |
|
352 puppi::deploy { "${name}-Run_POST-Checks": |
|
353 priority => '80' , |
|
354 command => 'check_project.sh' , |
|
355 arguments => $name , |
|
356 user => 'root' , |
|
357 project => $name , |
|
358 enable => $enable , |
|
359 } |
|
360 } |
|
361 |
|
362 |
|
363 ### ROLLBACK PROCEDURE |
|
364 |
|
365 if ($bool_backup_enable == true) { |
|
366 |
|
367 if ($firewall_src_ip != '') { |
|
368 puppi::rollback { "${name}-Load_Balancer_Block": |
|
369 priority => '25' , |
|
370 command => 'firewall.sh' , |
|
371 arguments => "${firewall_src_ip} ${firewall_dst_port} on ${firewall_delay}" , |
|
372 user => 'root', |
|
373 project => $name , |
|
374 enable => $enable , |
|
375 } |
|
376 } |
|
377 |
|
378 puppi::rollback { "${name}-Remove_existing_WAR": |
|
379 priority => '30' , |
|
380 command => 'delete.sh' , |
|
381 arguments => "${deploy_root}/${war_file}" , |
|
382 user => 'root' , |
|
383 project => $name , |
|
384 enable => $enable , |
|
385 } |
|
386 |
|
387 if ($bool_check_deploy == true) { |
|
388 puppi::rollback { "${name}-Check_undeploy": |
|
389 priority => '36' , |
|
390 command => 'checkwardir.sh' , |
|
391 arguments => "-a ${deploy_root}/${war_file}" , |
|
392 user => $user , |
|
393 project => $name , |
|
394 enable => $enable , |
|
395 } |
|
396 } |
|
397 |
|
398 if ($disable_services != '') { |
|
399 puppi::rollback { "${name}-Disable_extra_services": |
|
400 priority => '37' , |
|
401 command => 'service.sh' , |
|
402 arguments => "stop ${disable_services}" , |
|
403 user => 'root', |
|
404 project => $name , |
|
405 enable => $enable , |
|
406 } |
|
407 } |
|
408 |
|
409 if ($init_script != '') { |
|
410 puppi::rollback { "${name}-Service_stop": |
|
411 priority => '38' , |
|
412 command => 'service.sh' , |
|
413 arguments => "stop ${init_script}" , |
|
414 user => 'root', |
|
415 project => $name , |
|
416 enable => $enable , |
|
417 } |
|
418 } |
|
419 |
|
420 if ($predeploy_customcommand != '') { |
|
421 puppi::rollback { "${name}-Run_Custom_PreDeploy_Script": |
|
422 priority => $predeploy_priority , |
|
423 command => 'execute.sh' , |
|
424 arguments => $predeploy_customcommand , |
|
425 user => $predeploy_real_user , |
|
426 project => $name , |
|
427 enable => $enable , |
|
428 } |
|
429 } |
|
430 |
|
431 puppi::rollback { "${name}-Recover_Files_To_Deploy": |
|
432 priority => '40' , |
|
433 command => 'archive.sh' , |
|
434 arguments => "-r ${deploy_root} -t war -o '${backup_rsync_options}'" , |
|
435 user => $user , |
|
436 project => $name , |
|
437 enable => $enable , |
|
438 } |
|
439 |
|
440 if ($postdeploy_customcommand != '') { |
|
441 puppi::rollback { "${name}-Run_Custom_PostDeploy_Script": |
|
442 priority => $postdeploy_priority , |
|
443 command => 'execute.sh' , |
|
444 arguments => $postdeploy_customcommand , |
|
445 user => $postdeploy_real_user , |
|
446 project => $name , |
|
447 enable => $enable , |
|
448 } |
|
449 } |
|
450 |
|
451 if ($init_script != '') { |
|
452 puppi::rollback { "${name}-Service_start": |
|
453 priority => '42' , |
|
454 command => 'service.sh' , |
|
455 arguments => "start ${init_script}" , |
|
456 user => 'root', |
|
457 project => $name , |
|
458 enable => $enable , |
|
459 } |
|
460 } |
|
461 |
|
462 if ($disable_services != '') { |
|
463 puppi::rollback { "${name}-Enable_extra_services": |
|
464 priority => '44' , |
|
465 command => 'service.sh' , |
|
466 arguments => "start ${disable_services}" , |
|
467 user => 'root', |
|
468 project => $name , |
|
469 enable => $enable , |
|
470 } |
|
471 } |
|
472 |
|
473 if ($bool_check_deploy == true) { |
|
474 puppi::rollback { "${name}-Check_deploy": |
|
475 priority => '45' , |
|
476 command => 'checkwardir.sh' , |
|
477 arguments => "-p ${deploy_root}/${war_file}" , |
|
478 user => $user , |
|
479 project => $name , |
|
480 enable => $enable , |
|
481 } |
|
482 } |
|
483 |
|
484 if ($firewall_src_ip != '') { |
|
485 puppi::rollback { "${name}-Load_Balancer_Unblock": |
|
486 priority => '46' , |
|
487 command => 'firewall.sh' , |
|
488 arguments => "${firewall_src_ip} ${firewall_dst_port} off 0" , |
|
489 user => 'root', |
|
490 project => $name , |
|
491 enable => $enable , |
|
492 } |
|
493 } |
|
494 |
|
495 if ($bool_run_checks == true) { |
|
496 puppi::rollback { "${name}-Run_POST-Checks": |
|
497 priority => '80' , |
|
498 command => 'check_project.sh' , |
|
499 arguments => $name , |
|
500 user => 'root' , |
|
501 project => $name , |
|
502 enable => $enable , |
|
503 } |
|
504 } |
|
505 } |
|
506 |
|
507 ### REPORTING |
|
508 |
|
509 if ($report_email != '') { |
|
510 puppi::report { "${name}-Mail_Notification": |
|
511 priority => '20' , |
|
512 command => 'report_mail.sh' , |
|
513 arguments => $report_email , |
|
514 user => 'root', |
|
515 project => $name , |
|
516 enable => $enable , |
|
517 } |
|
518 } |
|
519 |
|
520 ### AUTO DEPLOY DURING PUPPET RUN |
|
521 if ($bool_auto_deploy == true) { |
|
522 puppi::run { $name: } |
|
523 } |
|
524 |
|
525 } |