diff --git a/etc/raspberrypios/wrolpi-upgrade.service b/etc/raspberrypios/wrolpi-upgrade.service index 76d6a047..621db2a6 100644 --- a/etc/raspberrypios/wrolpi-upgrade.service +++ b/etc/raspberrypios/wrolpi-upgrade.service @@ -4,6 +4,7 @@ After=network.target [Service] Type=oneshot +Environment=WROLPI_UPGRADE_SERVICE=1 EnvironmentFile=/tmp/wrolpi-upgrade.env ExecStart=/opt/wrolpi/upgrade.sh -b ${BRANCH} User=root diff --git a/upgrade.sh b/upgrade.sh index 07875e83..9b5d7f9b 100755 --- a/upgrade.sh +++ b/upgrade.sh @@ -52,6 +52,24 @@ if [ "$BRANCH_OVERRIDE" = false ]; then fi fi +# If not running via the wrolpi-upgrade service, delegate to it so logs are captured. +if [ -z "$WROLPI_UPGRADE_SERVICE" ]; then + trap 'echo ""; echo "Note: The upgrade service is still running in the background."; echo "Monitor with: journalctl -fu wrolpi-upgrade.service"' INT + echo "Delegating upgrade to wrolpi-upgrade.service..." + # Write branch config for the service. + echo "BRANCH=${BRANCH}" >/tmp/wrolpi-upgrade.env + # Start following journal in background (new entries only). + journalctl -fn0 -u wrolpi-upgrade.service & + JOURNAL_PID=$! + # Start service (blocks until complete for oneshot). + systemctl start wrolpi-upgrade.service + EXIT_CODE=$? + # Clean up journal follower. + kill $JOURNAL_PID 2>/dev/null + wait $JOURNAL_PID 2>/dev/null + exit $EXIT_CODE +fi + echo "Upgrading WROLPi from branch: ${BRANCH}" set -x