Skip to content

Commit

Permalink
Allow to set rails folder in host configuration file
Browse files Browse the repository at this point in the history
  • Loading branch information
dekart committed Nov 7, 2013
1 parent 5eefeb6 commit 796e719
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
6 changes: 5 additions & 1 deletion libexec/de-sc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ if ARGV.first == '--complete'
else
server = ARGV.first

rails_folder = SshHosts.remote_rails_folder(server)

puts "Connecting..."

SshHosts.remote_command(server, %{
echo Running console... && cd #{ server }/current; (if test -f script/console ; then ./script/console; else bundle exec rails c; fi)
echo Running console... && cd #{ rails_folder }/current; (if test -f script/console ; then ./script/console; else bundle exec rails c; fi)
})
end
6 changes: 5 additions & 1 deletion libexec/de-stl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ if ARGV.first == '--complete'
else
server = ARGV.first

rails_folder = SshHosts.remote_rails_folder(server)

puts "Connecting..."

SshHosts.remote_command(server, %{
tail -n 500 -f #{ server }/shared/log/production.log
tail -n 500 -f #{ rails_folder }/shared/log/production.log
})
end
18 changes: 17 additions & 1 deletion libexec/lib/ssh_hosts.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require "yaml"

module SshHosts
class << self
def host_list_autocomplete
Expand All @@ -8,8 +10,22 @@ def host_list_autocomplete

def remote_command(server, command)
system %{
ssh #{server} -t "bash -i -c '#{ command }'"
ssh #{server} -t "bash -i -c '. ~/.profile; #{ command }'"
}
end

def remote_rails_folder(server)
config_file = Dir[File.expand_path("~/.ssh/hosts/**/#{server}.yml")].first

if File.file?(config_file)
config = YAML.load_file(config_file)[server]

if config['de'] and config['de']['rails_folder']
return config['de']['rails_folder']
end
end

server
end
end
end

0 comments on commit 796e719

Please sign in to comment.