diff --git a/fleetctl/fleetctl.go b/fleetctl/fleetctl.go index 71785606d..f7eceb660 100644 --- a/fleetctl/fleetctl.go +++ b/fleetctl/fleetctl.go @@ -106,6 +106,7 @@ var ( BlockAttempts int Fields string SSHPort int + Replace bool }{} // used to cache MachineStates @@ -595,7 +596,7 @@ func createUnit(name string, uf *unit.UnitFile) (*schema.Unit, error) { // Any error encountered during these steps is returned immediately (i.e. // subsequent Jobs are not acted on). An error is also returned if none of the // above conditions match a given Job. -func lazyCreateUnits(args []string) error { +func lazyCreateUnits(args []string, replace bool) error { errchan := make(chan error) var wg sync.WaitGroup for _, arg := range args { @@ -609,7 +610,7 @@ func lazyCreateUnits(args []string) error { if err != nil { return fmt.Errorf("error retrieving Unit(%s) from Registry: %v", name, err) } - if u != nil { + if !replace && u != nil { log.Debugf("Found Unit(%s) in Registry, no need to recreate it", name) warnOnDifferentLocalUnit(arg, u) continue @@ -647,7 +648,7 @@ func lazyCreateUnits(args []string) error { if err != nil { return fmt.Errorf("failed getting template Unit(%s) from file: %v", uni.Template, err) } - } else { + } else if !replace { warnOnDifferentLocalUnit(arg, tmpl) uf = schema.MapSchemaUnitOptionsToUnitFile(tmpl.Options) } diff --git a/fleetctl/load.go b/fleetctl/load.go index 497f86058..9d4330259 100644 --- a/fleetctl/load.go +++ b/fleetctl/load.go @@ -24,7 +24,7 @@ var ( cmdLoadUnits = &Command{ Name: "load", Summary: "Schedule one or more units in the cluster, first submitting them if necessary.", - Usage: "[--no-block|--block-attempts=N] UNIT...", + Usage: "[--no-block|--block-attempts=N|--replace] UNIT...", Description: `Load one or many units in the cluster into systemd, but do not start. Select units to load by glob matching for units in the current working directory @@ -43,10 +43,11 @@ func init() { cmdLoadUnits.Flags.BoolVar(&sharedFlags.Sign, "sign", false, "DEPRECATED - this option cannot be used") cmdLoadUnits.Flags.IntVar(&sharedFlags.BlockAttempts, "block-attempts", 0, "Wait until the jobs are loaded, performing up to N attempts before giving up. A value of 0 indicates no limit. Does not apply to global units.") cmdLoadUnits.Flags.BoolVar(&sharedFlags.NoBlock, "no-block", false, "Do not wait until the jobs have been loaded before exiting. Always the case for global units.") + cmdLoadUnits.Flags.BoolVar(&sharedFlags.Replace, "replace", false, "replace (I need help with the text)") } func runLoadUnits(args []string) (exit int) { - if err := lazyCreateUnits(args); err != nil { + if err := lazyCreateUnits(args, sharedFlags.Replace); err != nil { stderr("Error creating units: %v", err) return 1 } diff --git a/fleetctl/start.go b/fleetctl/start.go index 77ea0d343..c7ba44ccd 100644 --- a/fleetctl/start.go +++ b/fleetctl/start.go @@ -24,7 +24,7 @@ var ( cmdStartUnit = &Command{ Name: "start", Summary: "Instruct systemd to start one or more units in the cluster, first submitting and loading if necessary.", - Usage: "[--no-block|--block-attempts=N] UNIT...", + Usage: "[--no-block|--block-attempts=N|--replace] UNIT...", Description: `Start one or many units on the cluster. Select units to start by glob matching for units in the current working directory or matching names of previously submitted units. @@ -51,10 +51,11 @@ func init() { cmdStartUnit.Flags.BoolVar(&sharedFlags.Sign, "sign", false, "DEPRECATED - this option cannot be used") cmdStartUnit.Flags.IntVar(&sharedFlags.BlockAttempts, "block-attempts", 0, "Wait until the units are launched, performing up to N attempts before giving up. A value of 0 indicates no limit. Does not apply to global units.") cmdStartUnit.Flags.BoolVar(&sharedFlags.NoBlock, "no-block", false, "Do not wait until the units have launched before exiting. Always the case for global units.") + cmdStartUnit.Flags.BoolVar(&sharedFlags.Replace, "replace", false, "replace (I need help with the text)") } func runStartUnit(args []string) (exit int) { - if err := lazyCreateUnits(args); err != nil { + if err := lazyCreateUnits(args, sharedFlags.Replace); err != nil { stderr("Error creating units: %v", err) return 1 } diff --git a/fleetctl/submit.go b/fleetctl/submit.go index cbfe03f93..904c8b4a1 100644 --- a/fleetctl/submit.go +++ b/fleetctl/submit.go @@ -17,7 +17,7 @@ package main var cmdSubmitUnit = &Command{ Name: "submit", Summary: "Upload one or more units to the cluster without starting them", - Usage: "UNIT...", + Usage: "[--replace] UNIT...", Description: `Upload one or more units to the cluster without starting them. Useful for validating units before they are started. @@ -33,10 +33,11 @@ Submit a directory of units with glob matching: func init() { cmdSubmitUnit.Flags.BoolVar(&sharedFlags.Sign, "sign", false, "DEPRECATED - this option cannot be used") + cmdSubmitUnit.Flags.BoolVar(&sharedFlags.Replace, "replace", false, "replace (I need help with the text)") } func runSubmitUnits(args []string) (exit int) { - if err := lazyCreateUnits(args); err != nil { + if err := lazyCreateUnits(args, sharedFlags.Replace); err != nil { stderr("Error creating units: %v", err) exit = 1 }