Class: Ridoku::Run

Inherits:
Base
  • Object
show all
Defined in:
lib/ridoku/run.rb

Constant Summary

Constants inherited from Base

Base::POSTGRES_GROUP_NAME

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

base_command, color_code_logs, configure_ec2_client, configure_iam_client, configure_instance_roles, configure_opsworks_client, configure_roles, configure_service_roles, create_app, create_role, deploy, execute_recipes, extract_instance_ids, fetch_account, fetch_app, fetch_instance, fetch_layer, fetch_permissions, fetch_roles, fetch_stack, get_instances_for_layer, get_layer_ids, if_debug?, initialize_app_environment, instance_by_id, instance_role_configured?, load_config, monitor_deployment, postgresql_group_exists?, pretty_instances, roles_configured?, rollback, run_command, save_app, save_config, save_layer, save_stack, select_instances, service_role_configured?, standard_deploy, update_cookbooks, update_pg_security_group, update_pg_security_groups_in_all_regions, valid_instances?

Instance Attribute Details

#environmentObject

Returns the value of attribute environment.



11
12
13
# File 'lib/ridoku/run.rb', line 11

def environment
  @environment
end

Class Method Details

.command(command = nil, relative_command = true) ⇒ Object



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
# File 'lib/ridoku/run.rb', line 46

def command(command = nil, relative_command = true)
  Base.fetch_app
  Base.fetch_permissions
  
  Base.fetch_stack
  
  # stupid fucking escaping bullshit
  # So, ruby escapes, so does bash, so does ssh
  # (all interpreter layers)
  # Sooo, we have to have an OMFG ridiculous number of backslashes...
  # to escape one mother fucking value.

  # TODO: The entire 'run' system is fucked.  Rethink it.
  command.gsub!(/\$/, '\\'*14 + '$') if command

  environment =
    Base.custom_json['deploy'][Base.app[:shortname]]['app_env']

  fail Ridoku::NoSshAccess.new unless
    Base.permissions[:permissions].first[:allow_ssh]
  
  if Base.permissions[:permissions].first[:allow_sudo]
    prefix = "sudo su #{Base.config[:shell_user] || 'root'} -c "
  else
    prefix = ''
  end

  environ = environment.map do |key, val|
    "#{key}='#{val}'"
  end.join(' ')

  dir = "/srv/www/#{Base.app[:shortname]}/current"
  chdir = "cd #{dir}"
  path = "PATH=/usr/local/bin:#{dir}/script/:${PATH}"
  network_path = create_ssh_path

  relative = relative_command ? '/usr/bin/env' : ''

  bash_command = (command && "-c \\\\\\\"#{chdir} && #{relative} #{command}\\\\\\\"") || ''

  ssh_command = [
    "-t #{network_path}",
    %Q("#{prefix} \\"#{environ} #{path} bash #{bash_command}\\"")
  ]

  ssh_command.unshift("-i #{Base.config[:ssh_key]}") if
    Base.config[:ssh_key]

  ssh_command.unshift("/usr/bin/env ssh").join(' ')
end

.create_ssh_path(instance = nil) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/ridoku/run.rb', line 30

def create_ssh_path(instance = nil)
  Base.fetch_instance
  Base.

  instance ||= Base.select_instances(Base.config[:instances]).first

  unless instance
    $stderr.puts 'Unable to find a valid instance.'
    print_run_help
    exit 1
  end

  username = Base.[:user][:user_name].gsub(/[.]/, '')
  "#{username}@#{instance[:elastic_ip] || instance[:public_ip]}"
end

Instance Method Details

#runObject



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/ridoku/run.rb', line 13

def run      
  command = Base.config[:command]
  sub_command = (command.length > 0 && command[1]) || nil

  case sub_command
  when 'command', nil
    run_command
  when 'shell'
    shell
  else
    print_run_help
  end
end