2023-04-10 15:36:59 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2020-01-13 10:34:46 +00:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/posener/complete"
|
|
|
|
)
|
|
|
|
|
|
|
|
type SystemGCCommand struct {
|
|
|
|
Meta
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *SystemGCCommand) Help() string {
|
|
|
|
helpText := `
|
|
|
|
Usage: nomad system gc [options]
|
|
|
|
|
|
|
|
Initializes a garbage collection of jobs, evaluations, allocations, and nodes.
|
|
|
|
|
2020-11-19 21:38:08 +00:00
|
|
|
If ACLs are enabled, this option requires a management token.
|
|
|
|
|
2020-01-13 10:34:46 +00:00
|
|
|
General Options:
|
|
|
|
|
2020-11-19 16:15:23 +00:00
|
|
|
` + generalOptionsUsage(usageOptsDefault|usageOptsNoNamespace)
|
2020-01-13 10:34:46 +00:00
|
|
|
return strings.TrimSpace(helpText)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *SystemGCCommand) Synopsis() string {
|
|
|
|
return "Run the system garbage collection process"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *SystemGCCommand) AutocompleteFlags() complete.Flags {
|
|
|
|
return c.Meta.AutocompleteFlags(FlagSetClient)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *SystemGCCommand) AutocompleteArgs() complete.Predictor {
|
|
|
|
return complete.PredictNothing
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *SystemGCCommand) Name() string { return "system gc" }
|
|
|
|
|
|
|
|
func (c *SystemGCCommand) Run(args []string) int {
|
2021-06-28 08:57:50 +00:00
|
|
|
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
|
|
|
|
flags.Usage = func() { c.Ui.Output(c.Help()) }
|
|
|
|
|
|
|
|
if err := flags.Parse(args); err != nil {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
if args = flags.Args(); len(args) > 0 {
|
|
|
|
c.Ui.Error("This command takes no arguments")
|
|
|
|
c.Ui.Error(commandErrorText(c))
|
|
|
|
}
|
2020-01-13 10:34:46 +00:00
|
|
|
|
|
|
|
// Get the HTTP client
|
|
|
|
client, err := c.Meta.Client()
|
|
|
|
if err != nil {
|
|
|
|
c.Ui.Error(fmt.Sprintf("Error initializing client: %s", err))
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := client.System().GarbageCollect(); err != nil {
|
|
|
|
c.Ui.Error(fmt.Sprintf("Error running system garbage-collection: %s", err))
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
return 0
|
|
|
|
}
|