Class: ServerRemote::Command

Inherits:
Object
  • Object
show all
Includes:
Util, SimpleCLI
Defined in:
lib/server_remote/server_remote.rb

Constant Summary

Constants included from Util

Util::DEFAULT_PROFILE

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Util

#app_root, #app_root=, #cd_to_app_action, #config, #config=, #config_path, #console_action, #default_options_path, #execute, #keyfile_option, #load_config, #parse_common_args, #remote_command, #remote_command_in_app, #scp_command, #scp_file_argument, #ssh_command, #tail_action, #user_and_host

Class Method Details

.start(app_root, args, options = {}) ⇒ Object



224
225
226
227
228
229
230
231
# File 'lib/server_remote/server_remote.rb', line 224

def self.start(app_root, args, options = {})
  remote = new(args, options.merge(:default => 'shell'))
  remote.app_root = app_root
  remote.parse_common_args
  remote.load_config
  remote.parse!
  remote.run
end

Instance Method Details

#cmd(*args) ⇒ Object



192
193
194
195
196
197
198
# File 'lib/server_remote/server_remote.rb', line 192

def cmd(*args)
  if args.empty?
    cmd_help
  else
    execute remote_command_in_app(args)
  end
end

#cmd_helpObject



184
185
186
187
188
189
190
# File 'lib/server_remote/server_remote.rb', line 184

def cmd_help
  %{
Summary: executes an arbitrary command on the server after a cd to the app path

usage: #{script_name} cmd <command>
}
end

#console(*args) ⇒ Object



172
173
174
# File 'lib/server_remote/server_remote.rb', line 172

def console(*args)
  execute remote_command_in_app(console_action)
end

#console_helpObject



168
169
170
# File 'lib/server_remote/server_remote.rb', line 168

def console_help
  'Summary: executes remote console'
end

#logtail(*args) ⇒ Object



180
181
182
# File 'lib/server_remote/server_remote.rb', line 180

def logtail(*args)
  execute remote_command_in_app(tail_action(args))
end

#logtail_helpObject



176
177
178
# File 'lib/server_remote/server_remote.rb', line 176

def logtail_help
  'Summary: executes remote tail -f on the log'
end

#scp(*args) ⇒ Object



215
216
217
218
219
220
221
# File 'lib/server_remote/server_remote.rb', line 215

def scp(*args)
  if args.empty?
    scp_help
  else
    execute scp_command + args.collect { |f| scp_file_argument(f) }.join(' ')
  end
end

#scp_helpObject



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

def scp_help
   %{
Summary: copies files over scp (prefix remote files with ':')

usage: #{script_name} scp <file1> <file2>

Example:

#{script_name} scp /local/file :/remote/file executes:
scp /local/file user@host:/remote/file

Any non colon prefixed arguments will be passed to scp.
}
end

#shell(*args) ⇒ Object



164
165
166
# File 'lib/server_remote/server_remote.rb', line 164

def shell(*args)
  execute ssh_command
end

#shell_helpObject



160
161
162
# File 'lib/server_remote/server_remote.rb', line 160

def shell_help
  "Summary: executes remote shell"
end

#usageObject



145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/server_remote/server_remote.rb', line 145

def usage
  puts <<EOH
Executes commands on a remote server over ssh. Configuration is in:
#{File.join(app_root, 'config', 'server_remote.yml')}

You can override the profile used with -p profile. The default profile is: #{config[:profile]}

Learn more in the readme:
#{File.join(GEM_ROOT, 'README.textile')}

EOH

  commands
end

#usage_helpObject



141
142
143
# File 'lib/server_remote/server_remote.rb', line 141

def usage_help
  "Summary: prints usage message"
end