Skip to content
Browse files

rake resource. workaround for setting PATH to include gem bins

  • Loading branch information...
1 parent c1e0dd2 commit 874cdc8f0b7f3394d1390e7af65debb26820a66e @emiltin emiltin committed Jun 29, 2009
Showing with 149 additions and 33 deletions.
  1. +5 −0 bin/heal-local
  2. +5 −0 bin/test
  3. +25 −0 docs/notes
  4. +24 −0 examples/deep_nesting.rb
  5. +30 −0 examples/nested.rb
  6. +7 −20 ideal.rb
  7. +1 −0 lib/healing.rb
  8. +2 −2 lib/structure/base.rb
  9. +0 −7 lib/structure/cloud.rb
  10. +37 −0 lib/structure/resources/rake.rb
  11. +13 −4 lib/structure/root.rb
View
5 bin/heal-local
@@ -2,6 +2,11 @@
require File.dirname(__FILE__)+'/../lib/healing'
+#FIXME this is a workaround, since /etc/profile is not loaded when we go through Net::SSH, for some reason,
+#not are any of the other bash config files.....
+ENV['PATH'] = "#{ENV['PATH']}:/var/lib/gems/1.8/bin"
+
+
h = Healing::App::Worker.new
h.load_ideal 'ideal.rb'
h.heal
View
5 bin/test
@@ -0,0 +1,5 @@
+#!/usr/bin/env ruby
+
+ENV['PATH']=ENV['PATH']+':/var/lib/gems/1.8/bin'
+
+puts `env`
View
25 docs/notes
@@ -193,3 +193,28 @@ is this possible now?
each structure element have a machting lingo. the structure have a parallel 'lingo-structure' that can be traversed. the only problem is that when creating new elements, the parent is not found in the lingo that responds, but in the first lingo in the lingo chain.
+.............
+
+alright. things seems to work well again after some restucturing. new lingo chain seems to work very well, i can nest clouds, instances, recipes, run blocks, plugins, etc. i can use lingo and recipes in classes. very cool!
+
+what's next?
+- upload healing lib and user files separately
+- handle uploading of user files: ideals, recipes, plugins, templates...
+- running of specific ideal file on instances
+- improve git_repo to handle code updates, branches, etc
+- rename cloud uuid to cloud ref?
+- better handling of keys
+- better error/exception handling
+- improve mysql_ebs backup of original mysql folder on the system volume.
+- support running rake task on instances
+
+
+
+ssh call chain:
+
+ruby
+net::ssh is a pure ruby implementation, that constructs ssh commands and sends them
+ssh now we're at the instance
+bash $_ = ] $_ = hBc
+ruby
+backticks here both $_ and $_ are empty, and PATH is wrong
View
24 examples/deep_nesting.rb
@@ -0,0 +1,24 @@
+#deep nesting, showing how clouds can be nested to arbitrary depth.
+#note that an instances can contain subclouds or subinstances.
+
+cloud :music do
+ uuid 'op2nm1jhwe2x'
+ key '/Users/emiltin/.ec2/testpair'
+ dir '/music'
+ cloud :rhytmic do
+ uuid 'vmcfncnagagnc344'
+ dir '/music/rhytmic'
+ cloud :jazz do
+ dir '/music/rhytmic/jazz'
+ instance :bebop do
+ uuid '0vhjj348isjsj3fb'
+ dir '/music/rhytmic/jazz/bebop'
+ end
+ instance :slow do
+ uuid '7877vjujxhhfd2h'
+ dir '/music/rhytmic/jazz/slow'
+ end
+ end
+ end
+end
+
View
30 examples/nested.rb
@@ -0,0 +1,30 @@
+
+cloud :master_slave do
+ uuid '68u2hcjcdjj3'
+ key '/Users/emiltin/.ec2/testpair'
+
+ dir '/xx'
+
+ cloud :app do
+ uuid 'vmcfncnagagnc344'
+ instances 3
+ dir '/xx/yy'
+ rails_app 'poolparty_example', :repo => 'git://github.com/emiltin/poolparty_example.git', :environment => :production
+ end
+
+ cloud :db do
+ instance :master do
+ uuid '0vhjj348isjsj3fb'
+ dir '/xx/zz'
+ mysql_ebs 'vol-4943a020'
+ end
+ instance :slave do
+ uuid '7877vjujxhhfd2h'
+ dir '/xx/ww'
+ package 'mysql-client'
+ package 'mysql-server'
+ end
+ end
+
+end
+
View
27 ideal.rb
@@ -1,26 +1,13 @@
-cloud :master_slave do
+cloud :raking do
uuid '68u2hcjcdjj3'
key '/Users/emiltin/.ec2/testpair'
+ instances 1
- dir '/xx'
-
- cloud :app do
- uuid 'vmcfncnagagnc344'
- instances 3
- dir '/xx/yy'
- end
-
- cloud :db do
- instance :master do
- uuid '0vhjj348isjsj3fb'
- dir '/xx/zz'
- end
- instance :slave do
- uuid '7877vjujxhhfd2h'
- dir '/xx/ww'
- end
- end
-
+# mysql_ebs 'vol-4943a020'
+# rails_app '/poolparty_example', :repo => 'git://github.com/emiltin/poolparty_example.git', :environment => :production
+# rubygem 'rake'
+ rake "stats", :base => '/poolparty_example'
+ rake "log:clear", :base => '/poolparty_example'
end
View
1 lib/healing.rb
@@ -21,6 +21,7 @@ module Healing
require BASE+'/lib/structure/resources/dir'
require BASE+'/lib/structure/resources/package'
require BASE+'/lib/structure/resources/service'
+ require BASE+'/lib/structure/resources/rake'
require BASE+'/lib/structure/resources/rubygem'
require BASE+'/lib/structure/resources/execute'
require BASE+'/lib/structure/resources/repo'
View
4 lib/structure/base.rb
@@ -93,8 +93,8 @@ def heal_resources
def revert
end
- def run cmd
- Healing::App::Base.run_locally cmd
+ def run cmd, options={}
+ Healing::App::Base.run_locally cmd, options
end
def log str, level=0
View
7 lib/structure/cloud.rb
@@ -199,10 +199,3 @@ def reorder
end
end
end
-
-
-
-def cloud name, options={}, &block
- Healing::Structure::Root.new( options.merge(:name=>name), &block )
-end
-
View
37 lib/structure/resources/rake.rb
@@ -0,0 +1,37 @@
+require 'yaml'
+
+module Healing
+ module Structure
+ class Rake < Resource
+
+ def initialize parent, task, o={}
+ super parent, o.merge(:task => task)
+ end
+
+ def heal
+ describe_name
+ r = "rake #{options.flags} #{options.task}"
+ if options.base?
+ wd = run "pwd", :quiet => true
+ begin
+ run("cd #{options.base} && #{r} && cd #{wd}")
+ ensure
+ run "cd #{wd}"
+ end
+ else
+ puts run(r)
+ end
+ end
+
+ def describe_name
+ puts_title :rake, options.task
+ end
+
+ def describe_settings
+ puts_setting :base if options.base
+ puts_setting :flags if options.flags
+ end
+
+ end
+ end
+end
View
17 lib/structure/root.rb
@@ -80,11 +80,14 @@ def heal_remote
end
def show_instances
- list = map.instances.dup.select { |i| Cloud.clouds.find { |c| c.options.uuid==i.cloud_uuid } }
+ list = map.instances.map { |i| [i,Cloud.clouds.find { |c| c.options.uuid==i.cloud_uuid }] }
+ list.reject! {|p| p[1]==nil }
if list.any?
puts_row ['instance','state','cloud','address']
- map.instances.each do |i|
- c = Cloud.clouds.find { |c| c.options.uuid==i.cloud_uuid }
+ list.sort! { |a,b| a[1].depth<=>b[1].depth }
+ list.each do |pair|
+ i = pair[0]
+ c = pair[1]
cloud_name = c ? "#{' '*c.depth}#{c.options.name}" : '-'
puts_row [i.id,i.state,cloud_name,i.address]
end
@@ -121,4 +124,10 @@ def prune
end
end
-end
+end
+
+
+def cloud name, options={}, &block
+ Healing::Structure::Root.new( options.merge(:name=>name), &block )
+end
+

0 comments on commit 874cdc8

Please sign in to comment.
Something went wrong with that request. Please try again.