Generate serial log file. And add the start and end flags into it. It's for generate docker's dmsg file in result root.
Signed-off-by: Wu Zhende wuzhende666@163.com --- providers/docker/docker.rb | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-)
diff --git a/providers/docker/docker.rb b/providers/docker/docker.rb index 8e489c6..e1ab057 100755 --- a/providers/docker/docker.rb +++ b/providers/docker/docker.rb @@ -18,6 +18,7 @@ names = Set.new %w[ defaults = relevant_defaults(names) SCHED_HOST = defaults['SCHED_HOST'] || '172.17.0.1' SCHED_PORT = defaults['SCHED_PORT'] || 3000 +LOG_DIR = '/srv/cci/serial/logs'
def get_url(hostname) "http://#%7BSCHED_HOST%7D:#%7BSCHED_PORT%7D/boot.container/hostname/#%7Bhostn..." @@ -82,12 +83,35 @@ def start_container(hostname, load_path, hash) docker_image = hash['docker_image'] system "#{ENV['CCI_SRC']}/sbin/docker-pull #{docker_image}" system( - { 'hostname' => hostname, 'docker_image' => docker_image, 'load_path' => load_path }, + { 'hostname' => hostname, + 'docker_image' => docker_image, + 'load_path' => load_path, + 'log_dir' => "#{LOG_DIR}/#{hostname}" + }, ENV['CCI_SRC'] + '/providers/docker/run.sh' ) clean_dir(load_path) end
+def record_runtime_log(hostname, start_time: Time.new, is_start: true, hash: {}) + log_file = "#{LOG_DIR}/#{hostname}" + if is_start + File.open(log_file, 'w') do |f| + # fluentd refresh time is 1s + # let fluentd to monitor this file first + sleep(2) + f.puts "\n#{start_time.strftime('%Y-%m-%d %H:%M:%S')} starting DOCKER" + f.puts "\n#{hash['job']}" + end + return start_time + end + + duration = ((Time.new - start_time) / 60).round(2) + File.open(log_file, 'a') do |f| + f.puts "\nTotal DOCKER duration: #{duration} minutes" + end +end + def main(hostname, queues) set_host2queues(hostname, queues) url = get_url hostname @@ -95,10 +119,14 @@ def main(hostname, queues) hash = parse_response url return del_host2queues(hostname) if hash.nil?
+ start_time = record_runtime_log(hostname, hash: hash) + load_path = build_load_path(hostname) load_initrds(load_path, hash) start_container(hostname, load_path, hash) + del_host2queues(hostname) + record_runtime_log(hostname, start_time: start_time, is_start: false) end
def loop_main(hostname, queues)