while(true)
log.info "Build Server[#{option[:name]}] Start - PORT:[#{option[:port]}]"
# Start child process
- cmd = Utils.execute_shell_generate("#{File.dirname(__FILE__)}/build-svr start -n #{option[:name]} -p #{option[:port]} --CHILD")
+ cmd = Utils.generate_shell_command("#{File.dirname(__FILE__)}/build-svr start -n #{option[:name]} -p #{option[:port]} --CHILD")
IO.popen(cmd)
pid = Process.wait
break
elsif ($?.exitstatus == 99) then # DIBS UPGRADE
cmd = "#{File.dirname(__FILE__)}/upgrade -l #{File.dirname(__FILE__)} -S -t BUILDSERVER -n #{option[:name]} -p #{option[:port]}"
- cmd = Utils.execute_shell_generate(cmd)
+ cmd = Utils.generate_shell_command(cmd)
puts cmd
Utils.spawn(cmd)
log.info cmd
def git_cmd(cmd, working_dir, log)
build_command = "cd \"#{working_dir}\";#{@server.git_bin_path} #{cmd}"
- ret = Utils.execute_shell_with_log(build_command,log)
-
- return ret
+ pid, status = Utils.execute_shell_with_log(build_command,log.path)
+ if status.exitstatus != 0 then
+ return false
+ else
+ return true
+ end
end
env_def =
"BUILD_TARGET_OS=#{os} \
- TARGET_OS=#{os} \
- TARGET_OS_CATEGORY=#{os_category} \
- SRCDIR=\"#{src_path2}\" \
- ROOTDIR=\"#{build_root_dir}\" \
- VERSION=\"#{version}\" "
+TARGET_OS=#{os} \
+TARGET_OS_CATEGORY=#{os_category} \
+SRCDIR=\"#{src_path2}\" \
+ROOTDIR=\"#{build_root_dir}\" \
+VERSION=\"#{version}\" "
# check script file
script_file = "#{src_path}/package/build.#{@host_os}"
f.puts "#{target}"
f.puts "echo \"success\""
end
- Utils.execute_shell_with_log( "chmod +x #{src_path}/.build.sh", @log )
+ Utils.execute_shell( "chmod +x #{src_path}/.build.sh", @log )
build_command = "cd \"#{src_path}\";" + env_def + "./.build.sh"
# execute script
- if not Utils.execute_shell_with_log( build_command, @log ) then
+ pid, status = Utils.execute_shell_with_log( build_command, @log.path )
+ if status.exitstatus != 0 then
@log.error( "Failed on build script: \"#{target}\"", Log::LV_USER)
return false
else
- Utils.execute_shell_with_log( "rm -rf #{src_path}/.build.sh", @log )
+ Utils.execute_shell( "rm -rf #{src_path}/.build.sh", @log )
return true
end
end
# zip
@log.info( "Creating package file ... #{pkg.package_name}_#{pkg.version}_#{os}.zip", Log::LV_USER)
@log.info("cd \"#{install_dir}\"; zip -r -y #{src_path}/#{pkg.package_name}_#{pkg.version}_#{os}.zip *")
- Utils.execute_shell_with_log("cd \"#{install_dir}\"; zip -r -y #{src_path}/#{pkg.package_name}_#{pkg.version}_#{os}.zip *", @log)
+ Utils.execute_shell_with_log("cd \"#{install_dir}\"; zip -r -y #{src_path}/#{pkg.package_name}_#{pkg.version}_#{os}.zip *", @log.path)
if not File.exist? "#{src_path}/#{pkg.package_name}_#{pkg.version}_#{os}.zip" then
return false
end
--- /dev/null
+#!/usr/bin/ruby
+
+require 'logger'
+
+# parse arguments
+cmd = ARGV[0]
+log_path = ARGV[1]
+
+# if log path specified, generate log
+if not log_path.nil? then
+ # create logger
+ log = Logger.new(log_path)
+
+ # execute and write log
+ IO.popen("#{cmd} 2>&1") { |io|
+ io.each { |line|
+ log.info line
+ }
+ }
+
+ # return exit code
+ exit $?.exitstatus
+#$?.to_i
+else
+ # execute command & wait
+ pipe = IO.popen("#{cmd}")
+ pid, status = Process.waitpid2(pipe.pid)
+
+ # return exit code
+ if pid.nil? or status.nil? then
+ exit 1
+ else
+ exit status.exitstatus
+ end
+end
return 0
end
- def Utils.execute_shell_generate(cmd, os_category = nil)
- result_lines = []
+ def Utils.generate_shell_command(cmd, os_category = nil)
if os_category.nil? then os_category = get_os_category( HOST_OS ) end
if os_category == "windows" then
def Utils.execute_shell(cmd, os_category = nil)
ret = false
- if os_category.nil? then os_category = get_os_category( HOST_OS ) end
-
- if os_category == "windows" then
- mingw_path = "sh.exe -c "
- cmd = cmd.gsub("\"", "\\\"")
- cmd = mingw_path + "\"#{cmd}\""
- end
+
+ # generate command
+ cmd = generate_shell_command(cmd, os_category)
`#{cmd}`
if $?.to_i == 0 then ret = true else ret = false end
def Utils.execute_shell_return(cmd, os_category = nil)
result_lines = []
- if os_category.nil? then os_category = get_os_category( HOST_OS ) end
-
- if os_category == "windows" then
- mingw_path = "sh.exe -c "
- cmd = cmd.gsub("\"", "\\\"")
- cmd = mingw_path + "\"#{cmd}\""
- end
+ # generate command
+ cmd = generate_shell_command(cmd, os_category)
# get result
IO.popen("#{cmd} 2>&1") { |io|
end
def Utils.execute_shell_return_ret(cmd, os_category = nil)
- if os_category.nil? then os_category = get_os_category( HOST_OS ) end
- if os_category == "windows" then
- mingw_path = "sh.exe -c "
- cmd = cmd.gsub("\"", "\\\"")
- cmd = mingw_path + "\"#{cmd}\""
- end
+ # generate command
+ cmd = generate_shell_command(cmd, os_category)
return `#{cmd}`
end
- def Utils.execute_shell_with_log(cmd, log, os_category = nil)
- if os_category.nil? then os_category = get_os_category( HOST_OS ) end
+ # create process and log its all output(stderr, stdout)
+ # can decide whether wait or not
+ def Utils.execute_shell_with_log(cmd, log_path, wait=true)
- if os_category == "windows" then
- mingw_path = "sh.exe -c "
- cmd = cmd.gsub("\"", "\\\"")
- cmd = mingw_path + "\"#{cmd}\""
- end
+ # call execute
+ cmd = "'#{File.dirname(__FILE__)}/execute_with_log' '#{cmd}' '#{log_path}'"
+
+ # generate command
+ cmd = generate_shell_command(cmd, nil)
# print log
- IO.popen("#{cmd} 2>&1") { |io|
- io.each do |line|
- log.output line
- end
- }
-
- if $?.to_i == 0 then
- return true
- else
- return false
- end
+ pipe = IO.popen("#{cmd} 2>&1")
+ if wait then
+ return Process.waitpid2(pipe.pid)
+ else
+ return [pipe.pid,nil]
+ end
end
+
def Utils.spawn(cmd, os_category = nil)
if os_category.nil? then os_category = get_os_category( HOST_OS ) end
logger.info "Downloading #{url}"
if is_remote then
- ret = Utils.execute_shell_with_log( "wget #{url} -O #{fullpath} -nv", logger )
+ pid,status = Utils.execute_shell_with_log( "wget #{url} -O #{fullpath} -nv", logger )
+ ret = status.exitstatus != 0 ? false : true
#ret = Utils.execute_shell( "wget #{url} -O #{fullpath} -q")
else
if not File.exist? url then
cmd = "#{UPGRADE_CMD} -I -l #{dibs_path} -u #{pkg_svr_url}"
end
- cmd = Utils.execute_shell_generate(cmd)
+ cmd = Utils.generate_shell_command(cmd)
Utils.spawn(cmd)
else
end
# Start Build server
- cmd = Utils.execute_shell_generate("#{dibs_path}/build-svr start -n #{svr_name} -p #{svr_port}")
+ cmd = Utils.generate_shell_command("#{dibs_path}/build-svr start -n #{svr_name} -p #{svr_port}")
Utils.spawn(cmd)
log.info("Upgrade Complete", Log::LV_USER)
else # PACKAGE SERVER
# Start Build server
- cmd = Utils.execute_shell_generate("#{dibs_path}/pkg-svr start -n #{svr_name} -p #{svr_port}")
+ cmd = Utils.generate_shell_command("#{dibs_path}/pkg-svr start -n #{svr_name} -p #{svr_port}")
Utils.spawn(cmd)
log.info("Upgrade Complete", Log::LV_USER)