Skip to content

Commit c1aeeac

Browse files
authored
ops: smoother update and deploy workflows (#37)
1 parent 6e6a0fc commit c1aeeac

2 files changed

Lines changed: 30 additions & 6 deletions

File tree

bin/baudbot

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ case "${1:-}" in
123123

124124
status)
125125
shift
126-
if has_systemd && systemctl is-enabled baudbot &>/dev/null 2>&1; then
126+
if has_systemd && systemctl is-enabled baudbot &>/dev/null; then
127127
exec systemctl status baudbot "$@"
128128
else
129129
# Fallback: check if baudbot_agent has pi running
@@ -138,7 +138,7 @@ case "${1:-}" in
138138

139139
logs)
140140
shift
141-
if has_systemd && systemctl is-enabled baudbot &>/dev/null 2>&1; then
141+
if has_systemd && systemctl is-enabled baudbot &>/dev/null; then
142142
exec journalctl -u baudbot -f "$@"
143143
else
144144
echo "No systemd unit. Check tmux sessions:"
@@ -254,14 +254,28 @@ 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; then
267+
echo "=== Restarting ==="
268+
systemctl restart baudbot
269+
# Wait for ExecStartPre hooks + process init
270+
sleep 3
271+
if systemctl is-active baudbot &>/dev/null; then
272+
echo "✅ Updated and running"
273+
else
274+
echo "⚠️ Deployed but agent didn't restart — check: baudbot logs"
275+
fi
276+
else
277+
echo "✅ Updated. Start with: sudo baudbot start"
278+
fi
265279
;;
266280

267281
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)