modules/hadoop1/hadoop1.rb in nuri-0.5.3 vs modules/hadoop1/hadoop1.rb in nuri-0.5.4

- old
+ new

@@ -22,19 +22,19 @@ def install(p={}) model = OpenStruct.new(@model) # add group hadoop - if `grep '^#{model.group}' /etc/group`.length <= 0 + if %x[grep '^#{model.group}' /etc/group].length <= 0 log.info "adding group #{model.group}" shell "echo '#{model.group}:x:8000:' >> /etc/group" else log.info "group #{model.group} is already exist" end # add user hadoop - if `grep '^#{model.user}' /etc/passwd`.length <= 0 + if %x[grep '^#{model.user}' /etc/passwd].length <= 0 log.info "adding user #{model.user}" shell "echo '#{model.user}:x:8000:8000::#{model.home}:/bin/bash' >> /etc/passwd && echo '#{model.user}:#{model.password}:15958:0:99999:7:::' >> /etc/shadow" else log.info "user #{model.user} is already exist" @@ -44,15 +44,17 @@ log.info "create hadoop home directory: #{model.home}" shell "mkdir -p #{model.home}" if !::File.exist?(model.home) # download and extract hadoop binaries log.info "download and install hadoop binaries" - source = (model.source[-7,7] == '.tar.gz' or model.source[-4,4] == '.tgz' ? model.source : "#{model.source}/hadoop-#{model.version}/hadoop-#{model.version}.tar.gz") + #source = (model.source[-7,7] == '.tar.gz' or model.source[-4,4] == '.tgz' ? model.source : "#{model.source}/hadoop-#{model.version}/hadoop-#{model.version}.tar.gz") + source = (model.source[-7,7] == '.tar.gz' or model.source[-4,4] == '.tgz' ? model.source : "#{model.source}/hadoop-#{model.version}.tar.gz") file = source.split('/').last.to_s basename = (::File.extname(file) == '.gz' ? ::File.basename(file, '.tar.gz') : ::File.basename(file, ::File.extname(file))) destination = "#{model.home}/#{file}" +log.info "download #{source} to #{destination}" download source, destination return false if not ::File.exist?(destination) shell "cd #{model.home} && tar xvzf #{file} && rm -f #{file} && bash -c 'cd #{model.home}/#{basename} && shopt -s dotglob && mv * .. && cd .. && rm -rf #{basename}'" @@ -90,12 +92,14 @@ def start(p={}) pids = self.pids services.each { |name| pid = pids[name] if pid <= 0 - cmd = "#{@model['home']}/bin/hadoop-daemon.sh start #{name}" - log.info `su -c '#{cmd} && sleep 3' #{@model['user']}` + cmd = "su -c '#{@model['home']}/bin/hadoop-daemon.sh start #{name} && sleep 3' #{@model['user']}" + pid = spawn(cmd) + Process.wait pid + #log.info %x[sudo su -c '#{cmd} && sleep 3' #{@model['user']}] end } running? end @@ -103,12 +107,14 @@ def stop(p={}) pids = self.pids services.reverse.each { |name| pid = pids[name] if pid > 0 - cmd = "#{@model['home']}/bin/hadoop-daemon.sh stop #{name}" - log.info `su -c '#{cmd}' #{@model['user']}` + cmd = "su -c '#{@model['home']}/bin/hadoop-daemon.sh stop #{name}' #{@model['user']}" + pid = spawn(cmd) + Process.wait pid + #log.info %x[sudo su -c '#{cmd}' #{@model['user']}] end } self.pids.each { |name,pid| begin @@ -139,11 +145,11 @@ end end def java_home return @model['java_home'] if @model['java_home'].to_s.strip.length > 0 - java = resolve_link(`which java`.strip) + java = resolve_link(%x[which java].strip) return '' if java.length <= 0 ::File.expand_path(java + '/../../') end def running? @@ -156,11 +162,11 @@ end def pids data = {} services.each { |name| - data[name] = `ps axf | grep java | grep -v grep | grep hadoop | grep Dproc_#{name}`.to_s.strip.split(' ', 2)[0].to_i + data[name] = %x[ps axf | grep java | grep -v grep | grep hadoop | grep Dproc_#{name}].to_s.strip.split(' ', 2)[0].to_i } data end end @@ -183,11 +189,11 @@ end def uninstall(p={}) super - shell "rm -rf #{model.data_dir}" + shell "rm -rf #{@model['data_dir']}" not installed? end ############################## @@ -204,11 +210,11 @@ def map { 'user' => @model['user'], - 'master' => `hostname`.strip, + 'master' => resolve("$." + Sfp::Agent.whoami? + ".sfpAddress"), #'master' => %x[hostname].strip, 'java_home' => java_home, 'tmp_dir' => @model['data_dir'], 'replication' => @model['replication'], } end @@ -238,9 +244,10 @@ def map { 'user' => @model['user'], 'master' => resolve(@model['master'] + '.parent.sfpAddress'), 'java_home' => java_home, + 'tmp_dir' => @model['data_dir'], 'replication' => resolve(@model['master'] + '.replication') } end def installed?