diff --git a/api/tasks.go b/api/tasks.go index 76c1be658..d3804850c 100644 --- a/api/tasks.go +++ b/api/tasks.go @@ -82,20 +82,23 @@ func (r *RestartPolicy) Merge(rp *RestartPolicy) { // The ServiceCheck data model represents the consul health check that // Nomad registers for a Task type ServiceCheck struct { - Id string - Name string - Type string - Command string - Args []string - Path string - Protocol string - PortLabel string `mapstructure:"port"` - Interval time.Duration - Timeout time.Duration - InitialStatus string `mapstructure:"initial_status"` - TLSSkipVerify bool `mapstructure:"tls_skip_verify"` - Header map[string][]string - Method string + Id string + Name string + Type string + Command string + Args []string + Path string + Protocol string + PortLabel string `mapstructure:"port"` + Interval time.Duration + Timeout time.Duration + InitialStatus string `mapstructure:"initial_status"` + TLSSkipVerify bool `mapstructure:"tls_skip_verify"` + Header map[string][]string + Method string + RestartAfter int + RestartGrace time.Duration + RestartWarning bool } // The Service model represents a Consul service definition diff --git a/command/agent/job_endpoint.go b/command/agent/job_endpoint.go index 75a77f0fc..ea1cfdcc6 100644 --- a/command/agent/job_endpoint.go +++ b/command/agent/job_endpoint.go @@ -690,19 +690,22 @@ func ApiTaskToStructsTask(apiTask *api.Task, structsTask *structs.Task) { structsTask.Services[i].Checks = make([]*structs.ServiceCheck, l) for j, check := range service.Checks { structsTask.Services[i].Checks[j] = &structs.ServiceCheck{ - Name: check.Name, - Type: check.Type, - Command: check.Command, - Args: check.Args, - Path: check.Path, - Protocol: check.Protocol, - PortLabel: check.PortLabel, - Interval: check.Interval, - Timeout: check.Timeout, - InitialStatus: check.InitialStatus, - TLSSkipVerify: check.TLSSkipVerify, - Header: check.Header, - Method: check.Method, + Name: check.Name, + Type: check.Type, + Command: check.Command, + Args: check.Args, + Path: check.Path, + Protocol: check.Protocol, + PortLabel: check.PortLabel, + Interval: check.Interval, + Timeout: check.Timeout, + InitialStatus: check.InitialStatus, + TLSSkipVerify: check.TLSSkipVerify, + Header: check.Header, + Method: check.Method, + RestartAfter: check.RestartAfter, + RestartGrace: check.RestartGrace, + RestartWarning: check.RestartWarning, } } } diff --git a/jobspec/parse.go b/jobspec/parse.go index efda8f95f..dd3105e3f 100644 --- a/jobspec/parse.go +++ b/jobspec/parse.go @@ -965,6 +965,9 @@ func parseChecks(service *api.Service, checkObjs *ast.ObjectList) error { "tls_skip_verify", "header", "method", + "restart_grace_period", + "restart_on_warning", + "restart_after_unhealthy", } if err := checkHCLKeys(co.Val, valid); err != nil { return multierror.Prefix(err, "check ->") diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index 8175024a3..cf53c6db2 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -2775,19 +2775,22 @@ const ( // The ServiceCheck data model represents the consul health check that // Nomad registers for a Task type ServiceCheck struct { - Name string // Name of the check, defaults to id - Type string // Type of the check - tcp, http, docker and script - Command string // Command is the command to run for script checks - Args []string // Args is a list of argumes for script checks - Path string // path of the health check url for http type check - Protocol string // Protocol to use if check is http, defaults to http - PortLabel string // The port to use for tcp/http checks - Interval time.Duration // Interval of the check - Timeout time.Duration // Timeout of the response from the check before consul fails the check - InitialStatus string // Initial status of the check - TLSSkipVerify bool // Skip TLS verification when Protocol=https - Method string // HTTP Method to use (GET by default) - Header map[string][]string // HTTP Headers for Consul to set when making HTTP checks + Name string // Name of the check, defaults to id + Type string // Type of the check - tcp, http, docker and script + Command string // Command is the command to run for script checks + Args []string // Args is a list of argumes for script checks + Path string // path of the health check url for http type check + Protocol string // Protocol to use if check is http, defaults to http + PortLabel string // The port to use for tcp/http checks + Interval time.Duration // Interval of the check + Timeout time.Duration // Timeout of the response from the check before consul fails the check + InitialStatus string // Initial status of the check + TLSSkipVerify bool // Skip TLS verification when Protocol=https + Method string // HTTP Method to use (GET by default) + Header map[string][]string // HTTP Headers for Consul to set when making HTTP checks + RestartAfter int // Restart task after this many unhealthy intervals + RestartGrace time.Duration // Grace time to give tasks after starting to get healthy + RestartWarning bool // If true treat checks in `warning` as unhealthy } func (sc *ServiceCheck) Copy() *ServiceCheck {