From 050e6a02b787ebea660862f945396bb9bc976af4 Mon Sep 17 00:00:00 2001 From: "CanbiZ (MickLesk)" <47820557+MickLesk@users.noreply.github.com> Date: Wed, 23 Sep 2026 16:26:45 +0200 Subject: [PATCH] Refactor: Scanopy (#16797) * scanopy: use prebuilt server binary, relax release profile for generate-fixtures * scanopy: drop unneeded rust build, use committed UI fixtures * scanopy: restore generate-fixtures build, ui/src/lib/data is gitignored and incomplete * scanopy: serve the UI from the binary, drop the source build Upstream confirmed in scanopy/scanopy#698 that scanopy-server-linux-* has carried the built UI since v0.17.13, fixtures and service logos included, served on the same port as the API. The release notes never said so, which is why we kept building it. That removes the source tarball, the Rust toolchain and generate-fixtures, Node with npm ci and npm run build, and SCANOPY_WEB_EXTERNAL_PATH. With the variable set to a directory that no longer has an index.html, v0.17.14 and earlier refuse to start, so the update deletes the line rather than leaving it. build-essential, libssl-dev and pkg-config go too: the release binary is static-pie with no INTERP segment, so it has no runtime library dependencies. /opt/scanopy stays, now only for .env and oidc.toml, and the unit's WorkingDirectory follows it out of the removed backend directory. Since nothing wipes that directory any more, the config survives an update on its own, which is the report upstream passed on of an update coming back without SCANOPY_WEB_EXTERNAL_PATH and the server starting API-only. The update keeps the running binary until the new one answers /api/health and puts it back if it does not, so a bad release leaves a working server instead of a stopped one. check_for_gh_release now keys on scanopy-server, matching the version file the binary deploy writes; the Scanopy key belonged to the tarball that is gone. Existing containers run one extra update, then agree. * Refactor scanopy-install.sh for server setup Updated installation script to configure Scanopy server and removed daemon configuration section. * Update service names from 'scanopy-server' to 'Scanopy' * Fix case sensitivity in fetch_and_deploy_gh_release * scanopy: make the rollback restore the whole old setup The health check put the previous binary back but nothing else, and the source tree it needs was already gone by then: the update deleted /opt/scanopy/ui before starting the new server, and removed SCANOPY_WEB_EXTERNAL_PATH from the env at the same time. A failed health check therefore left the old binary running without the UI it serves from disk, so the rollback produced an API-only server. Back up the env file and the unit alongside the binary, restore all three when the check fails, and delete the source tree only once the new server has answered. Nothing the old version needs is removed before the new one has proven itself. * scanopy: name the deployed binary what the unit starts singlefile mode writes the asset to /: local target_file="$app" [[ "${USE_ORIGINAL_FILENAME:-false}" == "true" ]] && target_file="$filename" so with the app renamed to Scanopy the binary lands at /usr/bin/Scanopy while the unit starts /usr/bin/scanopy-server, and the service never comes up on a fresh install. Rename it after the deploy, the same way the daemon block already renames "Scanopy Daemon". Keeping the app name is what matters here: it is also the version file (~/.scanopy), and changing it would make every existing container report an update it does not need. --- ct/scanopy.sh | 53 ++++++++++++++------------- install/scanopy-install.sh | 73 +++++--------------------------------- 2 files changed, 37 insertions(+), 89 deletions(-) diff --git a/ct/scanopy.sh b/ct/scanopy.sh index c1bbb1c9b..1ce28ad44 100644 --- a/ct/scanopy.sh +++ b/ct/scanopy.sh @@ -38,35 +38,20 @@ function update_script() { [[ -f /etc/systemd/system/scanopy-daemon.service ]] && systemctl stop scanopy-daemon msg_ok "Stopped services" - create_backup /opt/scanopy/.env /opt/scanopy/oidc.toml - - CLEAN_INSTALL=1 fetch_and_deploy_gh_release "Scanopy" "scanopy/scanopy" "tarball" "latest" "/opt/scanopy" - - restore_backup - - ensure_dependencies pkg-config libssl-dev - TOOLCHAIN="$(grep "channel" /opt/scanopy/backend/rust-toolchain.toml | awk -F\" '{print $2}')" - RUST_TOOLCHAIN=$TOOLCHAIN setup_rust + cp -f /usr/bin/scanopy-server /usr/bin/scanopy-server.bak 2>/dev/null || true + cp -f /opt/scanopy/.env /opt/scanopy/.env.bak + cp -f /etc/systemd/system/scanopy-server.service /etc/systemd/system/scanopy-server.service.bak if ! grep -q "PUBLIC_URL" /opt/scanopy/.env; then - sed -i "\|_PATH=|a\\scanopy_PUBLIC_URL=http://${LOCAL_IP}:60072" /opt/scanopy/.env + sed -i "\|_PATH=|a\\SCANOPY_PUBLIC_URL=http://${LOCAL_IP}:60072" /opt/scanopy/.env fi sed -i 's|_TARGET=.*$|_URL=http://127.0.0.1:60072|' /opt/scanopy/.env + sed -i '/^SCANOPY_WEB_EXTERNAL_PATH=/d' /opt/scanopy/.env + sed -i 's|^WorkingDirectory=/opt/scanopy/backend$|WorkingDirectory=/opt/scanopy|' /etc/systemd/system/scanopy-server.service + systemctl daemon-reload - msg_info "Building Scanopy Server (patience)" - cd /opt/scanopy/backend - CARGO_BUILD_JOBS="$(get_parallel_jobs)" $STD cargo build --release --bin server --bin generate-fixtures - $STD ./target/release/generate-fixtures --output-dir /opt/scanopy/ui/src/lib/data - mv ./target/release/server /usr/bin/scanopy-server - msg_ok "Built Scanopy Server" - - msg_info "Creating frontend UI" - export PUBLIC_SERVER_HOSTNAME=default - export PUBLIC_SERVER_PORT="" - cd /opt/scanopy/ui - $STD npm ci --no-fund --no-audit - $STD npm run build - msg_ok "Created frontend UI" + fetch_and_deploy_gh_release "Scanopy" "scanopy/scanopy" "singlefile" "latest" "/usr/bin" "scanopy-server-linux-$(arch_resolve)" + mv -f /usr/bin/Scanopy /usr/bin/scanopy-server if [[ -f /etc/systemd/system/scanopy-daemon.service ]]; then fetch_and_deploy_gh_release "Scanopy Daemon" "scanopy/scanopy" "singlefile" "latest" "/usr/local/bin" "scanopy-daemon-linux-$(arch_resolve)" @@ -81,6 +66,26 @@ function update_script() { msg_info "Starting services" systemctl start scanopy-server + healthy=0 + for _ in {1..30}; do + if curl -fsS -o /dev/null http://127.0.0.1:60072/api/health 2>/dev/null; then + healthy=1 + break + fi + sleep 2 + done + if [[ "$healthy" -ne 1 ]]; then + systemctl stop scanopy-server + [[ -f /usr/bin/scanopy-server.bak ]] && mv -f /usr/bin/scanopy-server.bak /usr/bin/scanopy-server + mv -f /opt/scanopy/.env.bak /opt/scanopy/.env + mv -f /etc/systemd/system/scanopy-server.service.bak /etc/systemd/system/scanopy-server.service + systemctl daemon-reload + systemctl start scanopy-server + msg_error "New server did not answer /api/health, restored the previous version" + exit 1 + fi + rm -rf /opt/scanopy/backend /opt/scanopy/ui + rm -f /usr/bin/scanopy-server.bak /opt/scanopy/.env.bak /etc/systemd/system/scanopy-server.service.bak [[ -f /etc/systemd/system/scanopy-daemon.service ]] && systemctl start scanopy-daemon msg_ok "Updated successfully!" fi diff --git a/install/scanopy-install.sh b/install/scanopy-install.sh index b272a2297..a2ee2e9c3 100644 --- a/install/scanopy-install.sh +++ b/install/scanopy-install.sh @@ -13,40 +13,16 @@ setting_up_container network_check update_os -msg_info "Installing Dependencies" -$STD apt install -y \ - build-essential \ - libssl-dev \ - pkg-config -msg_ok "Installed Dependencies" - PG_VERSION=17 setup_postgresql -NODE_VERSION="24" setup_nodejs PG_DB_NAME="scanopy_db" PG_DB_USER="scanopy" PG_DB_GRANT_SUPERUSER="true" setup_postgresql_db -fetch_and_deploy_gh_release "Scanopy" "scanopy/scanopy" "tarball" "latest" "/opt/scanopy" -TOOLCHAIN="$(grep "channel" /opt/scanopy/backend/rust-toolchain.toml | awk -F\" '{print $2}')" -RUST_TOOLCHAIN=$TOOLCHAIN setup_rust +fetch_and_deploy_gh_release "Scanopy" "scanopy/scanopy" "singlefile" "latest" "/usr/bin" "scanopy-server-linux-$(arch_resolve)" +mv -f /usr/bin/Scanopy /usr/bin/scanopy-server -msg_info "Building Scanopy Server (patience)" -cd /opt/scanopy/backend -CARGO_BUILD_JOBS="$(get_parallel_jobs)" $STD cargo build --release --bin server --bin generate-fixtures -$STD ./target/release/generate-fixtures --output-dir /opt/scanopy/ui/src/lib/data -mv ./target/release/server /usr/bin/scanopy-server -msg_ok "Built Scanopy Server" - -msg_info "Creating frontend UI" -export PUBLIC_SERVER_HOSTNAME=default -export PUBLIC_SERVER_PORT="" -cd /opt/scanopy/ui -$STD npm ci --no-fund --no-audit -$STD npm run build -msg_ok "Created frontend UI" - -msg_info "Configuring server for first-run" +msg_info "Configuring Scanopy" +mkdir -p /opt/scanopy cat </opt/scanopy/.env ### - SERVER SCANOPY_DATABASE_URL=postgresql://$PG_DB_USER:$PG_DB_PASS@localhost:5432/$PG_DB_NAME -SCANOPY_WEB_EXTERNAL_PATH="/opt/scanopy/ui/build" SCANOPY_PUBLIC_URL=http://${LOCAL_IP}:60072 SCANOPY_SERVER_PORT=60072 SCANOPY_LOG_LEVEL=info @@ -73,7 +49,9 @@ SCANOPY_HEARTBEAT_INTERVAL=30 ### - see https://github.com/scanopy/scanopy/blob/main/docs/CONFIGURATION.md for more options EOF +msg_ok "Configured Scanopy" +msg_info "Creating Service" cat </etc/systemd/system/scanopy-server.service [Unit] Description=Scanopy Network Discovery Server @@ -81,7 +59,7 @@ After=network.target postgresql.service [Service] Type=simple -WorkingDirectory=/opt/scanopy/backend +WorkingDirectory=/opt/scanopy EnvironmentFile=/opt/scanopy/.env ExecStart=/usr/bin/scanopy-server Restart=always @@ -92,43 +70,8 @@ StandardError=journal [Install] WantedBy=multi-user.target EOF - systemctl enable -q --now scanopy-server - -# Creating short script to configure scanopy-daemon -# cat <~/configure_daemon.sh -# #!/usr/bin/env bash -# -# echo "Auto-configuring integrated daemon..." -# -# NETWORK_ID="\$(sudo -u postgres psql -1 -t -d "${PG_DB_NAME}" -c 'SELECT id FROM networks;')" -# API_KEY="\$(sudo -u postgres psql -1 -t -d "${PG_DB_NAME}" -c 'SELECT key FROM api_keys;')" -# -# cat </etc/systemd/system/scanopy-daemon.service -# [Unit] -# Description=Scanopy Network Discovery Daemon -# After=network-online.target -# Wants=network-online.target -# -# [Service] -# Type=simple -# User=root -# ExecStart=/usr/bin/scanopy-daemon --server-url http://127.0.0.1:60072 --network-id \${NETWORK_ID} --daemon-api-key \${API_KEY} --mode push -# Restart=always -# RestartSec=10 -# StandardOutput=journal -# StandardError=journal -# -# [Install] -# WantedBy=multi-user.target -# END -# -# systemctl enable -q --now scanopy-daemon -# echo "Scanopy daemon configured and running" -# -# EOF -# chmod +x ~/configure_daemon.sh -msg_ok "Scanopy server running - please create an account, daemon API key and daemon in the Scanopy UI." +msg_ok "Created Service" motd_ssh customize