Class: Deployment::Worker

Inherits:
Object
  • Object
show all
Defined in:
lib/depengine/dsl/deployment.rb

Instance Method Summary collapse

Constructor Details

#initializeWorker

Returns a new instance of Worker.



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
# File 'lib/depengine/dsl/deployment.rb', line 18

def initialize
  # initialize logging
  if not $recipe_config[:log_level].nil?
    case $recipe_config[:log_level]
      when "DEBUG"
        $log.level('stdout_logger', Log4r::DEBUG)
      when "INFO"
        $log.level('stdout_logger', Log4r::INFO)
      when "WARN"
        $log.level('stdout_logger', Log4r::WARN)
      when "ERROR"
        $log.level('stdout_logger', Log4r::ERROR)
      when "FATAL"
        $log.level('stdout_logger', Log4r::FATAL)
    end
  end
  if $recipe_config[:log_trace]
    $log.enable_trace
  end

  # read global deployment configuration from etc/config.yaml
  if ENV['USE_DEPENGINE_AS_GEM']
    deployment_configuration_file = \
       ( File.join(File.dirname($exec_file_path), '../../etc/config.yaml') )
  else
    deployment_configuration_file = \
       ( File.join(File.dirname($exec_file_path), '../etc/config.yaml') )
  end      
  if File.file? deployment_configuration_file
    $recipe_config.merge! Helper.yaml_parse(deployment_configuration_file)
  else
    puts "Can not read deployment configuration etc/config.yaml"
  end

  # generate hash from environemnt variables and merge
  $recipe_config.merge! Helper.get_environemnt_variables($recipe_config['env_exceptions'])

  # generate version hash from environment variable
  @version = Helper.parse_version($recipe_config[:version])

  # validate needed environment variables
  Helper.validates_not_empty $recipe_config[:env], \
                               "env is not set"
  Helper.validates_not_empty $recipe_config[:version], \
                               "version is not set"
  Helper.validates_not_empty $recipe_config[:deploy_home], \
                               "deploy_home is not set"

  # read configuration from cdb
  @cdb = get_cdb_parameters(@version['cdb'])

  # clean workspace if needed       
  if $recipe_config[:cleanup_workspace_before]
     $log.writer.info "Remove all files from Workspace"
    Helper.cleanup_workspace!($recipe_config[:deploy_home])
  end
  # init workspace with default directorys
  Helper.init_workspace($recipe_config[:deploy_home])

  # the logfile needs a correct WORKSPACE and the initial dirs
  # so we have to set it here
  if $recipe_config[:log_file]
    level = Log4r::INFO
    $log.writer.info "Logfile level set to #{$recipe_config[:log_file_level]}"
    case $recipe_config[:log_file_level]
      when "DEBUG"
        level = Log4r::DEBUG
      when "INFO"
        level = Log4r::INFO
      when "WARN"
        level = Log4r::WARN
      when "ERROR"
        level = Log4r::ERROR
      when "FATAL"
        level = Log4r::FATAL
    end
    $log.add_outputter(Log4r::FileOutputter.new('log_file', \
      :filename => File.join($recipe_config[:deploy_home], 'log', \
                             $recipe_config[:log_file])), \
      level)
  end
end

Instance Method Details

#add_properties(source, target, options = {}) ⇒ Object



524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
# File 'lib/depengine/dsl/deployment.rb', line 524

def add_properties (source, target, options={})
  patch_set = 'patch_properties'
  if not options[:patch_set].nil?
    patch_set = options[:patch_set]
  end
  Helper.validates_presence_of @cdb[patch_set],  "Properties not set"

  assigner = '='
  if not options[:assigner].nil?
    assigner = options[:assigner]
  end
  
  properties                 = Processor::Properties.new
  properties.assigner        = assigner
  properties.properties_hash = @cdb[patch_set]
  properties.add(File.join($recipe_config[:deploy_home], source), \
                   File.join($recipe_config[:deploy_home], target,  \
                   File.basename(source)))
end

#assert_url_response_of(options = {}) ⇒ Object



618
619
620
621
622
623
624
625
626
627
# File 'lib/depengine/dsl/deployment.rb', line 618

def assert_url_response_of(options={})
  asserter = Asserter::Url.new
  asserter.check_protocol  = options[:check_protocol] ||  @cdb['check_protocol'] || "http"
  asserter.check_host  = options[:check_host] || @cdb['check_host']
  asserter.check_port  = options[:check_port] || @cdb['check_port'] || '80'
  asserter.check_uri  = options[:check_uri] || @cdb['check_uri'] || '/'
  asserter.check_response_string  = options[:chek_response_string] || @cdb['check_response_string'] || 'html'

  asserter.assert_url_response_of(options)
end

#check_filelist(list, target) ⇒ Object



128
129
130
131
# File 'lib/depengine/dsl/deployment.rb', line 128

def check_filelist(list, target)
  Processor.check_filelist(File.join($recipe_config[:deploy_home], list), \
                           File.join($recipe_config[:deploy_home], target))
end

#chmod(file, mode, options = {}) ⇒ Object



115
116
117
118
# File 'lib/depengine/dsl/deployment.rb', line 115

def chmod(file, mode, options={})
  Processor.chmod(File.join($recipe_config[:deploy_home], file), \
                  mode, options)
end

#copy(source, target, options = {}) ⇒ Object

access configdata like this… @hudson $recipe_config



105
106
107
108
109
# File 'lib/depengine/dsl/deployment.rb', line 105

def copy(source, target, options={})
  Processor.copy(File.join($recipe_config[:deploy_home], source), \
                 File.join($recipe_config[:deploy_home], target), \
                 options)
end


336
337
338
339
340
341
342
343
# File 'lib/depengine/dsl/deployment.rb', line 336

def dweb_link(source, symlink, options={})
  publisher = Publisher::Dweb.new
  publisher.staging_host = @cdb['staging_host']
  publisher.ssh_key_file = @cdb['ssh_key_file']
  publisher.siteid       = @cdb['siteid']

  publisher.remote_symlink(source, symlink, options)
end

#dweb_upload(source, target, options = {}) ⇒ Object



317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
# File 'lib/depengine/dsl/deployment.rb', line 317

def dweb_upload(source, target, options={})
  Helper.validates_presence_of @cdb['staging_host'], "Staging Host not set"
  Helper.validates_presence_of @cdb['ssh_key_file'], "SSH keyfile not set"
  Helper.validates_presence_of @cdb['siteid'], "Siteid not set"
  Helper.validates_presence_of source
  Helper.validates_presence_of target

  publisher = Publisher::Dweb.new
  publisher.staging_host = @cdb['staging_host']
  publisher.ssh_key_file = @cdb['ssh_key_file']
  publisher.siteid       = @cdb['siteid']

  vhost                  = options[:siteid]   || @cdb['siteid']
  options[:excludes]     = options[:excludes] || ['.svn']

  publisher.upload(File.join($recipe_config[:deploy_home], source), \
                   File.join('/vhosts/', vhost, target), options)
end

#get_all_config_parametersObject



178
179
180
181
# File 'lib/depengine/dsl/deployment.rb', line 178

def get_all_config_parameters
  # merge cdb data
  $recipe_config.merge @cdb
end

#get_cdb_parameters(version) ⇒ Object



183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/depengine/dsl/deployment.rb', line 183

def get_cdb_parameters(version)
  Helper.validates_presence_of version, "version parameter is missing"
  Helper.validates_presence_of $recipe_config['cdb_host'], \
                               "cdb_host parameter is missing"
  Helper.validates_presence_of $recipe_config['cdb_context'], \
                               "cdb_context parameter is missing"

  cdb          = Provider::CDB.new
  cdb.protocol = 'http'
  cdb.host     = $recipe_config['cdb_host']
  cdb.context  = $recipe_config['cdb_context']
  cdb.env      = $recipe_config[:env]

  cdb.get_parameters(File.join( $recipe_config[:env], \
                            $recipe_config[:module_name] ), version)
end

#get_dir_from_samba(source, target) ⇒ Object



231
232
233
234
235
236
237
238
239
240
# File 'lib/depengine/dsl/deployment.rb', line 231

def get_dir_from_samba(source, target)
  Helper.validates_presence_of @cdb['samba_repository'], "Samba repository not set"

  samba            = Provider::Repository.new
  samba.repository = @cdb['samba_repository']
  samba.samba_mountpoints = @cdb['samba_mountpoints']
  samba.method     = "samba"
  samba.worker  = self
  samba.get_from_repository(source, File.join($recipe_config[:deploy_home], target))
end

#get_file_from_maven(source, target) ⇒ Object



242
243
244
245
246
247
248
249
250
251
# File 'lib/depengine/dsl/deployment.rb', line 242

def get_file_from_maven(source, target)
  Helper.validates_presence_of @cdb['maven_repository'], "Maven repository not set"

  maven            = Provider::Repository.new
  maven.repository = @cdb['maven_repository']
  maven.user       = @cdb['maven_user']
  maven.password   = @cdb['maven_password']
  maven.method     = "maven"
  maven.get_from_repository(source, File.join($recipe_config[:deploy_home], target))
end

#get_file_via_scp(source, target, options = {}) ⇒ Object



253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
# File 'lib/depengine/dsl/deployment.rb', line 253

def get_file_via_scp(source, target, options={})
  Helper.validates_presence_of @cdb['scp_source_host'], \
      "scp source host not set"
  Helper.validates_presence_of @cdb['scp_source_user'], \
                    "scp source user not set"

  scp            = Provider::Repository.new
  scp.host       = @cdb['scp_source_host']
  scp.user       = @cdb['scp_source_user']
  if options[:ssh_key_file]
    scp.sshkey   = File.join(File.dirname($exec_file_path), \
                             options[:ssh_key_file])
  else
    scp.sshkey   = File.join(File.dirname($exec_file_path), \
                             @cdb['ssh_key_file'])
  end
  scp.method     = "scp"
  scp.get_from_repository(source, File.join($recipe_config[:deploy_home], target))
end

#get_file_via_svn(source, target, options = {}) ⇒ Object



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
# File 'lib/depengine/dsl/deployment.rb', line 273

def get_file_via_svn(source, target, options={})
  Helper.validates_presence_of @cdb['svn_binary'], \
                    "svn binary not set"
  Helper.validates_presence_of @cdb['svn_source_base_url'], \
                    "svn base url  not set"
  Helper.validates_presence_of @cdb['svn_source_user'], \
                    "svn source user not set"
  Helper.validates_presence_of @cdb['svn_source_command'], \
                    "svn command not set"

  svn            = Provider::Repository.new
  svn.svnbinary  = @cdb['svn_binary']
  svn.user       = @cdb['svn_source_user']
  svn.password   = @cdb['svn_source_password'] if @cdb['svn_source_password']
  svn.method     = "svn"

  if options[:svn_command]
    svn.svncmd     = options[:svn_command]
  else
    svn.svncmd     = @cdb['svn_source_command'] + " -r#{options[:revision]}"
  end

  if options[:svn_repository]
    svn.repository = options[:svn_repository]
  else
    svn.repository = @cdb['svn_source_base_url']
  end

  svn.get_from_repository(source, \
                          File.join($recipe_config[:deploy_home], target))
end

#git_checkout(branch_name, options = {}) ⇒ Object



682
683
684
685
686
687
# File 'lib/depengine/dsl/deployment.rb', line 682

def git_checkout(branch_name, options={})
  publisher = Publisher::Git.new
  publisher.repository_url = options[:git_repository_url] || @cdb['git_repository_url']
  publisher.repository_local_dir = options[:git_repository_local] || @cdb['git_repository_local']
  publisher.checkout(branch_name, options)
end

#git_fetch(options = {}) ⇒ Object



675
676
677
678
679
680
# File 'lib/depengine/dsl/deployment.rb', line 675

def git_fetch(options={})
  publisher = Publisher::Git.new
  publisher.repository_url = options[:git_repository_url] || @cdb['git_repository_url']
  publisher.repository_local_dir = options[:git_repository_local] || @cdb['git_repository_local']
  publisher.fetch()
end

#git_tag(tag_name, options = {}) ⇒ Object



689
690
691
692
693
694
# File 'lib/depengine/dsl/deployment.rb', line 689

def git_tag(tag_name, options={})
  publisher = Publisher::Git.new
  publisher.repository_url = options[:git_repository_url] || @cdb['git_repository_url']
  publisher.repository_local_dir = options[:git_repository_local] || @cdb['git_repository_local']
  publisher.tag(tag_name, options)
end

#iis_appcmdObject



599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
# File 'lib/depengine/dsl/deployment.rb', line 599

def iis_appcmd()
  Helper.validates_presence_of @cdb['iis_appcmd_url'], \
                               "iis_appcmd_url parameter is missing"
  Helper.validates_presence_of $recipe_config['VALUE'], \
                               "VALUE parameter is missing"

  iis          = Publisher::Iis_appcmd.new
  iis.iis_appcmd_protocol = @cdb['iis_appcmd_protocol']
  iis.iis_appcmd_url     = @cdb['iis_appcmd_url']
  if @cdb['http_read_timeout']
    iis.http_read_timeout = @cdb['http_read_timeout']
  else
     iis.http_read_timeout = 180
  end

  iis.appcmd($recipe_config['VALUE'])

end

#iis_buildObject



548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
# File 'lib/depengine/dsl/deployment.rb', line 548

def iis_build()
  Helper.validates_presence_of @cdb['iis_build_url'], \
                               "iis_build_url parameter is missing"
  Helper.validates_presence_of @cdb['iis_build_protocol'], \
                               "iis_build_protocol parameter is missing"
  Helper.validates_presence_of $recipe_config['TAG'], \
                               "TAG parameter is missing"
  Helper.validates_presence_of $recipe_config['ENVIRONMENT'], \
                               "ENV parameter is missing"
  Helper.validates_presence_of  @version['app'], \
                               "VERSION parameter is missing"
  Helper.validates_presence_of $recipe_config['VALUE'], \
                               "VALUE parameter is missing"

  iis          = Publisher::Iis_build.new
  iis.iis_build_protocol = @cdb['iis_build_protocol']
  iis.iis_build_url     = @cdb['iis_build_url']
  if @cdb['http_read_timeout']
    iis.http_read_timeout = @cdb['http_read_timeout']
  else
     iis.http_read_timeout = 180
  end

  iis.build($recipe_config['TAG'], $recipe_config['ENVIRONMENT'], @version['app'], $recipe_config['VALUE'], $recipe_config[:application_name])
end

#iis_deploy(options = {}) ⇒ Object



574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
# File 'lib/depengine/dsl/deployment.rb', line 574

def iis_deploy(options={})
  Helper.validates_presence_of options[:iis_deploy_url] || @cdb['iis_deploy_url'], \
                               "iis_deploy_url parameter is missing"
  Helper.validates_presence_of @cdb['iis_application_name'], \
                               "iis_application_name parameter is missing"
  Helper.validates_presence_of @cdb['iis_deploy_protocol'], \
                               "iis_deploy_protocol parameter is missing"
  Helper.validates_presence_of $recipe_config['ENVIRONMENT'], \
                               "ENV parameter is missing"
  Helper.validates_presence_of  @version['app'], \
                               "VERSION parameter is missing"

  iis          = Publisher::Iis_deploy.new
  iis.iis_deploy_protocol = @cdb['iis_deploy_protocol']
  iis.iis_deploy_url     = options[:iis_deploy_url] || @cdb['iis_deploy_url']
  if @cdb['http_read_timeout']
    iis.http_read_timeout = @cdb['http_read_timeout']
  else
     iis.http_read_timeout = 180
  end

  iis.deploy(@version['app'], @cdb['iis_application_name'], $recipe_config['ENVIRONMENT'].downcase)
end

#mkdir(directory) ⇒ Object



111
112
113
# File 'lib/depengine/dsl/deployment.rb', line 111

def mkdir(directory)
  Processor.mkdir(File.join($recipe_config[:deploy_home], directory))
end


124
125
126
# File 'lib/depengine/dsl/deployment.rb', line 124

def mklink(source, target)
  Processor.mklink(source, File.join($recipe_config[:deploy_home], target))
end

#parse_erb_template(source, target, content, options = {}) ⇒ Object



169
170
171
172
173
174
175
176
# File 'lib/depengine/dsl/deployment.rb', line 169

def parse_erb_template(source, target, content, options={})
  template           = Processor::Template.new
  template.cdb       = @cdb
  template.basepath  = options[:basepath] || $recipe_config[:deploy_home]
  options[:excludes] = [] if options[:excludes].nil?
  options[:excludes] << '.svn'
  template.parse_erb_template(source, content, target, options)
end

#parse_template(source, target, content, options = {}) ⇒ Object



160
161
162
163
164
165
166
167
# File 'lib/depengine/dsl/deployment.rb', line 160

def parse_template(source, target, content, options={})
  template           = Processor::Template.new
  template.cdb       = @cdb
  template.basepath  = options[:basepath] || $recipe_config[:deploy_home]
  options[:excludes] = [] if options[:excludes].nil?
  options[:excludes] << '.svn'
  template.parse_template(source, content, target, options)
end

#patch_properties(source, target, options = {}) ⇒ Object



453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
# File 'lib/depengine/dsl/deployment.rb', line 453

def patch_properties (source, target, options={})
  patch_set = 'patch_properties'
  if not options[:patch_set].nil?
    patch_set = options[:patch_set]
  end
  Helper.validates_presence_of @cdb[patch_set], \
     "Can not find a valid patch_set"

  assigner = '='
  if not options[:assigner].nil?
    assigner = options[:assigner]
  end

  properties                 = Processor::Properties.new
  properties.properties_hash = @cdb[patch_set]
### add db_endpoint
  properties.properties_hash['db_endpoint_1'] = @cdb['db_endpoint_1']
  properties.properties_hash['db_endpoint_2'] = @cdb['db_endpoint_2']      
  properties.assigner        = assigner
  properties.patch(File.join($recipe_config[:deploy_home], source), \
                   File.join($recipe_config[:deploy_home], target,  \
                   File.basename(source)))
end

#patch_strings(source, target, options = {}) ⇒ Object



477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
# File 'lib/depengine/dsl/deployment.rb', line 477

def patch_strings (source, target, options={})
  patch_set = 'patch_properties'
  if not options[:patch_set].nil?
    patch_set = options[:patch_set]
  end
  Helper.validates_presence_of @cdb[patch_set],  "Properties not set"

  assigner = '='
  if not options[:assigner].nil?
    assigner = options[:assigner]
  end
  
  properties                 = Processor::Properties.new
  properties.assigner        = assigner
  properties.properties_hash = @cdb[patch_set]
### add db_endpoint
  properties.properties_hash['db_endpoint_1'] = @cdb['db_endpoint_1']
  properties.properties_hash['db_endpoint_2'] = @cdb['db_endpoint_2']      
  properties.substitute(File.join($recipe_config[:deploy_home], source), \
                   File.join($recipe_config[:deploy_home], target,  \
                   File.basename(source)))
end

#patch_strings_r(source, target, options = {}) ⇒ Object



500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
# File 'lib/depengine/dsl/deployment.rb', line 500

def patch_strings_r (source, target, options={})
  patch_set   = 'patch_properties'
  if not options[:patch_set].nil?
    patch_set = options[:patch_set]
  end
  Helper.validates_presence_of @cdb[patch_set],  "Properties not set"

  assigner = '='
  if not options[:assigner].nil?
    assigner = options[:assigner]
  end

  source_path = File.join($recipe_config[:deploy_home], source)
  target_path = File.join($recipe_config[:deploy_home], target)

  properties                 = Processor::Properties.new
  properties.assigner        = assigner
  properties.properties_hash = @cdb[patch_set]
### add db_endpoint
  properties.properties_hash['db_endpoint_1'] = @cdb['db_endpoint_1']
  properties.properties_hash['db_endpoint_2'] = @cdb['db_endpoint_2']
  properties.substitute_r(source_path, target_path)
end

#remote_execute(command, options = {}) ⇒ Object



345
346
347
348
349
350
351
352
353
354
# File 'lib/depengine/dsl/deployment.rb', line 345

def remote_execute(command, options={})
  Helper.validates_presence_of command, "No command to execute!"
  Helper.validates_presence_of @cdb['ssh_key_file'], "SSH keyfile not set"

  publisher = Publisher::Ssh.new
  publisher.remote_host  = options[:remote_host]  || @cdb['remote_host']
  publisher.remote_user  = options[:remote_user]  || @cdb['remote_user']
  publisher.ssh_key_file = options[:ssh_key_file] || @cdb['ssh_key_file']
  publisher.remote_execute(command)
end

#remove(file) ⇒ Object



120
121
122
# File 'lib/depengine/dsl/deployment.rb', line 120

def remove(file)
  Processor.remove(File.join($recipe_config[:deploy_home], file))
end

#report_by_mail(options = {}) ⇒ Object



636
637
638
639
640
641
642
643
644
645
646
# File 'lib/depengine/dsl/deployment.rb', line 636

def report_by_mail(options={})
  reporter = Reporter::Mail.new
  reporter.deploy_email_from  = options[:deploy_email_from] || @cdb['deploy_email_from']
  reporter.deploy_email_to  = options[:deploy_email_to] || @cdb['deploy_email_to']
  reporter.application_name  = options[:application_name] ||  $recipe_config[:application_name] || @cdb['application_name']
  reporter.module_name  = options[:module_name] ||  $recipe_config[:module_name] || @cdb['module_name']
  reporter.environment  =  $recipe_config['ENVIRONMENT']
  reporter.version  =  @version.to_json
  reporter.worker  = self
  reporter.send(options)
end

#report_to_cdb(options = {}) ⇒ Object



629
630
631
632
633
634
# File 'lib/depengine/dsl/deployment.rb', line 629

def report_to_cdb(options={})
  reporter = Reporter::Cdb.new
  reporter.version  = @version.to_json
  reporter.worker  = self
  reporter.set_version(options)
end

#rsync(source, target, options = {}) ⇒ Object



356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
# File 'lib/depengine/dsl/deployment.rb', line 356

def rsync(source, target, options={})
  if options[:local].nil? or options[:local] == false
    Helper.validates_presence_of @cdb['ssh_key_file'], "SSH-keyfile not set"
  end
  Helper.validates_presence_of source
  Helper.validates_presence_of target

  publisher = Publisher::Rsync.new
  publisher.remote_host  = options[:remote_host]  || @cdb['remote_host']
  publisher.remote_user  = options[:remote_user]  || @cdb['remote_user']
  publisher.ssh_key_file = options[:ssh_key_file] || @cdb['ssh_key_file']

  # publisher.ssh_key_file = File.join(File.dirname($exec_file_path),    #                                    publisher.ssh_key_file)

  if options[:local].nil? or options[:local] == false
    Helper.validates_presence_of publisher.remote_host, "Remote host not set"
    Helper.validates_presence_of publisher.remote_user, "Remote user not set"
  end

  if source[0].chr == "/"
    source_path = source
  else
    source_path = File.join($recipe_config[:deploy_home], source)
  end

  publisher.sync(source_path, target, options)
end

#samba_mount(remote_path, local_path) ⇒ Object



662
663
664
665
666
667
# File 'lib/depengine/dsl/deployment.rb', line 662

def samba_mount (remote_path, local_path)
  smb                   = Helper::Smb.new
  smb.remote_path       = remote_path
  smb.local_path        = local_path
  smb.samba_mount()
end

#samba_umount(local_path) ⇒ Object



669
670
671
672
673
# File 'lib/depengine/dsl/deployment.rb', line 669

def samba_umount (local_path)
  smb                   = Helper::Smb.new
  smb.local_path        = local_path
  smb.samba_umount()
end

#samba_upload(source, target, options = {}) ⇒ Object



386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
# File 'lib/depengine/dsl/deployment.rb', line 386

def samba_upload(source, target, options={})
  Helper.validates_presence_of source
  Helper.validates_presence_of target

  publisher = Publisher::Samba.new
  publisher.samba_share      = options[:samba_share]      || @cdb['samba_share']
  publisher.worker = self
  publisher.samba_mountpoints      = options[:samba_mountpoints]      || @cdb['samba_mountpoints']

  Helper.validates_presence_of publisher.samba_share, "Sambe share not set"
  Helper.validates_presence_of publisher.samba_mountpoints, "Sambe mountpoints not set"

  publisher.copy(File.join($recipe_config[:deploy_home], source), \
                   target, options)
end

#sed_stringsObject



544
545
546
# File 'lib/depengine/dsl/deployment.rb', line 544

def sed_strings()
  Sed.copy($recipe_config[:source],$recipe_config[:target], $recipe_config[:pattern],$recipe_config[:replacement])
end

#send_dweb_command(command, options = {}) ⇒ Object



305
306
307
308
309
310
311
312
313
314
315
# File 'lib/depengine/dsl/deployment.rb', line 305

def send_dweb_command(command, options={})
  Helper.validates_presence_of @cdb['staging_host'], "Staging Host not set"
  Helper.validates_presence_of @cdb['ssh_key_file_command'], "SSH keyfile not set"
  Helper.validates_presence_of @cdb['siteid'], "Siteid not set"

  publisher = Publisher::Dweb.new
  publisher.staging_host = @cdb['staging_host']
  publisher.ssh_key_file = @cdb['ssh_key_file_command']
  publisher.siteid       = @cdb['siteid']
  publisher.send_command(command, options)
end

#sendmail(options) ⇒ Object



441
442
443
444
445
446
447
448
449
450
451
# File 'lib/depengine/dsl/deployment.rb', line 441

def sendmail(options)
  Helper.validates_presence_of options[:from],    "Mail-FROM not set"
  Helper.validates_presence_of options[:to],      "Mail-TO not set"
  Helper.validates_presence_of options[:subject], "No mail subject set"
  Helper.validates_presence_of options[:body],    "No mail body set"
  Helper.validates_presence_of @cdb['smtp_host'], "SMTP host not set"

  helper = Helper::Mail.new
  helper.smtp_host = @cdb['smtp_host']
  helper.sendmail(options)
end

#set_cdb_parameter(key, value) ⇒ Object



200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/depengine/dsl/deployment.rb', line 200

def set_cdb_parameter(key, value)
  Helper.validates_presence_of $recipe_config['cdb_host'], \
                               "cdb_host parameter is missing"
  Helper.validates_presence_of $recipe_config['cdb_context'], \
                               "cdb_context parameter is missing"

  cdb          = Provider::CDB.new
  cdb.protocol = 'http'
  cdb.host     = $recipe_config['cdb_host']
  cdb.context  = $recipe_config['cdb_context']
  cdb.env      = $recipe_config[:env]

  cdb.set_parameter(File.join( $recipe_config[:env], \
                            $recipe_config[:module_name] ), key, value)
end

#set_cdb_parameter_4_app(module_name, app_name, key, value) ⇒ Object



216
217
218
219
220
221
222
223
224
225
226
227
228
229
# File 'lib/depengine/dsl/deployment.rb', line 216

def set_cdb_parameter_4_app(module_name, app_name, key, value)
  Helper.validates_presence_of $recipe_config['cdb_host'], \
                               "cdb_host parameter is missing"
  Helper.validates_presence_of $recipe_config['cdb_context'], \
                               "cdb_context parameter is missing"

  cdb          = Provider::CDB.new
  cdb.protocol = 'http'
  cdb.host     = $recipe_config['cdb_host']
  cdb.context  = $recipe_config['cdb_context']
  cdb.env      = $recipe_config['ENVIRONMENT']

  cdb.set_parameter(File.join( module_name, app_name ), key, value)
end

#sftp_chmod(path, permissions, options = {}) ⇒ Object



422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
# File 'lib/depengine/dsl/deployment.rb', line 422

def sftp_chmod(path, permissions, options={})
  Helper.validates_presence_of @cdb['ssh_key_file'], "SSH-keyfile not set"
  Helper.validates_presence_of path
  Helper.validates_presence_of permissions

  publisher = Publisher::Sftp.new
  publisher.remote_host  = options[:remote_host]  || @cdb['remote_host']
  publisher.remote_user  = options[:remote_user]  || @cdb['remote_user']
  publisher.ssh_key_file = options[:ssh_key_file] || @cdb['ssh_key_file']

  publisher.ssh_key_file = File.join(File.dirname($exec_file_path), \
                                     publisher.ssh_key_file)

  Helper.validates_presence_of publisher.remote_host, "Remote host not set"
  Helper.validates_presence_of publisher.remote_user, "Remote user not set"

  publisher.chmod(path, permissions, options)
end

#sftp_upload(source, target, options = {}) ⇒ Object



402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
# File 'lib/depengine/dsl/deployment.rb', line 402

def sftp_upload(source, target, options={})
  Helper.validates_presence_of @cdb['ssh_key_file'], "SSH-keyfile not set"
  Helper.validates_presence_of source
  Helper.validates_presence_of target

  publisher = Publisher::Sftp.new
  publisher.remote_host  = options[:remote_host]  || @cdb['remote_host']
  publisher.remote_user  = options[:remote_user]  || @cdb['remote_user']
  publisher.ssh_key_file = options[:ssh_key_file] || @cdb['ssh_key_file']

  publisher.ssh_key_file = File.join(File.dirname($exec_file_path), \
                                     publisher.ssh_key_file)

  Helper.validates_presence_of publisher.remote_host, "Remote host not set"
  Helper.validates_presence_of publisher.remote_user, "Remote user not set"

  publisher.copy(File.join($recipe_config[:deploy_home], source), \
                   target, options)
end

#tgz_file(tgz_file, source_dir, filename = nil) ⇒ Object



142
143
144
145
146
147
148
149
# File 'lib/depengine/dsl/deployment.rb', line 142

def tgz_file(tgz_file, source_dir, filename=nil)
  Helper.validates_presence_of @cdb['tar_bin']

  Processor.tgz_file(File.join($recipe_config[:deploy_home], tgz_file), \
                     File.join($recipe_config[:deploy_home], source_dir), \
                     filename,
                     @cdb['tar_bin'])
end

#tomcat_deploy(options = {}) ⇒ Object



648
649
650
651
652
653
654
655
656
657
658
659
660
# File 'lib/depengine/dsl/deployment.rb', line 648

def tomcat_deploy(options={})
  publisher = Publisher::Tomcat.new
  publisher.servers  = options[:servers] || @cdb['servers']
  publisher.runners = options[:runners] || @cdb['runners'] || publisher.servers
  publisher.initd_script  = options[:initd_script] || @cdb['initd_script']
  publisher.application_name  = options[:application_name] ||  $recipe_config[:application_name] || @cdb['application_name']
  publisher.catalina_home  = options[:catalina_home] || @cdb['catalina_home']
  publisher.tomcat_context  = options[:tomcat_context] || @cdb['tomcat_context']
  publisher.logfilename  = options[:logfilename] || @cdb['logfilename']
  publisher.check_host  = options[:check_host] || @cdb['check_host']
  publisher.worker  = self
  publisher.deploy(options)
end

#untgz_file(tgz_file, target_dir, filename = nil) ⇒ Object



151
152
153
154
155
156
157
158
# File 'lib/depengine/dsl/deployment.rb', line 151

def untgz_file(tgz_file, target_dir, filename=nil)
  Helper.validates_presence_of @cdb['tar_bin']

  Processor.untgz_file(File.join($recipe_config[:deploy_home], tgz_file), \
                       File.join($recipe_config[:deploy_home], target_dir), \
                       filename,
                       @cdb['tar_bin'])
end

#unzip_file(zip_file, target_dir, filename = nil) ⇒ Object



133
134
135
136
137
138
139
140
# File 'lib/depengine/dsl/deployment.rb', line 133

def unzip_file(zip_file, target_dir, filename=nil)
  Helper.validates_presence_of @cdb['unzip_bin']

  Processor.unzip_file(File.join($recipe_config[:deploy_home], zip_file), \
                       File.join($recipe_config[:deploy_home], target_dir), \
                       filename,
                       @cdb['unzip_bin'])
end