Skip to content

Commit 8b20d79

Browse files
authored
Add docker reset-storage command (#674)
Add `ha docker reset-storage`, which posts to the new Supervisor endpoint POST /docker/reset-storage. Supervisor schedules a wipe of the whole Docker storage on the next boot; all container images are re-downloaded, while Home Assistant and app data are kept. A reboot is required to apply the reset. Requires HAOS 18.3+. Refs home-assistant/supervisor#6555
1 parent 753676d commit 8b20d79

2 files changed

Lines changed: 72 additions & 1 deletion

File tree

‎cmd/docker.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ Home Assistant is running on. It allows you to do things like use private OCI re
1414
Example: `
1515
ha docker info
1616
ha docker options
17-
ha docker registries`,
17+
ha docker registries
18+
ha docker reset-storage`,
1819
}
1920

2021
func init() {

‎cmd/docker_reset_storage.go‎

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package cmd
2+
3+
import (
4+
"log/slog"
5+
6+
helper "github.com/home-assistant/cli/client"
7+
"github.com/spf13/cobra"
8+
)
9+
10+
var dockerResetStorageCmd = &cobra.Command{
11+
Use: "reset-storage",
12+
Short: "Reset the Docker storage",
13+
Long: `
14+
This command wipes the complete Docker storage on the next reboot. All container
15+
images, including Supervisor, Home Assistant Core, plugins and apps, are deleted
16+
and downloaded again once the system is back up.
17+
18+
Use it to recover from a corrupted or inconsistent Docker storage, for example
19+
when containers fail to start or images cannot be updated.
20+
21+
Configuration and data of Home Assistant and apps are kept, they are stored
22+
outside of the Docker storage.
23+
24+
Internet connectivity is required for re-download of all the container images.
25+
A reboot is required to apply the reset.
26+
`,
27+
Example: `
28+
ha docker reset-storage
29+
`,
30+
ValidArgsFunction: cobra.NoFileCompletions,
31+
Args: cobra.NoArgs,
32+
Run: func(cmd *cobra.Command, args []string) {
33+
slog.Debug("docker reset-storage", "args", args)
34+
35+
section := "docker"
36+
command := "reset-storage"
37+
38+
confirmed, err := helper.AskForConfirmation(`
39+
This will delete all container images on the next reboot. Supervisor, Home
40+
Assistant Core, plugins and apps are downloaded again afterwards, which
41+
requires internet connectivity. Home Assistant and app data are kept.
42+
43+
Once confirmed, the reset will be applied on the next system reboot.
44+
45+
Are you sure you want to proceed?`, 0)
46+
47+
if err != nil {
48+
cmd.PrintErrln("Aborted:", err)
49+
ExitWithError = true
50+
return
51+
}
52+
53+
if confirmed {
54+
resp, err := helper.GenericJSONPost(section, command, nil)
55+
if err != nil {
56+
helper.PrintError(err)
57+
ExitWithError = true
58+
} else {
59+
ExitWithError = !helper.ShowJSONResponse(resp)
60+
}
61+
} else {
62+
cmd.PrintErrln("Aborted.")
63+
ExitWithError = true
64+
}
65+
},
66+
}
67+
68+
func init() {
69+
dockerCmd.AddCommand(dockerResetStorageCmd)
70+
}

0 commit comments

Comments
 (0)