Skip to content

Commit 37ef17d

Browse files
committed
ops: smoother update and deploy workflows
- baudbot update now pulls, deploys, and restarts in one command (was: pull + deploy only, user had to restart manually) - deploy.sh auto-detects admin user from repo ownership when SUDO_USER isn't set, so 'sudo baudbot deploy' just works without needing BAUDBOT_CONFIG_USER env var
1 parent 6e6a0fc commit 37ef17d

2 files changed

Lines changed: 27 additions & 4 deletions

File tree

bin/baudbot

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,14 +254,27 @@ case "${1:-}" in
254254

255255
update)
256256
shift
257-
# For now: git pull + deploy
258257
require_root "update"
259258
echo "=== Pulling latest ==="
260259
cd "$BAUDBOT_ROOT"
261260
git pull origin main
262261
echo ""
263262
echo "=== Deploying ==="
264-
exec "$BAUDBOT_ROOT/bin/deploy.sh" "$@"
263+
"$BAUDBOT_ROOT/bin/deploy.sh" "$@"
264+
echo ""
265+
# Restart if currently running
266+
if has_systemd && systemctl is-active baudbot &>/dev/null 2>&1; then
267+
echo "=== Restarting ==="
268+
systemctl restart baudbot
269+
sleep 2
270+
if systemctl is-active baudbot &>/dev/null 2>&1; then
271+
echo "✅ Updated and running"
272+
else
273+
echo "⚠️ Deployed but agent didn't restart — check: baudbot logs"
274+
fi
275+
else
276+
echo "✅ Updated. Start with: sudo baudbot start"
277+
fi
265278
;;
266279

267280
uninstall)

bin/deploy.sh

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,18 @@ fi
270270
echo "Deploying config..."
271271

272272
# Determine who invoked this (the admin user)
273-
# BAUDBOT_CONFIG_USER env var overrides detection (used by install.sh)
274-
DEPLOY_USER="${BAUDBOT_CONFIG_USER:-${SUDO_USER:-$(whoami)}}"
273+
# Priority: BAUDBOT_CONFIG_USER env > SUDO_USER > repo owner > whoami
274+
if [ -n "${BAUDBOT_CONFIG_USER:-}" ]; then
275+
DEPLOY_USER="$BAUDBOT_CONFIG_USER"
276+
elif [ -n "${SUDO_USER:-}" ] && [ "${SUDO_USER}" != "root" ]; then
277+
DEPLOY_USER="$SUDO_USER"
278+
else
279+
# Detect from repo ownership (the admin owns the source)
280+
DEPLOY_USER=$(stat -c '%U' "$BAUDBOT_SRC" 2>/dev/null || echo "")
281+
if [ -z "$DEPLOY_USER" ] || [ "$DEPLOY_USER" = "root" ]; then
282+
DEPLOY_USER="$(whoami)"
283+
fi
284+
fi
275285
DEPLOY_HOME=$(getent passwd "$DEPLOY_USER" | cut -d: -f6 2>/dev/null || echo "")
276286
ADMIN_CONFIG="$DEPLOY_HOME/.baudbot/.env"
277287

0 commit comments

Comments
 (0)