Skip to content

fix: restart running workspaces after a host reboot so sudo works - #247

Merged
rfay merged 1 commit into
mainfrom
20261116_rfay_restart_after_reboot
Nov 17, 2026
Merged

rfay merged 1 commit into
mainfrom
20261116_rfay_restart_after_reboot

Conversation

@rfay

@rfay rfay commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Short Summary (TL;DR)

After a host reboot, workspaces that Docker restarts by itself come up with a broken sudo and start_error. A new oneshot service runs coder restart on every running workspace at boot, which recreates their containers.

The Issue

When the coder.ddev.com host rebooted on 2026-11-16, every workspace that had been running came back with start_error. Inside those containers, /usr/bin/sudo and /etc/sudo.conf were owned by 65534 (nobody). The startup script failed on its first sudo call:

sudo: /etc/sudo.conf is owned by uid 65534, should be 0
sudo: /usr/bin/sudo must be owned by uid 0 and have the setuid bit set

Docker restarts these containers at boot because the templates use restart = "unless-stopped". Sysbox does not redo the container's user-namespace ID mapping on that restart. A plain docker restart without a reboot does not cause this: sudo stayed owned by root. A workspace created after the reboot was also fine.

How This PR Solves The Issue

coder restart destroys and recreates the workspace container, which fixes the ownership. The new scripts/restart-workspaces-after-boot.sh waits for Coder's /healthz, then restarts every workspace whose latest build is running. It is a dry run unless given --force.

scripts/restart-workspaces-after-boot.service runs it once at boot, after docker.service and coder.service. It reuses the workspace-janitor token from /etc/workspace-lifecycle-cleanup.env, which already has the owner role.

The templates keep restart = "unless-stopped". The docker-daemon module relies on it to bring workspaces back after a Docker package upgrade, and that path is not affected.

The docs add Step 15 to server-setup.md and a troubleshooting entry for the sudo symptom.

Manual Testing Instructions

On a Coder host with at least one running workspace and the Step 14 env file:

sudo install -m 755 scripts/restart-workspaces-after-boot.sh /usr/local/bin/restart-workspaces-after-boot
sudo -u rfay bash -c 'set -a; source /etc/workspace-lifecycle-cleanup.env; set +a; /usr/local/bin/restart-workspaces-after-boot'
# Expect "Running workspaces: N", one "would restart <owner>/<name>" per workspace, and "Dry run."

Then install and enable the service as Step 15 describes, and reboot the host:

sudo install -m 644 scripts/restart-workspaces-after-boot.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable restart-workspaces-after-boot.service
sudo reboot
# After boot:
sudo journalctl -u restart-workspaces-after-boot -q
# Expect one "restarting <owner>/<name>" per workspace, and no failures
coder ssh <workspace> -- stat -c '%u %n' /usr/bin/sudo
# Expect "0 /usr/bin/sudo"

Docs preview: https://coder-ddev--247.org.readthedocs.build/self-hosting/server-setup/#step-15-restart-workspaces-after-a-host-reboot

Automated Testing Overview

No automated tests: the behavior only shows across a host reboot.

  • Claude Code ran shellcheck on the script, and systemd-analyze verify on the unit on coder.ddev.com.
  • Claude Code ran the script without --force on coder.ddev.com. It listed the three running workspaces and exited 0.
  • Claude Code ran make docs-check, which passed.
  • coder.ddev.com was rebooted with the service enabled. At boot the service restarted the 3 running workspaces in about 80 seconds and exited successfully. Afterwards /usr/bin/sudo was owned by uid 0 in all three.

Release/Deployment Notes

Installed and enabled on coder.ddev.com. staging-coder.ddev.com does not get it: it has no owner-role token, and its workspaces are short-lived CI workspaces that the reaper removes.

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Previews

The start.coder.ddev.com landing-page preview has been removed. Read the Docs keeps or removes its own docs preview.

@read-the-docs-community

read-the-docs-community Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Documentation build overview

📚 coder-ddev | 🛠️ Build #35936755 | 📁 Comparing a4e248b against latest (25a1676)

  🔍 Preview build  

2 files changed
± self-hosting/server-setup/index.html
± self-hosting/troubleshooting/index.html

## Short Summary (TL;DR)

After a host reboot, workspaces that Docker restarts by itself come up with a broken `sudo` and `start_error`. A new oneshot service runs `coder restart` on every running workspace at boot, which recreates their containers.

## The Issue

When the coder.ddev.com host rebooted on 2026-11-16, every workspace that had been running came back with `start_error`. Inside those containers, `/usr/bin/sudo` and `/etc/sudo.conf` were owned by 65534 (`nobody`). The startup script failed on its first `sudo` call:

```text
sudo: /etc/sudo.conf is owned by uid 65534, should be 0
sudo: /usr/bin/sudo must be owned by uid 0 and have the setuid bit set
```

Docker restarts these containers at boot because the templates use `restart = "unless-stopped"`. Sysbox does not redo the container's user-namespace ID mapping on that restart. A plain `docker restart` without a reboot does not cause this: sudo stayed owned by root. A workspace created after the reboot was also fine.

## How This PR Solves The Issue

`coder restart` destroys and recreates the workspace container, which fixes the ownership. The new `scripts/restart-workspaces-after-boot.sh` waits for Coder's `/healthz`, then restarts every workspace whose latest build is running. It is a dry run unless given `--force`.

`scripts/restart-workspaces-after-boot.service` runs it once at boot, after `docker.service` and `coder.service`. It reuses the `workspace-janitor` token from `/etc/workspace-lifecycle-cleanup.env`, which already has the owner role.

The templates keep `restart = "unless-stopped"`. The `docker-daemon` module relies on it to bring workspaces back after a Docker package upgrade, and that path is not affected.

The docs add Step 15 to `server-setup.md` and a troubleshooting entry for the `sudo` symptom.

## Manual Testing Instructions

On a Coder host with at least one running workspace and the Step 14 env file:

```bash
sudo install -m 755 scripts/restart-workspaces-after-boot.sh /usr/local/bin/restart-workspaces-after-boot
sudo -u rfay bash -c 'set -a; source /etc/workspace-lifecycle-cleanup.env; set +a; /usr/local/bin/restart-workspaces-after-boot'
# Expect "Running workspaces: N", one "would restart <owner>/<name>" per workspace, and "Dry run."
```

Then install and enable the service as Step 15 describes, and reboot the host:

```bash
sudo install -m 644 scripts/restart-workspaces-after-boot.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable restart-workspaces-after-boot.service
sudo reboot
# After boot:
sudo journalctl -u restart-workspaces-after-boot -q
# Expect one "restarting <owner>/<name>" per workspace, and no failures
coder ssh <workspace> -- stat -c '%u %n' /usr/bin/sudo
# Expect "0 /usr/bin/sudo"
```

Docs preview: https://coder-ddev--247.org.readthedocs.build/self-hosting/server-setup/#step-15-restart-workspaces-after-a-host-reboot

## Automated Testing Overview

No automated tests: the behavior only shows across a host reboot.

- Claude Code ran `shellcheck` on the script, and `systemd-analyze verify` on the unit on coder.ddev.com.
- Claude Code ran the script without `--force` on coder.ddev.com. It listed the three running workspaces and exited 0.
- Claude Code ran `make docs-check`, which passed.
- Nobody has run the service across a real reboot yet.

## Release/Deployment Notes

Install the service on coder.ddev.com and staging-coder.ddev.com as Step 15 describes. Staging needs the Step 14 env file, or its own owner-role token, first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rfay
rfay force-pushed the 20261116_rfay_restart_after_reboot branch from feb3310 to a4e248b Compare November 16, 2026 19:04
@rfay
rfay merged commit b08b06e into main Nov 17, 2026
32 of 42 checks passed
@rfay
rfay deleted the 20261116_rfay_restart_after_reboot branch November 17, 2026 03:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant