Keep FastCGI available during restarts

This commit is contained in:
udo
2026-07-16 22:00:08 +00:00
parent 93c701c6c7
commit caffb3f404
16 changed files with 192 additions and 41 deletions
+2 -1
View File
@@ -4,7 +4,8 @@ set -e
if command -v systemctl >/dev/null 2>&1; then
systemctl daemon-reload >/dev/null 2>&1 || true
if [ "$1" = "configure" ]; then
systemctl enable uce.service >/dev/null 2>&1 || true
systemctl enable uce.socket uce.service >/dev/null 2>&1 || true
systemctl start uce.socket >/dev/null 2>&1 || true
systemctl restart uce.service >/dev/null 2>&1 || true
fi
fi
+1 -1
View File
@@ -3,7 +3,7 @@ set -e
if [ "$1" = "remove" ] || [ "$1" = "deconfigure" ]; then
if command -v systemctl >/dev/null 2>&1; then
systemctl disable --now uce.service >/dev/null 2>&1 || true
systemctl disable --now uce.service uce.socket >/dev/null 2>&1 || true
fi
fi
+3 -4
View File
@@ -1,7 +1,8 @@
[Unit]
Description=UCE FastCGI Runtime
After=network-online.target mariadb.service memcached.service
After=network-online.target mariadb.service memcached.service uce.socket
Wants=network-online.target
Requires=uce.socket
[Service]
Type=simple
@@ -10,12 +11,10 @@ RuntimeDirectory=uce
StateDirectory=uce
CacheDirectory=uce
ExecStartPre=/usr/bin/mkdir -p /var/cache/uce/work /var/lib/uce/uploads /var/lib/uce/sessions
ExecStartPre=/usr/bin/rm -f /run/uce/fastcgi.sock
ExecStart=/usr/lib/uce/bin/uce_fastcgi.linux.bin
ExecStopPost=/usr/bin/rm -f /run/uce/fastcgi.sock
Restart=always
RestartSec=2
TimeoutStopSec=15
TimeoutStopSec=30
KillMode=mixed
StandardOutput=journal
StandardError=journal
+15
View File
@@ -0,0 +1,15 @@
[Unit]
Description=UCE FastCGI socket
[Socket]
ListenStream=/run/uce/fastcgi.sock
FileDescriptorName=fastcgi
SocketUser=www-data
SocketGroup=www-data
SocketMode=0660
DirectoryMode=0755
Backlog=100
Service=uce.service
[Install]
WantedBy=sockets.target
+1
View File
@@ -205,6 +205,7 @@ bundle_wasmtime "$STAGE_DIR"
write_packaged_settings "$STAGE_DIR/etc/uce/settings.cfg" "$WEBROOT"
install -m 0644 "$DEB_ASSET_DIR/uce.service" "$STAGE_DIR/lib/systemd/system/uce.service"
install -m 0644 "$DEB_ASSET_DIR/uce.socket" "$STAGE_DIR/lib/systemd/system/uce.socket"
install -m 0644 "$DEB_ASSET_DIR/conffiles" "$DEBIAN_DIR/conffiles"
install -m 0755 "$DEB_ASSET_DIR/postinst" "$DEBIAN_DIR/postinst"
install -m 0755 "$DEB_ASSET_DIR/prerm" "$DEBIAN_DIR/prerm"
+5 -2
View File
@@ -179,6 +179,7 @@ bundle_wasi_sdk "$STAGE_DIR"
bundle_wasmtime "$STAGE_DIR"
write_packaged_settings "$STAGE_DIR/etc/uce/settings.cfg" "$WEBROOT"
install -m 0644 "$REPO_ROOT/scripts/deb/uce.service" "$STAGE_DIR/usr/lib/systemd/system/uce.service"
install -m 0644 "$REPO_ROOT/scripts/deb/uce.socket" "$STAGE_DIR/usr/lib/systemd/system/uce.socket"
(
cd "$STAGE_DIR"
@@ -225,13 +226,14 @@ cp -a %{_builddir}/$PACKAGE_NAME-$VERSION/. %{buildroot}/
%post
if command -v systemctl >/dev/null 2>&1; then
systemctl daemon-reload >/dev/null 2>&1 || true
systemctl enable uce.service >/dev/null 2>&1 || true
systemctl enable uce.socket uce.service >/dev/null 2>&1 || true
systemctl start uce.socket >/dev/null 2>&1 || true
systemctl restart uce.service >/dev/null 2>&1 || true
fi
%preun
if [ "\$1" = "0" ] && command -v systemctl >/dev/null 2>&1; then
systemctl disable --now uce.service >/dev/null 2>&1 || true
systemctl disable --now uce.service uce.socket >/dev/null 2>&1 || true
fi
%postun
@@ -245,6 +247,7 @@ fi
%config(noreplace) /etc/uce/settings.cfg
/usr/lib/uce
/usr/lib/systemd/system/uce.service
/usr/lib/systemd/system/uce.socket
$WEBROOT
%dir /var/cache/uce
%dir /var/lib/uce
+1
View File
@@ -73,4 +73,5 @@ if [[ "$action" == "run" ]]; then
scripts/test_mysql_epoch_refresh.sh
scripts/test_mysql_persistent_pool.sh
scripts/test_log_timeliness.sh
scripts/test_socket_activation.sh
fi
+3 -4
View File
@@ -1,7 +1,8 @@
[Unit]
Description=UCE FastCGI Runtime
After=network-online.target mariadb.service memcached.service
After=network-online.target mariadb.service memcached.service uce.socket
Wants=network-online.target
Requires=uce.socket
[Service]
Type=simple
@@ -10,13 +11,11 @@ RuntimeDirectory=uce
StateDirectory=uce
CacheDirectory=uce
ExecStartPre=/usr/bin/mkdir -p /var/cache/uce/work /var/lib/uce/uploads /var/lib/uce/sessions
ExecStartPre=/usr/bin/rm -f /run/uce/fastcgi.sock
ExecStartPre=/usr/bin/bash /Code/uce.openfu.com/uce/scripts/build_linux.sh
ExecStart=/Code/uce.openfu.com/uce/bin/uce_fastcgi.linux.bin
ExecStopPost=/usr/bin/rm -f /run/uce/fastcgi.sock
Restart=always
RestartSec=2
TimeoutStopSec=15
TimeoutStopSec=30
KillMode=mixed
StandardOutput=journal
StandardError=journal
+15
View File
@@ -0,0 +1,15 @@
[Unit]
Description=UCE FastCGI socket
[Socket]
ListenStream=/run/uce/fastcgi.sock
FileDescriptorName=fastcgi
SocketUser=www-data
SocketGroup=www-data
SocketMode=0660
DirectoryMode=0755
Backlog=100
Service=uce.service
[Install]
WantedBy=sockets.target
+38
View File
@@ -0,0 +1,38 @@
#!/usr/bin/env bash
set -euo pipefail
service_name="${UCE_TEST_SERVICE:-uce.service}"
socket_name="${UCE_TEST_SOCKET_SERVICE:-uce.socket}"
http_host="${UCE_TEST_HTTP_HOST:-uce.openfu.com}"
http_path="${UCE_TEST_HTTP_PATH:-/info/}"
requests="${UCE_TEST_RESTART_REQUESTS:-100}"
statuses=$(mktemp)
trap 'rm -f "$statuses"' EXIT
systemctl is-active --quiet "$socket_name"
systemctl is-active --quiet "$service_name"
socket_path=$(systemctl show -p Listen --value "$socket_name" | sed -n 's/ \+(Stream)$//p')
[[ -S "$socket_path" ]]
inode_before=$(stat -c %i "$socket_path")
(
for ((i = 0; i < requests; i++)); do
curl -sS --max-time 15 -o /dev/null -w '%{http_code}\n' \
-H "Host: $http_host" "http://127.0.0.1${http_path}"
done
) >"$statuses" &
load_pid=$!
sleep 0.05
systemctl restart "$service_name"
wait "$load_pid"
inode_after=$(stat -c %i "$socket_path")
[[ "$inode_after" = "$inode_before" ]]
[[ $(wc -l <"$statuses") -eq "$requests" ]]
if [[ $(grep -c '^200$' "$statuses") -ne "$requests" ]]; then
sort "$statuses" | uniq -c >&2
exit 1
fi
systemctl is-active --quiet "$socket_name"
systemctl is-active --quiet "$service_name"
echo "socket activation restart passed across $requests HTTP requests"