Fix Volumio startup and online updates
This commit is contained in:
Executable
+58
@@ -0,0 +1,58 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
if [ "$(id -u)" -ne 0 ]; then
|
||||
echo "run this installer as root" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"
|
||||
PHOENIX_ROOT="$(cd "$SCRIPT_DIR/.." && pwd -P)"
|
||||
SYSTEMD_SOURCE="$PHOENIX_ROOT/etc/systemd/system"
|
||||
SUDOERS_SOURCE="$PHOENIX_ROOT/etc/sudoers.d/phoenix-update-volumio"
|
||||
LIBEXEC_DIR="/usr/local/libexec/phoenix"
|
||||
|
||||
required_files=(
|
||||
"$SYSTEMD_SOURCE/analyzer-kiosk-volumio.service"
|
||||
"$SYSTEMD_SOURCE/analyzer-web-volumio.service"
|
||||
"$SYSTEMD_SOURCE/phoenix-update-volumio.service"
|
||||
"$SUDOERS_SOURCE"
|
||||
"$PHOENIX_ROOT/scripts/restart_phoenix_services.sh"
|
||||
)
|
||||
|
||||
for path in "${required_files[@]}"; do
|
||||
if [ ! -f "$path" ]; then
|
||||
echo "required Volumio integration file missing: $path" >&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
if ! command -v visudo >/dev/null 2>&1; then
|
||||
echo "visudo not found; refusing to install sudo policy" >&2
|
||||
exit 1
|
||||
fi
|
||||
visudo -cf "$SUDOERS_SOURCE"
|
||||
|
||||
install -d -o root -g root -m 0755 "$LIBEXEC_DIR"
|
||||
install -o root -g root -m 0755 \
|
||||
"$PHOENIX_ROOT/scripts/restart_phoenix_services.sh" \
|
||||
"$LIBEXEC_DIR/restart_phoenix_services.sh"
|
||||
install -o root -g root -m 0644 \
|
||||
"$SYSTEMD_SOURCE/analyzer-kiosk-volumio.service" \
|
||||
/etc/systemd/system/analyzer-kiosk-volumio.service
|
||||
install -o root -g root -m 0644 \
|
||||
"$SYSTEMD_SOURCE/analyzer-web-volumio.service" \
|
||||
/etc/systemd/system/analyzer-web-volumio.service
|
||||
install -o root -g root -m 0644 \
|
||||
"$SYSTEMD_SOURCE/phoenix-update-volumio.service" \
|
||||
/etc/systemd/system/phoenix-update-volumio.service
|
||||
install -o root -g root -m 0440 \
|
||||
"$SUDOERS_SOURCE" \
|
||||
/etc/sudoers.d/phoenix-update-volumio
|
||||
|
||||
systemctl daemon-reload
|
||||
systemctl enable analyzer-web-volumio.service analyzer-kiosk-volumio.service
|
||||
|
||||
echo "Volumio integration installed"
|
||||
echo "Existing services were not restarted"
|
||||
@@ -3,7 +3,12 @@
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"
|
||||
PHOENIX_ROOT="$(cd "$SCRIPT_DIR/.." && pwd -P)"
|
||||
PHOENIX_ROOT="${PHOENIX_ROOT_OVERRIDE:-}"
|
||||
if [ -z "$PHOENIX_ROOT" ]; then
|
||||
PHOENIX_ROOT="$(cd "$SCRIPT_DIR/.." && pwd -P)"
|
||||
else
|
||||
PHOENIX_ROOT="$(cd "$PHOENIX_ROOT" && pwd -P)"
|
||||
fi
|
||||
PHOENIX_PARENT="$(cd "$PHOENIX_ROOT/.." && pwd -P)"
|
||||
PHOENIX_NAME="$(basename "$PHOENIX_ROOT")"
|
||||
STAGE_DIR="$PHOENIX_PARENT/${PHOENIX_NAME}.update"
|
||||
@@ -14,6 +19,10 @@ LOG_FILE="$PHOENIX_PARENT/${PHOENIX_NAME}.update.log"
|
||||
exec >>"$LOG_FILE" 2>&1
|
||||
echo "=== $(date): restart_phoenix_services.sh START ==="
|
||||
|
||||
is_volumio_install() {
|
||||
[ "${PHOENIX_INSTALL_PROFILE:-}" = "volumio" ] || [ "$PHOENIX_ROOT" = "/home/volumio/Phoenix" ]
|
||||
}
|
||||
|
||||
restart_if_present() {
|
||||
local unit="$1"
|
||||
if ! command -v systemctl >/dev/null 2>&1; then
|
||||
@@ -61,6 +70,19 @@ run_systemd_run() {
|
||||
/usr/bin/env PHOENIX_UPDATE_DETACHED=1 /bin/bash "$0"
|
||||
}
|
||||
|
||||
start_volumio_update_service() {
|
||||
local unit="phoenix-update-volumio.service"
|
||||
if [ "$(id -u)" -eq 0 ]; then
|
||||
/usr/bin/systemctl --no-block start "$unit"
|
||||
return $?
|
||||
fi
|
||||
if ! command -v sudo >/dev/null 2>&1; then
|
||||
echo "sudo not found; cannot start $unit as non-root" >&2
|
||||
return 1
|
||||
fi
|
||||
sudo -n /usr/bin/systemctl --no-block start "$unit"
|
||||
}
|
||||
|
||||
health_ok() {
|
||||
if ! command -v curl >/dev/null 2>&1; then
|
||||
return 0
|
||||
@@ -144,7 +166,56 @@ wait_for_candidate_health() {
|
||||
return 1
|
||||
}
|
||||
|
||||
build_volumio_candidate() {
|
||||
local phoenix_dir="${1:-$STAGE_DIR}"
|
||||
local cargo_bin=""
|
||||
local cargo_dir=""
|
||||
local candidate
|
||||
|
||||
if ! needs_phoenix_build "$phoenix_dir"; then
|
||||
echo "Volumio candidate already contains a runnable Phoenix binary"
|
||||
return 0
|
||||
fi
|
||||
|
||||
for candidate in /root/.cargo/bin/cargo /home/volumio/.cargo/bin/cargo /usr/local/bin/cargo /usr/bin/cargo; do
|
||||
if [ -x "$candidate" ]; then
|
||||
cargo_bin="$candidate"
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [ -z "$cargo_bin" ]; then
|
||||
echo "cargo not found; cannot build staged Volumio update" >&2
|
||||
return 1
|
||||
fi
|
||||
cargo_dir="$(dirname "$cargo_bin")"
|
||||
|
||||
echo "building staged Volumio update before stopping the running kiosk"
|
||||
if ! (
|
||||
cd "$phoenix_dir"
|
||||
PATH="$cargo_dir:/root/.cargo/bin:/home/volumio/.cargo/bin:/usr/local/bin:/usr/bin:/bin" \
|
||||
CARGO_TERM_COLOR=never "$cargo_bin" build --release --locked
|
||||
); then
|
||||
if [ -d "$phoenix_dir/target" ]; then
|
||||
chown -R volumio:volumio "$phoenix_dir/target" || true
|
||||
fi
|
||||
echo "staged Volumio build failed; running installation was left untouched" >&2
|
||||
return 1
|
||||
fi
|
||||
chown -R volumio:volumio "$phoenix_dir/target"
|
||||
if [ ! -x "$phoenix_dir/target/release/phoenix" ] || [ ! -s "$phoenix_dir/target/release/phoenix" ]; then
|
||||
echo "staged Volumio build did not produce a runnable Phoenix binary" >&2
|
||||
return 1
|
||||
fi
|
||||
echo "staged Volumio build completed"
|
||||
}
|
||||
|
||||
start_all_services() {
|
||||
if is_volumio_install; then
|
||||
restart_if_present analyzer-web-volumio.service
|
||||
clear_browser_asset_caches
|
||||
restart_if_present analyzer-kiosk-volumio.service
|
||||
return
|
||||
fi
|
||||
restart_if_present phoenix.service
|
||||
restart_if_present analyzer-web.service
|
||||
restart_if_present analyzer-web-volumio.service
|
||||
@@ -154,6 +225,11 @@ start_all_services() {
|
||||
}
|
||||
|
||||
stop_all_services() {
|
||||
if is_volumio_install; then
|
||||
stop_if_present analyzer-kiosk-volumio.service
|
||||
stop_if_present analyzer-web-volumio.service
|
||||
return
|
||||
fi
|
||||
stop_if_present analyzer-kiosk.service
|
||||
stop_if_present analyzer-kiosk-volumio.service
|
||||
stop_if_present analyzer-web.service
|
||||
@@ -180,6 +256,16 @@ rollback_to_backup() {
|
||||
}
|
||||
|
||||
if [ "${PHOENIX_UPDATE_DETACHED:-0}" != "1" ]; then
|
||||
if is_volumio_install; then
|
||||
echo "handing Volumio update to phoenix-update-volumio.service"
|
||||
if start_volumio_update_service; then
|
||||
echo "Volumio update service accepted"
|
||||
exit 0
|
||||
fi
|
||||
echo "failed to start phoenix-update-volumio.service" >&2
|
||||
echo "run scripts/install_volumio_services.sh once as root" >&2
|
||||
exit 1
|
||||
fi
|
||||
if ! command -v systemd-run >/dev/null 2>&1; then
|
||||
echo "systemd-run not found; cannot safely detach updater" >&2
|
||||
exit 1
|
||||
@@ -202,6 +288,10 @@ if [ ! -f "$STAGE_DIR/Cargo.toml" ] || [ ! -d "$STAGE_DIR/src" ] || [ ! -d "$STA
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if is_volumio_install; then
|
||||
build_volumio_candidate "$STAGE_DIR"
|
||||
fi
|
||||
|
||||
stop_all_services
|
||||
|
||||
rm -rf "$BACKUP_DIR"
|
||||
@@ -222,4 +312,11 @@ if ! wait_for_candidate_health "$PHOENIX_ROOT" "$health_attempts" "$health_delay
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if is_volumio_install && [ "$(id -u)" -eq 0 ] && [ -f "$PHOENIX_ROOT/scripts/restart_phoenix_services.sh" ]; then
|
||||
install -o root -g root -m 0755 \
|
||||
"$PHOENIX_ROOT/scripts/restart_phoenix_services.sh" \
|
||||
/usr/local/libexec/phoenix/restart_phoenix_services.sh
|
||||
echo "Volumio privileged update helper refreshed"
|
||||
fi
|
||||
|
||||
echo "=== $(date): restart_phoenix_services.sh OK ==="
|
||||
|
||||
Reference in New Issue
Block a user