lib/kuzushi.rb in kuzushi-0.0.3 vs lib/kuzushi.rb in kuzushi-0.0.6
- old
+ new
@@ -1,9 +1,10 @@
require 'rubygems'
require 'json'
require 'restclient'
require 'ostruct'
+require 'rush'
class Kuzushi
def initialize(url)
@base_url = File.dirname(url)
@name = File.basename(url)
@@ -96,11 +97,11 @@
add_package "mdadm"
end
def process_mounts(m)
task "mount #{m.label}" do
- shell "mount -o #{m.options} -L #{m.label} #{m.label}"
+ shell "mkdir -p #{m.label} && mount -o #{m.options} -L #{m.label} #{m.label}"
end
end
def process_files(f)
fetch("/templates/#{f.template}") do |file|
@@ -111,11 +112,11 @@
end
def process_users(user)
(user.authorized_keys || []).each do |key|
task "add authorized_key for user #{user.name}" do
- shell "su - #{user.name} -c 'mkdir -p .ssh; echo \"#{key}\" >> .ssh/authorized_keys; chmod -R 600 .ssh'"
+ shell "su - #{user.name} -c 'mkdir -p .ssh; echo \"#{key}\" >> .ssh/authorized_keys; chmod -R 0600 .ssh'"
end
end
end
def set_scheduler(v)
@@ -163,11 +164,11 @@
tmp_dir = "/tmp/kuzushi"
Dir.mkdir(tmp_dir) unless File.exists?(tmp_dir)
file = "#{tmp_dir}/#{File.basename(file)}"
File.open(file,"w") do |f|
f.write(content)
- f.chmod(700)
+ f.chmod(0700)
end if content
block.call(file) if block
file
end
@@ -197,11 +198,14 @@
def get_array(key)
[ get(key) || [] ].flatten
end
def wait_for_volume(vol)
- puts "waiting for volume #{vol}"
+ until File.exists?("/sys/block/#{File.basename(vol)}") do
+ puts "waiting for volume #{vol}"
+ sleep 2
+ end
end
def start
puts "----"
@tasks.each do |t|
@@ -210,10 +214,11 @@
end
puts "----"
end
def shell(cmd, env = {})
- puts " SHELL: #{cmd}"
+ puts "# #{cmd}"
+ puts Rush.bash cmd, :env => env
end
def task(description, &blk)
@tasks << { :description => description, :blk => blk }
end