Compare commits

...

5 Commits

Author SHA1 Message Date
fea9f9c677 fix: wine too much clients errors 2026-03-31 19:29:42 +02:00
280d423f89 fix: remove wine errors 2026-03-31 19:26:03 +02:00
3143f49d9c fix: create new server 2026-03-31 19:19:42 +02:00
30ceffee1c fix: remove image pull 2026-03-31 19:15:14 +02:00
b912f45472 fix: migrate script 2026-03-31 19:12:07 +02:00
4 changed files with 137 additions and 26 deletions

View File

@@ -13,12 +13,10 @@ RUN dpkg --add-architecture i386 && \
apt-get update && \ apt-get update && \
apt-get install -y --install-recommends \ apt-get install -y --install-recommends \
winehq-staging \ winehq-staging \
xvfb \
tcpdump \ tcpdump \
&& \ && \
rm -rf /var/lib/apt/lists/* rm -rf /var/lib/apt/lists/*
RUN mkdir -p /tmp/.X11-unix && chmod 1777 /tmp/.X11-unix
WORKDIR /root WORKDIR /root

View File

@@ -1,20 +1,20 @@
#!/bin/bash #!/bin/bash
set -e set -e
# Use a display number derived from the server port to avoid conflicts # Wine Staging looks for PulseAudio via XDG_RUNTIME_DIR. There is no audio
# between containers (each server gets its own unique display). # in this container, so point it at a valid (empty) directory to silence
DISPLAY_NUM=$((SERVER_PORT % 1000 + 100)) # the "XDG_RUNTIME_DIR is invalid" errors.
export DISPLAY=:${DISPLAY_NUM} export XDG_RUNTIME_DIR=/tmp/runtime-${SERVER_PORT}
mkdir -p "${XDG_RUNTIME_DIR}"
# Clean up any stale X lock from a previous container run. # Use Wine's headless (null) display driver — accServer.exe has no GUI so
rm -f /tmp/.X${DISPLAY_NUM}-lock /tmp/.X11-unix/X${DISPLAY_NUM} 2>/dev/null || true # there is no need for Xvfb at all. This avoids the X11 client limit and
# removes the Xvfb process entirely.
Xvfb ${DISPLAY} -screen 0 1024x768x16 -nolisten tcp & export DISPLAY=
XVFB_PID=$! export WINEDLLOVERRIDES="winex11.drv="
cleanup() { cleanup() {
echo "Stopping ACC server..." echo "Stopping ACC server..."
kill $XVFB_PID 2>/dev/null || true
} }
trap cleanup SIGTERM SIGINT trap cleanup SIGTERM SIGINT

View File

@@ -8,10 +8,8 @@ import (
"acc-server-manager/local/utl/logging" "acc-server-manager/local/utl/logging"
"context" "context"
"fmt" "fmt"
"io"
"github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/container"
dockerimage "github.com/docker/docker/api/types/image"
dockerclient "github.com/docker/docker/client" dockerclient "github.com/docker/docker/client"
) )
@@ -39,16 +37,6 @@ func NewSystemService(
func (s *SystemService) MigrateImage(ctx context.Context, stopRunning bool) (*model.MigrationResult, error) { func (s *SystemService) MigrateImage(ctx context.Context, stopRunning bool) (*model.MigrationResult, error) {
image := env.GetACCImage() image := env.GetACCImage()
reader, err := s.dockerClient.ImagePull(ctx, image, dockerimage.PullOptions{})
if err != nil {
return nil, fmt.Errorf("failed to pull image %s: %v", image, err)
}
if _, err := io.Copy(io.Discard, reader); err != nil {
logging.Warn("Error draining image pull response for %s: %v", image, err)
}
reader.Close()
logging.Info("Pulled image %s", image)
servers, err := s.repo.GetAll(ctx, &model.ServerFilter{}) servers, err := s.repo.GetAll(ctx, &model.ServerFilter{})
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to list servers: %v", err) return nil, fmt.Errorf("failed to list servers: %v", err)
@@ -90,10 +78,19 @@ func (s *SystemService) MigrateImage(ctx context.Context, stopRunning bool) (*mo
if err := s.dockerClient.ContainerRemove(ctx, server.ContainerID, container.RemoveOptions{Force: true}); err != nil { if err := s.dockerClient.ContainerRemove(ctx, server.ContainerID, container.RemoveOptions{Force: true}); err != nil {
logging.Warn("Failed to remove container %s for server %s: %v", server.ContainerID, server.ID, err) logging.Warn("Failed to remove container %s for server %s: %v", server.ContainerID, server.ID, err)
} }
server.ContainerID = ""
}
if err := s.runtime.Create(ctx, &server); err != nil {
result.Failed = append(result.Failed, model.ServerMigrationError{
ID: server.ID.String(),
Name: server.Name,
Error: fmt.Sprintf("recreate failed: %v", err),
})
continue
} }
server.ContainerID = ""
if err := s.repo.Update(ctx, &server); err != nil { if err := s.repo.Update(ctx, &server); err != nil {
logging.Warn("Failed to clear ContainerID for server %s: %v", server.ID, err) logging.Warn("Failed to persist new ContainerID for server %s: %v", server.ID, err)
} }
if isRunning { if isRunning {

116
scripts/migrate-wine.sh Executable file
View File

@@ -0,0 +1,116 @@
#!/usr/bin/env bash
# migrate-wine.sh — Pull the latest acc-wine image and migrate all server containers.
#
# Usage:
# ./scripts/migrate-wine.sh -u <username> -p <password> -b <base_url> [--stop-running]
#
# Options:
# -u, --username API username
# -p, --password API password
# -b, --base-url Base URL of the manager (e.g. http://192.168.0.177:3000)
# --stop-running Also migrate currently running servers (stop → migrate → restart)
#
# Examples:
# ./scripts/migrate-wine.sh -u admin -p secret -b http://192.168.0.177:3000
# ./scripts/migrate-wine.sh -u admin -p secret -b http://192.168.0.177:3000 --stop-running
set -euo pipefail
# ── Argument parsing ────────────────────────────────────────────────────────────
USERNAME=""
PASSWORD=""
BASE_URL=""
STOP_RUNNING=false
usage() {
grep '^#' "$0" | sed 's/^# \{0,1\}//' | tail -n +2
exit 1
}
while [[ $# -gt 0 ]]; do
case "$1" in
-u|--username) USERNAME="$2"; shift 2 ;;
-p|--password) PASSWORD="$2"; shift 2 ;;
-b|--base-url) BASE_URL="$2"; shift 2 ;;
--stop-running) STOP_RUNNING=true; shift ;;
-h|--help) usage ;;
*) echo "Unknown option: $1"; usage ;;
esac
done
[[ -z "$USERNAME" ]] && { echo "Error: --username is required"; usage; }
[[ -z "$PASSWORD" ]] && { echo "Error: --password is required"; usage; }
[[ -z "$BASE_URL" ]] && { echo "Error: --base-url is required"; usage; }
BASE_URL="${BASE_URL%/}" # strip trailing slash
BASE_URL="${BASE_URL/#http:\/\//https://}" # upgrade http → https
# ── Check dependencies ──────────────────────────────────────────────────────────
for cmd in curl jq; do
command -v "$cmd" &>/dev/null || { echo "Error: '$cmd' is required but not installed."; exit 1; }
done
# ── Login ───────────────────────────────────────────────────────────────────────
echo "Logging in as '$USERNAME'..."
LOGIN_RESPONSE=$(curl -sL --post301 --post302 -X POST "${BASE_URL}/v1/auth/login" \
-H "Content-Type: application/json" \
-d "$(jq -n --arg u "$USERNAME" --arg p "$PASSWORD" '{username: $u, password: $p}')")
TOKEN=$(echo "$LOGIN_RESPONSE" | jq -r '.token // empty' 2>/dev/null || true)
if [[ -z "$TOKEN" ]]; then
echo "Error: Login failed — no token in response."
exit 1
fi
echo "Login successful."
# ── Migrate ─────────────────────────────────────────────────────────────────────
echo "Starting image migration (stopRunning=${STOP_RUNNING})..."
MIGRATE_RESPONSE=$(curl -sL --post301 --post302 -X POST "${BASE_URL}/v1/system/migrate-image" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${TOKEN}" \
-d "{\"stopRunning\":${STOP_RUNNING}}")
# ── Results ──────────────────────────────────────────────────────────────────────
SERVER_ERROR=$(echo "$MIGRATE_RESPONSE" | jq -r '.error // empty' 2>/dev/null || true)
if [[ -n "$SERVER_ERROR" ]]; then
echo "Error: Migration failed — $SERVER_ERROR"
echo "Full response: $MIGRATE_RESPONSE"
exit 1
fi
IMAGE=$(echo "$MIGRATE_RESPONSE" | jq -r '.image')
MIGRATED=$(echo "$MIGRATE_RESPONSE" | jq -r '.migrated | length')
SKIPPED=$(echo "$MIGRATE_RESPONSE" | jq -r '.skipped | length')
FAILED=$(echo "$MIGRATE_RESPONSE" | jq -r '.failed | length')
echo ""
echo "Image: ${IMAGE}"
echo "────────────────────────────────"
printf " Migrated : %s\n" "$MIGRATED"
printf " Skipped : %s\n" "$SKIPPED"
printf " Failed : %s\n" "$FAILED"
echo "────────────────────────────────"
if [[ "$MIGRATED" -gt 0 ]]; then
echo ""
echo "Migrated servers:"
echo "$MIGRATE_RESPONSE" | jq -r '.migrated[] | " - \(.name) (wasRunning: \(.wasRunning))"'
fi
if [[ "$SKIPPED" -gt 0 ]]; then
echo ""
echo "Skipped (running, use --stop-running to include):"
echo "$MIGRATE_RESPONSE" | jq -r '.skipped[] | " - \(.name)"'
fi
if [[ "$FAILED" -gt 0 ]]; then
echo ""
echo "Failed:"
echo "$MIGRATE_RESPONSE" | jq -r '.failed[] | " - \(.name): \(.error)"'
exit 1
fi
echo ""
echo "Done."