A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.
feat(rexctl): add rexctl down to remove containers and keep data (#3729)
Hampusa057711e0039
diff --git a/fluxer_docs/src/content/docs/operator/rexctl.mdx b/fluxer_docs/src/content/docs/operator/rexctl.mdxindex b1617e831..da4474a1b 100644--- a/fluxer_docs/src/content/docs/operator/rexctl.mdx+++ b/fluxer_docs/src/content/docs/operator/rexctl.mdx@@ -262,6 +262,14 @@ rexctl doctor [flags]Print JSON.+## rexctl down++Stop Fluxer and remove its containers and networks, like docker compose down. Your data, settings, backups and images stay. Fluxer stays stopped until you run rexctl start, which creates the containers again.++```sh+rexctl down+```+## rexctl ejectWrites every setting into the instance folder for docker compose and stops rexctl from changing the instance. Fluxer keeps running. Run rexctl takeover to hand it back.@@ -763,7 +771,7 @@ rexctl status [flags]## rexctl stop-Stop your instance.+Stop Fluxer and keep its containers. Fluxer stays stopped until you run rexctl start. To remove the containers too, run rexctl down.```shrexctl stop@@ -783,7 +791,7 @@ rexctl takeover [flags]## rexctl uninstall-Remove Fluxer from this machine.+Remove Fluxer from this machine, with its data and backups unless you pass --keep-data. To stop Fluxer and keep everything, run rexctl stop or rexctl down.```shrexctl uninstall [flags]diff --git a/fluxer_docs/src/content/docs/operator/voice-servers.mdx b/fluxer_docs/src/content/docs/operator/voice-servers.mdxindex f7818613a..cd89a8857 100644--- a/fluxer_docs/src/content/docs/operator/voice-servers.mdx+++ b/fluxer_docs/src/content/docs/operator/voice-servers.mdx@@ -329,13 +329,13 @@ A voice machine doesn't upgrade with the Fluxer machine. Run `rexctl upgrade` th## Stop, restart and back up-`rexctl stop` on the Fluxer machine stops the voice servers there too, and calls on them end. `rexctl start` starts them again. `rexctl restart` restarts Fluxer and leaves running voice servers alone.+`rexctl stop` on the Fluxer machine stops the voice servers there too, and calls on them end. `rexctl down` removes their containers as well. `rexctl start` starts them again. `rexctl restart` restarts Fluxer and leaves running voice servers alone.`rexctl backup` keeps the voice servers of the instance, with their keys. `rexctl restore` writes their files again, starts them and opens their ports in the firewall. A server added after the backup is removed by the restore.Changing `network.ipv6` with `rexctl config set` rebuilds Fluxer's network. rexctl stops the voice servers on the machine first and starts them again afterwards, and calls on them end.-On a voice machine, `rexctl stop`, `rexctl restart`, `rexctl logs` and `rexctl backup` don't apply. Docker runs each server as `fluxer-voice-<id>-livekit-1`, and the edge as `fluxer-voice-edge-edge-1`.+On a voice machine, `rexctl stop`, `rexctl down`, `rexctl restart`, `rexctl logs` and `rexctl backup` don't apply. Docker runs each server as `fluxer-voice-<id>-livekit-1`, and the edge as `fluxer-voice-edge-edge-1`.```shdocker logs fluxer-voice-fra-server-1-livekit-1diff --git a/fluxer_rexctl/cmd/lifecycle.go b/fluxer_rexctl/cmd/lifecycle.goindex 90022543e..fd9801116 100644--- a/fluxer_rexctl/cmd/lifecycle.go+++ b/fluxer_rexctl/cmd/lifecycle.go@@ -715,7 +715,9 @@ func defaultRoute() bool {}func newStopCmd(app *App) *cobra.Command {- return newBootableCmd(app, "stop", "Stop your instance", runStop, runBootStop)+ c := newBootableCmd(app, "stop", "Stop your instance", runStop, runBootStop)+ c.Long = "Stop Fluxer and keep its containers. Fluxer stays stopped until you run rexctl start. To remove the containers too, run rexctl down."+ return c}func runStop(ctx context.Context, app *App) error {@@ -757,6 +759,62 @@ func runStop(ctx context.Context, app *App) error {})}+func newDownCmd(app *App) *cobra.Command {+ return &cobra.Command{+ Use: "down",+ Short: "Stop your instance and remove its containers",+ Long: "Stop Fluxer and remove its containers and networks, like docker compose down. Your data, settings, backups and images stay. Fluxer stays stopped until you run rexctl start, which creates the containers again.",+ Args: noArgs,+ RunE: func(c *cobra.Command, _ []string) error {+ return runDown(c.Context(), app)+ },+ }+}++func runDown(ctx context.Context, app *App) error {+ inst, err := app.Instance()+ if err != nil {+ return err+ }+ return app.Locked(ctx, inst, func() error {+ if err := managed(inst); err != nil {+ return err+ }+ p, err := app.Named(ctx, inst)+ if err != nil {+ return err+ }+ if p.Engine.TooOld {+ return ui.Refused("rexctl can't create Fluxer's containers again with this version of Podman.", "Run rexctl stop to stop Fluxer and keep its containers.")+ }+ err = app.UI.Step(ctx, "Removing Fluxer's containers", func(ctx context.Context, s *ui.Step) error {+ switch n := len(inst.State.Voice); {+ case n == 1:+ s.Info("Removing the voice server %s too. Calls on it end.", inst.State.Voice[0].ID)+ case n > 1:+ s.Info("Removing %d voice servers too. Calls on them end.", n)+ }+ eachVoiceServer(app, inst, "removing", func(srv *instance.VoiceServer) error {+ return voiceProject(p.Engine, inst, srv).DownWithin(context.WithoutCancel(ctx), false, deploy.VoiceStopTimeout)+ })+ if err := p.Down(ctx, false); err != nil {+ return ui.Wrap(engineFailure(err), "Couldn't remove Fluxer's containers.", "Run rexctl status to see what's still running.")+ }+ s.Done("Stopped Fluxer and removed its containers and networks.")+ return nil+ })+ if err != nil {+ return err+ }+ inst.State.Stopped = true+ if err := inst.Save(); err != nil {+ return ui.Wrap(err, "Couldn't save your instance's state.", "Run rexctl down again.")+ }+ app.UI.Info("Your data and settings are kept. Run rexctl start to start Fluxer again.")+ return nil+ })+}+func runBootStop(ctx context.Context, app *App) error {inst, err := bootInstance(app)if err != nil || inst == nil {diff --git a/fluxer_rexctl/cmd/root.go b/fluxer_rexctl/cmd/root.goindex a2bc90f75..75143777a 100644--- a/fluxer_rexctl/cmd/root.go+++ b/fluxer_rexctl/cmd/root.go@@ -108,6 +108,7 @@ func newRoot(app *App) *cobra.Command {newLogsCmd(app),newStartCmd(app),newStopCmd(app),+ newDownCmd(app),newRestartCmd(app),newUpgradeCmd(app),newAutoUpgradeCmd(app),@@ -161,7 +162,7 @@ const ()var commandGroups = map[string][]string{- "run": {"install", "setup", "status", "doctor", "logs", "start", "stop", "restart", "upgrade", "auto-upgrade", "rollback", "backup", "restore", "proxy", "takeover", "eject", "use", "uninstall"},+ "run": {"install", "setup", "status", "doctor", "logs", "start", "stop", "down", "restart", "upgrade", "auto-upgrade", "rollback", "backup", "restore", "proxy", "takeover", "eject", "use", "uninstall"},"manage": {"users", "admins", "invites", "voice", "registration", "email", "branding", "search", "config"},"other": {"version", "docs"},}diff --git a/fluxer_rexctl/cmd/uninstall.go b/fluxer_rexctl/cmd/uninstall.goindex d85061a1e..71bb80cf1 100644--- a/fluxer_rexctl/cmd/uninstall.go+++ b/fluxer_rexctl/cmd/uninstall.go@@ -24,6 +24,7 @@ func newUninstallCmd(app *App) *cobra.Command {c := &cobra.Command{Use: "uninstall",Short: "Remove Fluxer from this machine",+ Long: "Remove Fluxer from this machine, with its data and backups unless you pass --keep-data. To stop Fluxer and keep everything, run rexctl stop or rexctl down.",Args: noArgs,RunE: func(c *cobra.Command, _ []string) error {return runUninstall(c.Context(), app, keepData, confirm)