Skip to content

Commit

Permalink
Merge pull request #20077 from yrudman/check-for-nilif-stdin-not-nil-…
Browse files Browse the repository at this point in the history
…in-cockpit-worker

Fixed cockpit process starting

(cherry picked from commit 87de914)

https://bugzilla.redhat.com/show_bug.cgi?id=1824355
  • Loading branch information
jrafanie authored and simaishi committed May 7, 2020
1 parent 0258135 commit c9453d4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
21 changes: 14 additions & 7 deletions app/models/miq_cockpit_ws_worker/runner.rb
Expand Up @@ -66,14 +66,16 @@ def stop_cockpit_ws

def stop_cockpit_ws_process
return unless @pid
@stdout&.close
@stderr&.close
Process.kill("TERM", @pid)
wait_on_cockpit_ws
end

# Waits for a cockpit-ws process to stop. The process is expected to be
# in the act of shutting down, and thus it will wait 5 minutes
# before issuing a kill.
def wait_on_cockpit_ws(pid)
def wait_on_cockpit_ws(pid = nil)
pid ||= @pid
# TODO: Use Process.waitpid or one of its async variants
begin
Expand Down Expand Up @@ -148,13 +150,18 @@ def cockpit_ws_run
"XDG_CONFIG_DIRS" => cockpit_ws.config_dir,
"DRB_URI" => @drb_uri
}
Bundler.with_clean_env do
stdin, stdout, stderr, wait_thr = Open3.popen3(env, *cockpit_ws.command(BINDING_ADDRESS), :unsetenv_others => true)
_log.info("Starting cockpit-ws process with command: #{cockpit_ws.command(BINDING_ADDRESS)} ")
_log.info("Cockpit environment #{env} ")
stdin, stdout, stderr, wait_thr = Bundler.with_clean_env do
Open3.popen3(env, cockpit_ws.command(BINDING_ADDRESS), :unsetenv_others => true)
end
stdin&.close
if wait_thr
_log.info("#{log_prefix} cockpit-ws process started - pid=#{wait_thr.pid}")
return wait_thr.pid, stdout, stderr
else
raise "Cockpit-ws process failed to start"
end
stdin.close

_log.info("#{log_prefix} cockpit-ws process started - pid=#{@pid}")
return wait_thr.pid, stdout, stderr
end

def check_drb_service
Expand Down
2 changes: 1 addition & 1 deletion lib/miq_cockpit.rb
Expand Up @@ -71,7 +71,7 @@ def self.url(miq_server, opts, address)

def initialize(opts = {})
@opts = opts || {}
@config_dir = File.join(__dir__, "..", "config")
@config_dir = Rails.root.join("config").to_s
@cockpit_conf_dir = File.join(@config_dir, "cockpit")
FileUtils.mkdir_p(@cockpit_conf_dir)
end
Expand Down

0 comments on commit c9453d4

Please sign in to comment.