startapp 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (156) hide show
  1. checksums.yaml +7 -0
  2. data/COPYRIGHT +1 -0
  3. data/LICENSE +11 -0
  4. data/README.md +95 -0
  5. data/Rakefile +6 -0
  6. data/autocomplete/rhc_bash +1672 -0
  7. data/bin/app +37 -0
  8. data/conf/express.conf +8 -0
  9. data/features/assets/deploy.tar.gz +0 -0
  10. data/features/core_feature.rb +191 -0
  11. data/features/deployments_feature.rb +129 -0
  12. data/features/domains_feature.rb +58 -0
  13. data/features/keys_feature.rb +37 -0
  14. data/features/members_feature.rb +166 -0
  15. data/lib/rhc/auth/basic.rb +64 -0
  16. data/lib/rhc/auth/token.rb +102 -0
  17. data/lib/rhc/auth/token_store.rb +53 -0
  18. data/lib/rhc/auth.rb +5 -0
  19. data/lib/rhc/autocomplete.rb +66 -0
  20. data/lib/rhc/autocomplete_templates/bash.erb +39 -0
  21. data/lib/rhc/cartridge_helpers.rb +118 -0
  22. data/lib/rhc/cli.rb +40 -0
  23. data/lib/rhc/command_runner.rb +185 -0
  24. data/lib/rhc/commands/account.rb +25 -0
  25. data/lib/rhc/commands/alias.rb +124 -0
  26. data/lib/rhc/commands/app.rb +726 -0
  27. data/lib/rhc/commands/apps.rb +20 -0
  28. data/lib/rhc/commands/authorization.rb +115 -0
  29. data/lib/rhc/commands/base.rb +174 -0
  30. data/lib/rhc/commands/cartridge.rb +329 -0
  31. data/lib/rhc/commands/clone.rb +66 -0
  32. data/lib/rhc/commands/configure.rb +20 -0
  33. data/lib/rhc/commands/create.rb +100 -0
  34. data/lib/rhc/commands/delete.rb +19 -0
  35. data/lib/rhc/commands/deploy.rb +32 -0
  36. data/lib/rhc/commands/deployment.rb +82 -0
  37. data/lib/rhc/commands/domain.rb +172 -0
  38. data/lib/rhc/commands/env.rb +142 -0
  39. data/lib/rhc/commands/force_stop.rb +17 -0
  40. data/lib/rhc/commands/git_clone.rb +34 -0
  41. data/lib/rhc/commands/logout.rb +51 -0
  42. data/lib/rhc/commands/logs.rb +21 -0
  43. data/lib/rhc/commands/member.rb +148 -0
  44. data/lib/rhc/commands/port_forward.rb +197 -0
  45. data/lib/rhc/commands/reload.rb +17 -0
  46. data/lib/rhc/commands/restart.rb +17 -0
  47. data/lib/rhc/commands/scp.rb +54 -0
  48. data/lib/rhc/commands/server.rb +40 -0
  49. data/lib/rhc/commands/setup.rb +60 -0
  50. data/lib/rhc/commands/show.rb +43 -0
  51. data/lib/rhc/commands/snapshot.rb +137 -0
  52. data/lib/rhc/commands/ssh.rb +51 -0
  53. data/lib/rhc/commands/sshkey.rb +97 -0
  54. data/lib/rhc/commands/start.rb +17 -0
  55. data/lib/rhc/commands/stop.rb +17 -0
  56. data/lib/rhc/commands/tail.rb +47 -0
  57. data/lib/rhc/commands/threaddump.rb +14 -0
  58. data/lib/rhc/commands/tidy.rb +17 -0
  59. data/lib/rhc/commands.rb +396 -0
  60. data/lib/rhc/config.rb +321 -0
  61. data/lib/rhc/context_helper.rb +121 -0
  62. data/lib/rhc/core_ext.rb +202 -0
  63. data/lib/rhc/coverage_helper.rb +33 -0
  64. data/lib/rhc/deployment_helpers.rb +111 -0
  65. data/lib/rhc/exceptions.rb +256 -0
  66. data/lib/rhc/git_helpers.rb +106 -0
  67. data/lib/rhc/help_formatter.rb +55 -0
  68. data/lib/rhc/helpers.rb +481 -0
  69. data/lib/rhc/highline_extensions.rb +479 -0
  70. data/lib/rhc/json.rb +51 -0
  71. data/lib/rhc/output_helpers.rb +260 -0
  72. data/lib/rhc/rest/activation.rb +11 -0
  73. data/lib/rhc/rest/alias.rb +42 -0
  74. data/lib/rhc/rest/api.rb +87 -0
  75. data/lib/rhc/rest/application.rb +348 -0
  76. data/lib/rhc/rest/attributes.rb +36 -0
  77. data/lib/rhc/rest/authorization.rb +8 -0
  78. data/lib/rhc/rest/base.rb +79 -0
  79. data/lib/rhc/rest/cartridge.rb +162 -0
  80. data/lib/rhc/rest/client.rb +650 -0
  81. data/lib/rhc/rest/deployment.rb +18 -0
  82. data/lib/rhc/rest/domain.rb +98 -0
  83. data/lib/rhc/rest/environment_variable.rb +15 -0
  84. data/lib/rhc/rest/gear_group.rb +16 -0
  85. data/lib/rhc/rest/httpclient.rb +145 -0
  86. data/lib/rhc/rest/key.rb +44 -0
  87. data/lib/rhc/rest/membership.rb +105 -0
  88. data/lib/rhc/rest/mock.rb +1042 -0
  89. data/lib/rhc/rest/user.rb +32 -0
  90. data/lib/rhc/rest.rb +148 -0
  91. data/lib/rhc/scp_helpers.rb +27 -0
  92. data/lib/rhc/ssh_helpers.rb +380 -0
  93. data/lib/rhc/tar_gz.rb +51 -0
  94. data/lib/rhc/usage_templates/command_help.erb +51 -0
  95. data/lib/rhc/usage_templates/command_syntax_help.erb +11 -0
  96. data/lib/rhc/usage_templates/help.erb +61 -0
  97. data/lib/rhc/usage_templates/missing_help.erb +1 -0
  98. data/lib/rhc/usage_templates/options_help.erb +12 -0
  99. data/lib/rhc/vendor/okjson.rb +600 -0
  100. data/lib/rhc/vendor/parseconfig.rb +178 -0
  101. data/lib/rhc/vendor/sshkey.rb +253 -0
  102. data/lib/rhc/vendor/zliby.rb +628 -0
  103. data/lib/rhc/version.rb +5 -0
  104. data/lib/rhc/wizard.rb +637 -0
  105. data/lib/rhc.rb +34 -0
  106. data/spec/coverage_helper.rb +82 -0
  107. data/spec/direct_execution_helper.rb +339 -0
  108. data/spec/keys/example.pem +23 -0
  109. data/spec/keys/example_private.pem +27 -0
  110. data/spec/keys/server.pem +19 -0
  111. data/spec/rest_spec_helper.rb +31 -0
  112. data/spec/rhc/assets/cert.crt +22 -0
  113. data/spec/rhc/assets/cert_key_rsa +27 -0
  114. data/spec/rhc/assets/empty.txt +0 -0
  115. data/spec/rhc/assets/env_vars.txt +7 -0
  116. data/spec/rhc/assets/env_vars_2.txt +1 -0
  117. data/spec/rhc/assets/foo.txt +1 -0
  118. data/spec/rhc/assets/targz_corrupted.tar.gz +1 -0
  119. data/spec/rhc/assets/targz_sample.tar.gz +0 -0
  120. data/spec/rhc/auth_spec.rb +442 -0
  121. data/spec/rhc/cli_spec.rb +186 -0
  122. data/spec/rhc/command_spec.rb +435 -0
  123. data/spec/rhc/commands/account_spec.rb +42 -0
  124. data/spec/rhc/commands/alias_spec.rb +333 -0
  125. data/spec/rhc/commands/app_spec.rb +777 -0
  126. data/spec/rhc/commands/apps_spec.rb +39 -0
  127. data/spec/rhc/commands/authorization_spec.rb +157 -0
  128. data/spec/rhc/commands/cartridge_spec.rb +665 -0
  129. data/spec/rhc/commands/clone_spec.rb +41 -0
  130. data/spec/rhc/commands/deployment_spec.rb +327 -0
  131. data/spec/rhc/commands/domain_spec.rb +401 -0
  132. data/spec/rhc/commands/env_spec.rb +493 -0
  133. data/spec/rhc/commands/git_clone_spec.rb +102 -0
  134. data/spec/rhc/commands/logout_spec.rb +86 -0
  135. data/spec/rhc/commands/member_spec.rb +247 -0
  136. data/spec/rhc/commands/port_forward_spec.rb +217 -0
  137. data/spec/rhc/commands/scp_spec.rb +77 -0
  138. data/spec/rhc/commands/server_spec.rb +69 -0
  139. data/spec/rhc/commands/setup_spec.rb +118 -0
  140. data/spec/rhc/commands/snapshot_spec.rb +179 -0
  141. data/spec/rhc/commands/ssh_spec.rb +163 -0
  142. data/spec/rhc/commands/sshkey_spec.rb +188 -0
  143. data/spec/rhc/commands/tail_spec.rb +81 -0
  144. data/spec/rhc/commands/threaddump_spec.rb +84 -0
  145. data/spec/rhc/config_spec.rb +407 -0
  146. data/spec/rhc/helpers_spec.rb +531 -0
  147. data/spec/rhc/highline_extensions_spec.rb +314 -0
  148. data/spec/rhc/json_spec.rb +30 -0
  149. data/spec/rhc/rest_application_spec.rb +258 -0
  150. data/spec/rhc/rest_client_spec.rb +752 -0
  151. data/spec/rhc/rest_spec.rb +740 -0
  152. data/spec/rhc/targz_spec.rb +55 -0
  153. data/spec/rhc/wizard_spec.rb +756 -0
  154. data/spec/spec_helper.rb +575 -0
  155. data/spec/wizard_spec_helper.rb +330 -0
  156. metadata +469 -0
@@ -0,0 +1,43 @@
1
+ require 'rhc/commands/app'
2
+
3
+ module RHC::Commands
4
+ class Show < App
5
+
6
+ summary "Show information about an application"
7
+ description <<-DESC
8
+ Display the properties of an application, including its URL, the SSH
9
+ connection string, and the Git remote URL. Will also display any
10
+ cartridges, their scale, and any values they expose.
11
+
12
+ The '--state' option will retrieve information from each cartridge in
13
+ the application, which may include cartridge specific text.
14
+
15
+ The '--configuration' option will display configuration values set in
16
+ the application. Use 'rhc configure-app' to configure.
17
+
18
+ To see information about the individual gears within an application,
19
+ use '--gears', including whether they are started or stopped and their
20
+ SSH host strings. Passing '--gears quota' will show the free and maximum
21
+ storage on each gear.
22
+
23
+ If you want to run commands against individual gears, use:
24
+
25
+ rhc ssh <app> --gears '<command>'
26
+
27
+ to run and display the output from each gear.
28
+
29
+ DESC
30
+ syntax "<app> [--namespace NAME]"
31
+ takes_application :argument => true
32
+ option ["--state"], "Get the current state of the cartridges in this application"
33
+ option ["--configuration"], "Get the current configuration values set in this application"
34
+ option ["--gears [quota|ssh]"], "Show information about the cartridges on each gear in this application. Pass 'quota' to see per gear disk usage and limits. Pass 'ssh' to print only the SSH connection strings of each gear."
35
+
36
+ def run(app_name)
37
+ self.class.superclass.instance_method(:show).bind(self).call app_name
38
+
39
+ 0
40
+ end
41
+
42
+ end
43
+ end
@@ -0,0 +1,137 @@
1
+ require 'rhc/commands/base'
2
+
3
+ module RHC::Commands
4
+ class Snapshot < Base
5
+ summary "Save the current state of your application locally"
6
+ syntax "<action>"
7
+ description <<-DESC
8
+ Snapshots allow you to export the current state of your OpenShift application
9
+ into an archive on your local system, and then to restore it later.
10
+
11
+ The snapshot archive contains the Git repository, dumps of any attached databases,
12
+ and any other information that the cartridges decide to export.
13
+
14
+ WARNING: Both 'save' and 'restore' will stop the application and then restart
15
+ after the operation completes.
16
+ DESC
17
+ alias_action :"app snapshot", :root_command => true
18
+ default_action :help
19
+
20
+ summary "Save a snapshot of your app to disk"
21
+ syntax "<application> [--filepath FILE] [--ssh path_to_ssh_executable]"
22
+ takes_application :argument => true
23
+ option ["-f", "--filepath FILE"], "Local path to save tarball (default: ./$APPNAME.tar.gz)"
24
+ option ["--deployment"], "Snapshot as a deployable file which can be deployed with 'rhc deploy'"
25
+ option ["--ssh PATH"], "Full path to your SSH executable with additional options"
26
+ alias_action :"app snapshot save", :root_command => true, :deprecated => true
27
+ def save(app)
28
+ ssh = check_ssh_executable! options.ssh
29
+ rest_app = find_app
30
+
31
+ raise RHC::DeploymentsNotSupportedException.new if options.deployment && !rest_app.supports?("DEPLOY")
32
+
33
+ ssh_uri = URI.parse(rest_app.ssh_url)
34
+ filename = options.filepath ? options.filepath : "#{rest_app.name}.tar.gz"
35
+
36
+ snapshot_cmd = options.deployment ? 'gear archive-deployment' : 'snapshot'
37
+ ssh_cmd = "#{ssh} #{ssh_uri.user}@#{ssh_uri.host} '#{snapshot_cmd}' > #{filename}"
38
+ debug ssh_cmd
39
+
40
+ say "Pulling down a snapshot to #{filename}..."
41
+
42
+ begin
43
+ if !RHC::Helpers.windows?
44
+ status, output = exec(ssh_cmd)
45
+ if status != 0
46
+ debug output
47
+ raise RHC::SnapshotSaveException.new "Error in trying to save snapshot. You can try to save manually by running:\n#{ssh_cmd}"
48
+ end
49
+ else
50
+ Net::SSH.start(ssh_uri.host, ssh_uri.user) do |ssh|
51
+ File.open(filename, 'wb') do |file|
52
+ ssh.exec! "snapshot" do |channel, stream, data|
53
+ if stream == :stdout
54
+ file.write(data)
55
+ else
56
+ debug data
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+ rescue Timeout::Error, Errno::EADDRNOTAVAIL, Errno::EADDRINUSE, Errno::EHOSTUNREACH, Errno::ECONNREFUSED, Net::SSH::AuthenticationFailed => e
63
+ debug e.backtrace
64
+ raise RHC::SnapshotSaveException.new "Error in trying to save snapshot. You can try to save manually by running:\n#{ssh_cmd}"
65
+ end
66
+ results { say "Success" }
67
+ 0
68
+ end
69
+
70
+ summary "Restores a previously saved snapshot"
71
+ syntax "<application> [--filepath FILE] [--ssh path_to_ssh_executable]"
72
+ takes_application :argument => true
73
+ option ["-f", "--filepath FILE"], "Local path to restore tarball"
74
+ option ["--ssh PATH"], "Full path to your SSH executable with additional options"
75
+ alias_action :"app snapshot restore", :root_command => true, :deprecated => true
76
+ def restore(app)
77
+ ssh = check_ssh_executable! options.ssh
78
+ rest_app = find_app
79
+ filename = options.filepath ? options.filepath : "#{rest_app.name}.tar.gz"
80
+
81
+ if File.exists? filename
82
+
83
+ include_git = RHC::Helpers.windows? ? true : RHC::TarGz.contains(filename, './*/git')
84
+ ssh_uri = URI.parse(rest_app.ssh_url)
85
+
86
+ ssh_cmd = "cat '#{filename}' | #{ssh} #{ssh_uri.user}@#{ssh_uri.host} 'restore#{include_git ? ' INCLUDE_GIT' : ''}'"
87
+
88
+ say "Restoring from snapshot #{filename}..."
89
+ debug ssh_cmd
90
+
91
+ begin
92
+ if !RHC::Helpers.windows?
93
+ status, output = exec(ssh_cmd)
94
+ if status != 0
95
+ debug output
96
+ raise RHC::SnapshotRestoreException.new "Error in trying to restore snapshot. You can try to restore manually by running:\n#{ssh_cmd}"
97
+ end
98
+ else
99
+ ssh = Net::SSH.start(ssh_uri.host, ssh_uri.user)
100
+ ssh.open_channel do |channel|
101
+ channel.exec("restore#{include_git ? ' INCLUDE_GIT' : ''}") do |ch, success|
102
+ channel.on_data do |ch, data|
103
+ say data
104
+ end
105
+ channel.on_extended_data do |ch, type, data|
106
+ say data
107
+ end
108
+ channel.on_close do |ch|
109
+ say "Terminating..."
110
+ end
111
+ File.open(filename, 'rb') do |file|
112
+ file.chunk(1024) do |chunk|
113
+ channel.send_data chunk
114
+ end
115
+ end
116
+ channel.eof!
117
+ end
118
+ end
119
+ ssh.loop
120
+ end
121
+ rescue Timeout::Error, Errno::EADDRNOTAVAIL, Errno::EADDRINUSE, Errno::EHOSTUNREACH, Errno::ECONNREFUSED, Net::SSH::AuthenticationFailed => e
122
+ debug e.backtrace
123
+ raise RHC::SnapshotRestoreException.new "Error in trying to restore snapshot. You can try to restore manually by running:\n#{ssh_cmd}"
124
+ end
125
+
126
+ else
127
+ raise RHC::SnapshotRestoreException.new "Archive not found: #{filename}"
128
+ end
129
+ results { say "Success" }
130
+ 0
131
+ end
132
+
133
+ protected
134
+ include RHC::SSHHelpers
135
+
136
+ end
137
+ end
@@ -0,0 +1,51 @@
1
+ require 'rhc/commands/base'
2
+ require 'resolv'
3
+ require 'rhc/git_helpers'
4
+ require 'rhc/cartridge_helpers'
5
+
6
+ module RHC::Commands
7
+ class Ssh < Base
8
+ suppress_wizard
9
+
10
+ summary "SSH into the specified application"
11
+ description <<-DESC
12
+ Connect to your application using SSH. This will connect to your primary gear
13
+ (the one with your Git repository and web cartridge) by default. To SSH to
14
+ other gears run 'rhc show-app --gears' to get a list of their SSH hosts.
15
+
16
+ You may run a specific SSH command by passing one or more arguments, or use a
17
+ different SSH executable or pass options to SSH with the '--ssh' option.
18
+ DESC
19
+ syntax "[--ssh path_to_ssh_executable] [--gears] [<app> --] <command>"
20
+ takes_application :argument => true
21
+ argument :command, "Command to run in the application's SSH session", ['--command COMMAND'], :type => :list, :optional => true
22
+ option ["--ssh PATH"], "Path to your SSH executable or additional options"
23
+ option ["--gears"], "Execute this command on all gears in the app. Requires a command."
24
+ option ["--limit INTEGER"], "Limit the number of simultaneous SSH connections opened with --gears (default: 5).", :type => Integer, :default => 5
25
+ option ["--raw"], "Output only the data returned by each host, no hostname prefix."
26
+ alias_action 'app ssh', :root_command => true
27
+ def run(_, command)
28
+ raise ArgumentError, "--gears requires a command" if options.gears && command.blank?
29
+ raise ArgumentError, "--limit must be an integer greater than zero" if options.limit && options.limit < 1
30
+
31
+ ssh = check_ssh_executable! options.ssh
32
+
33
+ if options.gears
34
+ run_on_gears(command.join(' '), find_app(:with_gear_groups => true))
35
+ 0
36
+ else
37
+ rest_app = find_app
38
+ $stderr.puts "Connecting to #{rest_app.ssh_string.to_s} ..." unless command.present?
39
+
40
+ debug "Using user specified SSH: #{options.ssh}" if options.ssh
41
+
42
+ command_line = [ ssh.split, rest_app.ssh_string.to_s, command].flatten.compact
43
+ debug "Invoking Kernel.exec with #{command_line.inspect}"
44
+ Kernel.send(:exec, *command_line)
45
+ end
46
+ end
47
+
48
+ protected
49
+ include RHC::SSHHelpers
50
+ end
51
+ end
@@ -0,0 +1,97 @@
1
+ require 'rhc/commands/base'
2
+
3
+ module RHC::Commands
4
+ class Sshkey < Base
5
+ include RHC::SSHHelpers
6
+
7
+ summary 'Add and remove keys for Git and SSH'
8
+ syntax '<action>'
9
+ description <<-DESC
10
+ OpenShift uses public keys to securely access your application source
11
+ code and to control access to your application gears via SSH. Your
12
+ account may have one or more public SSH keys associated with it, and
13
+ any computer with the private SSH key will be able to download code
14
+ from Git or SSH to the application.
15
+
16
+ Depending on your operating system, you may have to ensure that both
17
+ Git and the local SSH installation have access to your keys. Running
18
+ the 'setup' command is any easy way to get your first key created and
19
+ uploaded.
20
+ DESC
21
+ default_action :list
22
+
23
+ summary 'Display all the SSH keys for your account'
24
+ syntax ''
25
+ def list
26
+ keys = rest_client.sshkeys.each{ |key| paragraph{ display_key(key) } }
27
+
28
+ success "You have #{keys.length} SSH keys associated with your account."
29
+
30
+ 0
31
+ end
32
+
33
+ summary 'Show the SSH key with the given name'
34
+ syntax '<name>'
35
+ argument :name, 'SSH key to display', []
36
+ def show(name)
37
+ key = rest_client.find_key(name)
38
+ display_key(key)
39
+
40
+ 0
41
+ end
42
+
43
+ summary 'Add SSH key to your account'
44
+ syntax '<name> <path to SSH key file>'
45
+ argument :name, 'Name for this key', []
46
+ argument :key, 'SSH public key filepath', [], :optional => true
47
+ option ['--confirm'], 'Bypass key validation'
48
+ option ['--type TYPE'], 'Provide the key type directly if no key file is given'
49
+ option ['--content CONTENT'], 'Provide the key content directly if no key file is given'
50
+ def add(name, key_path=nil)
51
+
52
+ if key_path
53
+ type, content, comment = ssh_key_triple_for(key_path)
54
+ elsif options[:type].present? and options[:content].present?
55
+ type = options[:type]
56
+ content = options[:content]
57
+ else
58
+ raise ArgumentError, "You must either provide a key file, or the key type and content"
59
+ end
60
+
61
+ if type == 'krb5-principal'
62
+ # TODO: validate krb5?
63
+ else
64
+ # validate the user input before sending it to the server
65
+ begin
66
+ Net::SSH::KeyFactory.load_data_public_key "#{type} #{content}"
67
+ rescue NotImplementedError, OpenSSL::PKey::PKeyError, Net::SSH::Exception => e
68
+ debug e.inspect
69
+ if options.confirm
70
+ warn 'The key you are uploading is not recognized. You may not be able to authenticate to your application through Git or SSH.'
71
+ else
72
+ raise ::RHC::KeyDataInvalidException.new("File '#{key_path}' does not appear to be a recognizable key file (#{e}). You may specify the '--confirm' flag to add the key anyway.") if key_path
73
+ raise ::RHC::KeyDataInvalidException.new("The provided type and content does not appear to be a recognizable key (#{e}). You may specify the '--confirm' flag to add the key anyway.")
74
+ end
75
+ end
76
+ end
77
+
78
+ rest_client.add_key(name, content, type)
79
+ results { say key_path ? "SSH key #{key_path} has been added as '#{name}'" : "SSH key '#{name}' has been added" }
80
+
81
+ 0
82
+ end
83
+
84
+ summary 'Remove SSH key from your account'
85
+ syntax '<name>'
86
+ alias_action :delete, :deprecated => true
87
+ argument :name, 'Name of SSH key to remove'
88
+ def remove(name)
89
+ say "Removing the key '#{name} ... "
90
+ rest_client.delete_key(name)
91
+
92
+ success "removed"
93
+
94
+ 0
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,17 @@
1
+ require 'rhc/commands/app'
2
+
3
+ module RHC::Commands
4
+ class Start < App
5
+
6
+ summary "Start the application"
7
+ syntax "<app> [--namespace NAME]"
8
+ takes_application :argument => true
9
+
10
+ def run(app)
11
+ self.class.superclass.instance_method(:start).bind(self).call app
12
+
13
+ 0
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ require 'rhc/commands/app'
2
+
3
+ module RHC::Commands
4
+ class Stop < App
5
+
6
+ summary "Stop the application"
7
+ syntax "<app> [--namespace NAME]"
8
+ takes_application :argument => true
9
+
10
+ def run(app)
11
+ self.class.superclass.instance_method(:stop).bind(self).call app
12
+
13
+ 0
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,47 @@
1
+ require 'rhc/commands/base'
2
+ require 'rhc/config'
3
+ require 'rhc/ssh_helpers'
4
+
5
+ module RHC::Commands
6
+ class Tail < Base
7
+ include RHC::SSHHelpers
8
+
9
+ summary "Tail the logs of an application"
10
+ syntax "<application>"
11
+ takes_application :argument => true
12
+ option ["-o", "--opts options"], "Options to pass to the server-side (linux based) tail command (applicable to tail command only) (-f is implicit. See the linux tail man page full list of options.) (Ex: --opts '-n 100')"
13
+ option ["-f", "--files files"], "File glob relative to app (default <application_name>/logs/*) (optional)"
14
+ option ["-g", "--gear ID"], "Tail only a specific gear"
15
+ #option ["-c", "--cartridge name"], "Tail only a specific cartridge"
16
+ alias_action :"app tail", :root_command => true, :deprecated => true
17
+ def run(app_name)
18
+ rest_app = find_app(:include => :cartridges)
19
+ ssh_url = options.gear ? rest_app.gear_ssh_url(options.gear) : rest_app.ssh_url
20
+
21
+ tail('*', URI(ssh_url), options)
22
+
23
+ 0
24
+ end
25
+
26
+ private
27
+ #Application log file tailing
28
+ def tail(cartridge_name, ssh_url, options)
29
+ debug "Tail in progress for cartridge #{cartridge_name}"
30
+
31
+ host = ssh_url.host
32
+ uuid = ssh_url.user
33
+
34
+ file_glob = options.files ? options.files : "#{cartridge_name}/log*/*"
35
+ remote_cmd = "tail#{options.opts ? ' --opts ' + Base64::encode64(options.opts).chomp : ''} #{file_glob}"
36
+ ssh_cmd = "ssh -t #{uuid}@#{host} '#{remote_cmd}'"
37
+ begin
38
+ #Use ssh -t to tail the logs
39
+ debug ssh_cmd
40
+ ssh_ruby(host, uuid, remote_cmd, false, true)
41
+ rescue
42
+ warn "You can tail this application directly with:\n#{ssh_cmd}"
43
+ raise
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,14 @@
1
+ require 'rhc/commands/base'
2
+ module RHC::Commands
3
+ class Threaddump < Base
4
+ summary "Trigger a thread dump for JBoss and Ruby apps"
5
+ syntax "<application>"
6
+ takes_application :argument => true
7
+ def run(app)
8
+ rest_app = find_app
9
+ rest_app.threaddump.messages.each { |m| say m }
10
+
11
+ 0
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,17 @@
1
+ require 'rhc/commands/app'
2
+
3
+ module RHC::Commands
4
+ class Tidy < App
5
+
6
+ summary "Clean out the application's logs and tmp directories and tidy up the git repo on the server"
7
+ syntax "<app> [--namespace NAME]"
8
+ takes_application :argument => true
9
+
10
+ def run(app)
11
+ self.class.superclass.instance_method(:tidy).bind(self).call app
12
+
13
+ 0
14
+ end
15
+
16
+ end
17
+ end