Skip to content

Commit

Permalink
Allow restarting openqa-webui-daemon without downtime
Browse files Browse the repository at this point in the history
* Allow restarting `openqa-webui-daemon` without downtime by sending SIGHUP
  to the process or reloading the systemd unit `openqa-webui.service`
* Start the Mojolicious application with `reuse=1` as mentioned on
  https://docs.mojolicious.org/Mojolicious/Guides/Cookbook#Zero-downtime-software-upgrades
* Note that other services are not covered but those are also not user
  facing or retried and thus not required
* See https://progress.opensuse.org/issues/162533
  • Loading branch information
Martchus committed Aug 5, 2024
1 parent a5a8098 commit fc2bcef
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/OpenQA/Utils.pm
Original file line number Diff line number Diff line change
Expand Up @@ -840,10 +840,10 @@ sub set_listen_address {
my $port = shift;

return if $ENV{MOJO_LISTEN};
my @listen_addresses = ("http://127.0.0.1:$port");
my @listen_addresses = ("http://127.0.0.1:$port?reuse=1");

# Check for IPv6
push @listen_addresses, "http://[::1]:$port" if IO::Socket::IP->new(Listen => 5, LocalAddr => '::1');
push @listen_addresses, "http://[::1]:$port?reuse=1" if IO::Socket::IP->new(Listen => 5, LocalAddr => '::1');

$ENV{MOJO_LISTEN} = join ',', @listen_addresses;
}
Expand Down
40 changes: 37 additions & 3 deletions script/openqa-webui-daemon
Original file line number Diff line number Diff line change
@@ -1,3 +1,37 @@
#!/bin/sh -e
# Our API commands are very expensive, so the default timeouts are too tight
exec "$(dirname "$0")"/openqa prefork -m production --proxy -i 100 -H 900 -w 30 -c 1 -G 800 "$@"
#!/bin/bash
set -e

pid=
pid_idx=0
pid_dir=${OPENQA_BASEDIR:-/var/lib}/openqa/webui
openqa_args=("$@")
openqa_dir=$(dirname "$0")

function start_service {
# keep track of the previous and next PID
pid_last=$pid
pid_file=$pid_dir/prefork-$pid_idx.pid
pid_idx=$(((pid_idx + 1) % 2))
rm -f "$pid_file"

# start openQA in the background
# note: Our API commands are very expensive, so the default timeouts are too tight.
"$openqa_dir"/openqa prefork -m production --proxy -i 100 -H 900 -w 30 -c 1 -G 800 -P "$pid_file" "${openqa_args[@]}" &
pid=$!

# wait until openQA is ready to accept requests by waiting for its PID file
while [[ ! -e $pid_file ]] && [[ -e /proc/$pid ]]; do sleep 1; done

# terminate a previously started openQA instance
[[ $pid_last ]] && kill -s TERM "$pid_last"

# keep running until openQA terminates (with the "wait"-builtin so bash can handle SIGHUP)
wait "$pid"
}

mkdir -p "$pid_dir"

# start service now and restart it gracefully when we receive SIGHUP
# see https://docs.mojolicious.org/Mojolicious/Guides/Cookbook#Zero-downtime-software-upgrades
trap start_service SIGHUP
start_service
1 change: 1 addition & 0 deletions systemd/openqa-webui.service
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Requires=openqa-livehandler.service openqa-websockets.service openqa-gru.service
[Service]
User=geekotest
ExecStart=/usr/share/openqa/script/openqa-webui-daemon
ExecReload=kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target

0 comments on commit fc2bcef

Please sign in to comment.