Class: VagrantPlugins::SPTSync::Command::Root

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-sptsync/commands/root.rb

Defined Under Namespace

Classes: SiteError

Instance Method Summary collapse

Constructor Details

#initialize(argv, env) ⇒ Root

Returns a new instance of Root.



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
# File 'lib/vagrant-sptsync/commands/root.rb', line 7

def initialize(argv, env)
  super
  @options = {
    :help => false,
    :server => "dev",
    :site => "share"
  }

  @opts = OptionParser.new do |opts|
    opts.banner = "Sync site to your local"
    opts.separator ""
    opts.separator "Usage: vagrant sptsync"

    opts.on("-e", "--server [SERVER]", [:dev, :qa, :stage, :stg], "Specifies the server to pulldown from (dev, qa, stage). Defaults to dev") do |server|
      puts "server: #{server}"
      @options[:server] = server
    end

    opts.on("-s", "--site [SITE]", "Specifies the site to pulldown. Defaults to share") do |site|
      puts "site: #{site}"
      @options[:site] = site
    end

    opts.on("-r", "--revision [VERSION]", "Specifies the verion of the site to pulldown. Defaults to 3.1") do |revision|
      puts "revision: #{revision}"
      @options[:revision] = revision
    end

    opts.on("-h", "--help", "run help") do |help|
      @options[:help] = true
    end
  end
end

Instance Method Details

#commandsObject



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
# File 'lib/vagrant-sptsync/commands/root.rb', line 63

def commands
  revision = @options[:revision] || '3.1'
  server = @options[:server]
  site = @options[:site]
  drush = "#{site}.v#{revision.gsub('.', '')}"
  files_dir = "/var/www/sites/virtual/deploy/shared/#{drush}/files/"
  server_name = "tn-#{server}-web00.lax.spehosting.com"
  commands = {
    "downloading files" => "sudo -E rsync --recursive --compress --times --rsh='ssh -l deploy' #{server_name}:#{files_dir} #{files_dir} --exclude=cdn --exclude=css --exclude=js --exclude=languages --exclude=styles --exclude=xmlsitemap",
    "setting file owner" => "sudo chown -R deploy:apache #{files_dir}",
    "setting css file owner" => "sudo chown -R apache:apache #{files_dir}css",
    "setting cdn file owner" => "sudo chown -R apache:apache #{files_dir}cdn",
    "setting file permissions" => "sudo chmod -R 2775 #{files_dir}",
    "dropping database" => "drush @#{drush} sql-drop -y && drush cc drush",
    "downloading database" => "ssh -l deploy #{server_name} drush @#{drush} sql-dump | drush @#{drush} sql-cli",
    "updating database" => "drush @#{drush} updb -y",
    "turning off css compressing" => "drush @#{drush} vset preprocess_css 0 --yes",
    "turning off js compressing" => "drush @#{drush} vset preprocess_js 0 --yes",
    "turning off block caching" => "drush @#{drush} vset block_cache 0 --yes",
    "turning off page caching" => "drush @#{drush} vset cache 0 --yes",
    "flushing block cache" => "drush @#{drush} vset cache_content_flush_cache_block 0 --yes",
    "flushing page cache" => "drush @#{drush} vset cache_content_flush_cache_page 0 --yes",
    "setting image permissions" => "drush @#{drush} vset image_allow_insecure_derivatives 1 --yes",
    "turning on error reporting" => "drush @#{drush} vset error_level 2 --yes",
    "turning on devel and theme_swapper" => "drush @#{drush} en devel theme_swapper -y",
    "setting devel permissions" => "drush @#{drush} php-eval '$permissions = array(\"access devel information\"); user_role_grant_permissions(4, $permissions);'",
    "disabling autologout, cdn, and constant contact" => "drush @#{drush} dis autologout cdn spt_constant_contact -y",
  }
  commands
end

#executeObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/vagrant-sptsync/commands/root.rb', line 41

def execute
  parse_options(@opts)
  if @options[:help]
    # Print the help for all the box commands.
    return help
  end

  self.validate

  with_target_vms(nil, single_target: true) do |vm|
    vm.config.exec.finalize! # TODO: do we have to call it explicitly?

    commands.each do |message, command|
      vm.env.ui.info(message, :color => :green, :new_line => true)
      vm.env.ui.info(command, :color => :cyan, :new_line => true)
      ssh_opts = { extra_args: [] }
      vm.action(:ssh_run, ssh_run_command: command, ssh_opts: ssh_opts)
    end

  end
end

#helpObject

Prints the help out for this command



106
107
108
# File 'lib/vagrant-sptsync/commands/root.rb', line 106

def help
  @env.ui.info(@opts.help, :prefix => false)
end

#validateObject



94
95
96
97
98
99
100
101
102
103
# File 'lib/vagrant-sptsync/commands/root.rb', line 94

def validate
  # command  = "drush @#{@options[:site]} status > /dev/null"
  # ssh_opts = { extra_args: ['-q'] } # make it quiet
  # with_target_vms(nil, single_target: true) do |vm|
  #   env = vm.action(:ssh_run, ssh_run_command: command, ssh_opts: ssh_opts)
  #   if env[:ssh_run_exit_status] != 0
  #     raise SiteError.new(@options[:site])
  #   end
  # end
end