feat(autostart): automatically start projects on command when project stopped, fixes #8245#8258
Merged
Merged
Conversation
…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>
|
Download the artifacts for this pull request:
See Testing a PR. |
Member
Author
|
This seems like a pretty trivial thing in general. I removed |
rpkoller
reviewed
Mar 29, 2026
Collaborator
rpkoller
left a comment
There was a problem hiding this comment.
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!
tyler36
approved these changes
Mar 31, 2026
Collaborator
tyler36
left a comment
There was a problem hiding this comment.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Issue
Commands like
ddev execandddev sshwould fail with "No runningcontainer 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 thatlacked auto-start behavior:
exec: starts project before looking up the containerssh: starts project before opening the shell sessionshare: replaces the hard "Use 'ddev start' first" failurexhgui: replaces the hard "Use 'ddev start' first" failurepull: starts project in each provider subcommand Runpush: starts project in each provider subcommand Runsnapshot restore: starts project before restoringManual Testing Instructions
ddev stopddev exec pwd— should auto-start and print/var/www/htmlddev ssh— should auto-start and open a shellddev share— should auto-start then launch tunnelddev xhgui status— should auto-start then show statusddev snapshot restore --latest— should auto-start then restoreddev startfirst.Automated Testing Overview
Added
TestCmdAutostartincmd/ddev/cmd/autostart_test.gowhich:ddev exec pwdand verifies output contains/var/www/htmlecho exit | ddev sshand verifies the app is running afterwardExisting 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.