Skip to content

Commit 23ccad0

Browse files
committed
Fix services restart script
1 parent dd47d96 commit 23ccad0

2 files changed

Lines changed: 23 additions & 5 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
#
99
# Optional:
1010
# DEPLOY_PORT — SSH port (default 22)
11-
# DEPLOY_COMMAND — command to run after rsync (e.g. sudo systemctl restart myapp). If unset, only files are synced.
11+
# DEPLOY_COMMAND — command to run after rsync (e.g. sudo /usr/local/bin/restart-workspace.sh). If unset, only files are synced.
12+
# For "sudo: a terminal is required" / "password is required" from the deploy user: that user must
13+
# have a sudoers NOPASSWD rule for the exact command. Test on the server: sudo -n true and
14+
# sudo -n /path/to/restart-workspace.sh (no prompt). See deploy/restart-workspace.sh comments.
1215

1316
name: Build and deploy
1417

@@ -91,7 +94,8 @@ jobs:
9194
exit 0
9295
fi
9396
PORT="${DEPLOY_PORT:-22}"
94-
# shell over SSH: cd then run your restart script or systemctl
95-
ssh -p "$PORT" -o StrictHostKeyChecking=yes \
97+
# -tt: allocate a TTY (helps if sudoers has requiretty; CI has no TTY by default)
98+
# Passwordless sudo (NOPASSWD) for the exact path is still required; see repo deploy/restart-workspace.sh
99+
ssh -tt -p "$PORT" -o StrictHostKeyChecking=yes \
96100
"${DEPLOY_USER}@${DEPLOY_HOST}" \
97101
bash -lc "cd $(printf %q "$DEPLOY_PATH") && $DEPLOY_COMMAND"

deploy/restart-workspace.sh

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,22 @@
44
# One-time on the server:
55
# sudo install -m 755 -o root -g root deploy/restart-workspace.sh /usr/local/bin/restart-workspace.sh
66
#
7-
# Sudoers for the CI/deploy user (use visudo), allow only this script, no password:
8-
# deploy ALL=(ALL) NOPASSWD: /usr/local/bin/restart-workspace.sh
7+
# Sudo: GitHub Actions is non-interactive, so the SSH user (same as secret DEPLOY_USER) must
8+
# be allowed to run *exactly* this path without a password. Create a file, e.g. with visudo:
9+
# /etc/sudoers.d/99-restart-workspace
10+
# ----
11+
# replace USERNAME with your deploy/SSH user (e.g. adept, deploy, github)
12+
# USERNAME ALL=(root) NOPASSWD: /usr/local/bin/restart-workspace.sh
13+
# ----
14+
# sudo chmod 440 /etc/sudoers.d/99-restart-workspace
15+
#
16+
# Verify as the deploy/SSH user (must succeed, exit 0, no password prompt):
17+
# sudo -n /usr/local/bin/restart-workspace.sh
18+
#
19+
# If you see "a password is required" from CI, the rule does not match: wrong user, path, or typo.
20+
# If you see TTY / requiretty issues, /etc/ssh/ssh_config or the workflow uses -tt; also try
21+
# Defaults!USERNAME !requiretty
22+
# in a sudoers drop-in (use visudo).
923
#
1024
# GitHub Actions secret DEPLOY_COMMAND:
1125
# sudo /usr/local/bin/restart-workspace.sh

0 commit comments

Comments
 (0)