#!/usr/bin/env bash # Builds the release binary and installs it to the running deployment at # /opt/steamapi, then restarts the systemd service. See README.md for the # full deployment layout and why the dev tree and runtime dir are separate. set -euo pipefail PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" DEPLOY_DIR=/opt/steamapi SERVICE=steamapi cd "$PROJECT_DIR" echo "==> Building release binary" cargo build --release echo "==> Installing binary to $DEPLOY_DIR" # Copy to a temp file and rename into place (atomic) rather than # overwriting target/steamapi's inode directly, since that inode is the # currently-running executable and a direct in-place write can race with it. sudo cp "target/release/steamapi" "$DEPLOY_DIR/steamapi.new" sudo chown steamapi:steamapi "$DEPLOY_DIR/steamapi.new" sudo chmod 755 "$DEPLOY_DIR/steamapi.new" sudo mv "$DEPLOY_DIR/steamapi.new" "$DEPLOY_DIR/steamapi" echo "==> Restarting $SERVICE" sudo systemctl restart "$SERVICE" sleep 1 sudo systemctl --no-pager --lines=5 status "$SERVICE"