Skip to content

feat(autostart): automatically start projects on command when project stopped, fixes #8245#8258

Merged
rfay merged 2 commits into
ddev:mainfrom
rfay:20260328_rfay_autostart
Apr 1, 2026
Merged

feat(autostart): automatically start projects on command when project stopped, fixes #8245#8258
rfay merged 2 commits into
ddev:mainfrom
rfay:20260328_rfay_autostart

Conversation

@rfay
Copy link
Copy Markdown
Member

@rfay rfay commented Mar 28, 2026

The Issue

Commands like ddev exec and ddev ssh would fail with "No running
container found" when the project was stopped, while other commands
(composer, import-db, export-db, snapshot) already auto-started the
project transparently.

How This PR Solves The Issue

Added app.StartAppIfNotRunning() calls to the eight commands that
lacked auto-start behavior:

  • exec: starts project before looking up the container
  • ssh: starts project before opening the shell session
  • share: replaces the hard "Use 'ddev start' first" failure
  • xhgui: replaces the hard "Use 'ddev start' first" failure
  • pull: starts project in each provider subcommand Run
  • push: starts project in each provider subcommand Run
  • snapshot restore: starts project before restoring

Manual Testing Instructions

  1. Stop a project: ddev stop
  2. Run each previously-failing command:
    • ddev exec pwd — should auto-start and print /var/www/html
    • ddev ssh — should auto-start and open a shell
    • ddev share — should auto-start then launch tunnel
    • ddev xhgui status — should auto-start then show status
    • ddev snapshot restore --latest — should auto-start then restore
  3. All should start the project transparently without requiring a manual ddev start first.

Automated Testing Overview

Added TestCmdAutostart in cmd/ddev/cmd/autostart_test.go which:

  • Stops the project
  • Runs ddev exec pwd and verifies output contains /var/www/html
  • Stops the project again
  • Runs echo exit | ddev ssh and verifies the app is running afterward

Existing tests (TestCmdExec, TestCmdSnapshotRestore, TestImportTilde) all pass with the new binary.

Release/Deployment Notes

Purely behavioral change: commands that previously required a running
project now start it automatically. No configuration changes, no
breaking changes. Users who relied on the failure message to detect a
stopped project will now see the project start instead.

…ull, push, snapshot restore, fixes ddev#8245

## The Issue

- Fixes ddev#8245

Commands like `ddev exec` and `ddev ssh` would fail with "No running
container found" when the project was stopped, while other commands
(composer, import-db, export-db, snapshot) already auto-started the
project transparently.

## How This PR Solves The Issue

Added `app.StartAppIfNotRunning()` calls to the eight commands that
lacked auto-start behavior:

- `exec`: starts project before looking up the container
- `ssh`: starts project before opening the shell session
- `share`: replaces the hard "Use 'ddev start' first" failure
- `xhgui`: replaces the hard "Use 'ddev start' first" failure
- `import-files`: starts project at the top of `importFilesRun`
- `pull`: starts project in each provider subcommand Run
- `push`: starts project in each provider subcommand Run
- `snapshot restore`: starts project before restoring

## Manual Testing Instructions

1. Stop a project: `ddev stop`
2. Run each previously-failing command:
   - `ddev exec pwd` — should auto-start and print `/var/www/html`
   - `ddev ssh` — should auto-start and open a shell
   - `ddev share` — should auto-start then launch tunnel
   - `ddev xhgui status` — should auto-start then show status
   - `ddev import-files --source=some.tar.gz` — should auto-start then import
   - `ddev snapshot restore --latest` — should auto-start then restore
3. All should start the project transparently without requiring a manual `ddev start` first.

## Automated Testing Overview

Added `TestCmdAutostart` in `cmd/ddev/cmd/autostart_test.go` which:
- Stops the project
- Runs `ddev exec pwd` and verifies output contains `/var/www/html`
- Stops the project again
- Runs `echo exit | ddev ssh` and verifies the app is running afterward

Existing tests (`TestCmdExec`, `TestCmdSnapshotRestore`, `TestImportTilde`) all pass with the new binary.

## Release/Deployment Notes

Purely behavioral change: commands that previously required a running
project now start it automatically. No configuration changes, no
breaking changes. Users who relied on the failure message to detect a
stopped project will now see the project start instead.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 28, 2026

@rfay rfay changed the title feat: auto-start project for exec, ssh, share, xhgui, import-files, pull, push, snapshot restore, fixes #8245 feat: auto-start project for exec, ssh, share, xhgui, pull, push, snapshot restore, fixes #8245 Mar 28, 2026
@rfay rfay marked this pull request as ready for review March 28, 2026 20:25
@rfay rfay requested a review from a team as a code owner March 28, 2026 20:25
@rfay
Copy link
Copy Markdown
Member Author

rfay commented Mar 28, 2026

This seems like a pretty trivial thing in general. I removed ddev import-files because it doesn't need the project running anyway.

@rfay rfay requested review from rpkoller and stasadev March 28, 2026 20:26
@rfay rfay changed the title feat: auto-start project for exec, ssh, share, xhgui, pull, push, snapshot restore, fixes #8245 feat: autostart project for exec, ssh, share, xhgui, pull, push, snapshot restore, fixes #8245 Mar 28, 2026
Copy link
Copy Markdown
Collaborator

@rpkoller rpkoller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

manually tested the steps under point 2 in the manual testing section and each of them is starting the project as expect. i simply aborted the started startup process after a secon, just checking if it is triggered and it was for exec, ssh, share, xhgui and snapshot. thank you!

@rfay rfay changed the title feat: autostart project for exec, ssh, share, xhgui, pull, push, snapshot restore, fixes #8245 feat(autostart):Automatically start projects on command when project stopped, fixes #8245 Mar 29, 2026
@rfay rfay changed the title feat(autostart):Automatically start projects on command when project stopped, fixes #8245 feat(autostart):automatically start projects on command when project stopped, fixes #8245 Mar 29, 2026
@stasadev stasadev changed the title feat(autostart):automatically start projects on command when project stopped, fixes #8245 feat(autostart): automatically start projects on command when project stopped, fixes #8245 Mar 30, 2026
Copy link
Copy Markdown
Collaborator

@tyler36 tyler36 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works as expected with the commands in manual testing. With the exception of ddev snapshot restore --lates which auto-starts the project in 1.25.1

Tests

Commands recieve a ✅ if the project auto-starts.

Current version ( v1.25.1)

  • ddev poweroff && ddev exec pwd
  • ddev poweroff && ddev ssh
  • ddev poweroff && ddev share
  • ddev poweroff && ddev xhgui status
  • ddev poweroff && ddev snapshot restore --latest

This PR ( v1.25.1-32-g08ccacabd)

  • ddev poweroff && ddev exec pwd
  • ddev poweroff && ddev ssh
  • ddev poweroff && ddev share
  • ddev poweroff && ddev xhgui status
  • ddev poweroff && ddev snapshot restore --latest

Copy link
Copy Markdown
Member

@stasadev stasadev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@rfay rfay merged commit 938a813 into ddev:main Apr 1, 2026
44 of 53 checks passed
@rfay rfay deleted the 20260328_rfay_autostart branch April 1, 2026 19:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Autostart projects when referenced but not running - make the behavior consistent across all commands

4 participants