Download this file
| 1 | package instancectl |
| 2 | |
| 3 | import "context" |
| 4 | |
| 5 | func (u ClaimUnits) StopInvocation(ctx context.Context, host, invocation string) error { |
| 6 | if u.BoundUnit == "" && u.BoundHost == "" { |
| 7 | return u.Stop(ctx, host) |
| 8 | } |
| 9 | unit, group, err := u.Placement(host) |
| 10 | if err != nil || invocation == "" || u.Systemctl == nil { |
| 11 | return ErrClaimUnit |
| 12 | } |
| 13 | state, err := u.show(ctx, unit, "ActiveState", "InvocationID", "ControlGroup") |
| 14 | if err != nil { |
| 15 | return err |
| 16 | } |
| 17 | if state["InvocationID"] != invocation || state["ControlGroup"] != "/"+group { |
| 18 | return ErrClaimUnitBusy |
| 19 | } |
| 20 | if err := u.Stop(ctx, host); err != nil { |
| 21 | return err |
| 22 | } |
| 23 | state, err = u.show(ctx, unit, "InvocationID", "ControlGroup") |
| 24 | if err != nil { |
| 25 | return err |
| 26 | } |
| 27 | // systemctl stops by name. A replacement between the check and stop |
| 28 | // makes the result uncertain; never issue a successful stop receipt. |
| 29 | if state["InvocationID"] != "" && state["InvocationID"] != invocation || state["ControlGroup"] != "" && state["ControlGroup"] != "/"+group { |
| 30 | return ErrClaimUnitBusy |
| 31 | } |
| 32 | return nil |
| 33 | } |
| 34 | |