From add79d79023854621e5dd2e977bfd8ccaa66c8c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miquel=20Sabat=C3=A9=20Sol=C3=A0?= Date: Fri, 22 Jan 2016 15:13:13 +0100 Subject: [PATCH] portusctl: fixed the location of crono logs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since we don't daemonize it, crono's logs are sent to stdout. Since we manage it with systemd, logs are accessible through journalctl, not on /srv/Portus/log/crono.log. Signed-off-by: Miquel Sabaté Solà --- packaging/suse/portusctl/lib/cli.rb | 1 + packaging/suse/portusctl/lib/runner.rb | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/packaging/suse/portusctl/lib/cli.rb b/packaging/suse/portusctl/lib/cli.rb index c53c346d9..6fe3005a4 100644 --- a/packaging/suse/portusctl/lib/cli.rb +++ b/packaging/suse/portusctl/lib/cli.rb @@ -136,6 +136,7 @@ def logs(*args) ensure_root Runner.produce_versions_file! + Runner.produce_crono_log_file! Runner.tar_files("log/production.log", "log/crono.log", "log/versions.log") end diff --git a/packaging/suse/portusctl/lib/runner.rb b/packaging/suse/portusctl/lib/runner.rb index e8365e93d..4973555a7 100644 --- a/packaging/suse/portusctl/lib/runner.rb +++ b/packaging/suse/portusctl/lib/runner.rb @@ -2,12 +2,17 @@ class Runner # Run a simple external command def self.exec(cmd, args = []) - final_cmd = cmd + " " + args.map { |a| Shellwords.escape(a) }.join(" ") + final_cmd = Runner.escape_command(cmd, args) unless system(final_cmd) raise "Something went wrong while invoking: #{final_cmd}" end end + # Returns a string containing the command with its arguments all escaped. + def self.escape_command(cmd, args = []) + cmd + " " + args.map { |a| Shellwords.escape(a) }.join(" ") + end + # Run an external command using the bundler binary shipped with Portus' RPM def self.bundler_exec(cmd, args, extra_env_variables) Dir.chdir(PORTUS_ROOT) do @@ -42,6 +47,15 @@ def self.produce_versions_file! end end + # Creates a new file called "crono.log" with the logs stored by systemd about + # crono. + def self.produce_crono_log_file! + File.open(File.join(PORTUS_ROOT, "log/crono.log"), "w+") do |file| + cmd = Runner.escape_command("journalctl", ["--no-pager", "-u", "portus_crono"]) + file.puts(`#{cmd}`) + end + end + # Tar and compress the given files into the /tmp directory. It's assumed that # these files are located inside of PORTUS_ROOT. def self.tar_files(*files)