lib/fulmar/domain/task/optional/vhost.rb in fulmar-1.5.2 vs lib/fulmar/domain/task/optional/vhost.rb in fulmar-1.6.0

- old
+ new

@@ -1,23 +1,24 @@ require 'fulmar/domain/service/helper/vhost_helper' include Fulmar::Domain::Service::Helper::VhostHelper VHOST_DEFAULT_CONFIG = { webserver: 'nginx', - sites_enabled_dir: '../sites-enabled', - + sites_enabled_dir: '../sites-enabled' } vhost_count = 0 configuration.each { |_env, _target, data| vhost_count += 1 unless data[:vhost_template].blank? } namespace :vhost do configuration.each do |env, target, data| next if data[:vhost_template].blank? + task_environment = vhost_count > 1 ? ":#{env}" : '' + desc "Create a vhost for #{env}" - task (vhost_count > 1 ? "create:#{env}" : 'create') do + task "create#{task_environment}" do configuration.environment = env configuration.target = target configuration.merge(VHOST_DEFAULT_CONFIG) # Store remote_path for recovery @@ -34,21 +35,23 @@ config_file_name = "#{File.dirname(rendered_vhost_config)}/auto_vhost_#{configuration[:vhost_name]}.conf" FileUtils.mv rendered_vhost_config, config_file_name upload config_file_name config_remote_path = configuration[:sites_available_dir] + '/' + File.basename(config_file_name) remote_shell.run [ - "rm -f #{configuration[:sites_enabled_dir]}/#{File.basename(config_file_name)}", # remove any existing link - "ln -s #{config_remote_path} #{configuration[:sites_enabled_dir]}/#{File.basename(config_file_name)}", - "service #{configuration[:webserver]} reload" - ] + "rm -f #{configuration[:sites_enabled_dir]}/#{File.basename(config_file_name)}", # remove any existing link + "ln -s #{config_remote_path} #{configuration[:sites_enabled_dir]}/#{File.basename(config_file_name)}", + "service #{configuration[:webserver]} reload" + ] + FileUtils.rm config_file_name + # recover remote path configuration[:remote_path] = remote_path end desc "List existing vhosts for #{env}" - task (vhost_count > 1 ? "list:#{env}" : 'list') do + task "list#{task_environment}" do configuration.environment = env configuration.target = target configuration.merge(VHOST_DEFAULT_CONFIG) remote_shell.run 'ls -1' @@ -60,18 +63,18 @@ end end end desc "Delete a vhost for #{env}" - task (vhost_count > 1 ? "delete:#{env}" : 'delete'), [:name] do |_t, argv| + task "delete#{task_environment}", [:name] do |_t, argv| configuration.environment = env configuration.target = target configuration.merge(VHOST_DEFAULT_CONFIG) remote_shell.run [ - "rm auto_vhost_#{argv[:name]}.conf", - "rm #{configuration[:sites_enabled_dir]}/auto_vhost_#{argv[:name]}.conf", - "service #{configuration[:webserver] || 'nginx'} reload" - ] + "rm auto_vhost_#{argv[:name]}.conf", + "rm #{configuration[:sites_enabled_dir]}/auto_vhost_#{argv[:name]}.conf", + "service #{configuration[:webserver] || 'nginx'} reload" + ] end end end