diff --git a/agent/agent.go b/agent/agent.go index 800302c1aed6..5da86230f25b 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -1823,11 +1823,6 @@ func (a *Agent) AddCheck(check *structs.HealthCheck, chkType *structs.CheckType, check.CheckID, checks.MinInterval)) chkType.Interval = checks.MinInterval } - if chkType.Script != "" { - a.logger.Printf("[WARN] agent: check %q has the 'script' field, which has been deprecated "+ - "and replaced with the 'args' field. See https://www.consul.io/docs/agent/checks.html", - check.CheckID) - } if a.dockerClient == nil { dc, err := checks.NewDockerClient(os.Getenv("DOCKER_HOST"), checks.BufSize) @@ -1844,7 +1839,6 @@ func (a *Agent) AddCheck(check *structs.HealthCheck, chkType *structs.CheckType, CheckID: check.CheckID, DockerContainerID: chkType.DockerContainerID, Shell: chkType.Shell, - Script: chkType.Script, ScriptArgs: chkType.ScriptArgs, Interval: chkType.Interval, Logger: a.logger, @@ -1866,16 +1860,10 @@ func (a *Agent) AddCheck(check *structs.HealthCheck, chkType *structs.CheckType, check.CheckID, checks.MinInterval) chkType.Interval = checks.MinInterval } - if chkType.Script != "" { - a.logger.Printf("[WARN] agent: check %q has the 'script' field, which has been deprecated "+ - "and replaced with the 'args' field. See https://www.consul.io/docs/agent/checks.html", - check.CheckID) - } monitor := &checks.CheckMonitor{ Notify: a.State, CheckID: check.CheckID, - Script: chkType.Script, ScriptArgs: chkType.ScriptArgs, Interval: chkType.Interval, Timeout: chkType.Timeout, diff --git a/agent/agent_endpoint_test.go b/agent/agent_endpoint_test.go index c6e4f0532484..1a62a8427909 100644 --- a/agent/agent_endpoint_test.go +++ b/agent/agent_endpoint_test.go @@ -716,14 +716,6 @@ func TestAgent_RegisterCheck_Scripts(t *testing.T) { name string check map[string]interface{} }{ - { - "< Consul 1.0.0", - map[string]interface{}{ - "Name": "test", - "Interval": "2s", - "Script": "true", - }, - }, { "== Consul 1.0.0", map[string]interface{}{ diff --git a/agent/agent_test.go b/agent/agent_test.go index 69a7d124a6a3..b4989de662c8 100644 --- a/agent/agent_test.go +++ b/agent/agent_test.go @@ -651,8 +651,8 @@ func TestAgent_AddCheck(t *testing.T) { Status: api.HealthCritical, } chk := &structs.CheckType{ - Script: "exit 0", - Interval: 15 * time.Second, + ScriptArgs: []string{"exit", "0"}, + Interval: 15 * time.Second, } err := a.AddCheck(health, chk, false, "") if err != nil { @@ -690,8 +690,8 @@ func TestAgent_AddCheck_StartPassing(t *testing.T) { Status: api.HealthPassing, } chk := &structs.CheckType{ - Script: "exit 0", - Interval: 15 * time.Second, + ScriptArgs: []string{"exit", "0"}, + Interval: 15 * time.Second, } err := a.AddCheck(health, chk, false, "") if err != nil { @@ -729,8 +729,8 @@ func TestAgent_AddCheck_MinInterval(t *testing.T) { Status: api.HealthCritical, } chk := &structs.CheckType{ - Script: "exit 0", - Interval: time.Microsecond, + ScriptArgs: []string{"exit", "0"}, + Interval: time.Microsecond, } err := a.AddCheck(health, chk, false, "") if err != nil { @@ -764,8 +764,8 @@ func TestAgent_AddCheck_MissingService(t *testing.T) { ServiceID: "baz", } chk := &structs.CheckType{ - Script: "exit 0", - Interval: time.Microsecond, + ScriptArgs: []string{"exit", "0"}, + Interval: time.Microsecond, } err := a.AddCheck(health, chk, false, "") if err == nil || err.Error() != `ServiceID "baz" does not exist` { @@ -829,8 +829,8 @@ func TestAgent_AddCheck_ExecDisable(t *testing.T) { Status: api.HealthCritical, } chk := &structs.CheckType{ - Script: "exit 0", - Interval: 15 * time.Second, + ScriptArgs: []string{"exit", "0"}, + Interval: 15 * time.Second, } err := a.AddCheck(health, chk, false, "") if err == nil || !strings.Contains(err.Error(), "Scripts are disabled on this agent") { @@ -904,8 +904,8 @@ func TestAgent_RemoveCheck(t *testing.T) { Status: api.HealthCritical, } chk := &structs.CheckType{ - Script: "exit 0", - Interval: 15 * time.Second, + ScriptArgs: []string{"exit", "0"}, + Interval: 15 * time.Second, } err := a.AddCheck(health, chk, false, "") if err != nil { @@ -1315,8 +1315,8 @@ func TestAgent_PersistCheck(t *testing.T) { Status: api.HealthPassing, } chkType := &structs.CheckType{ - Script: "/bin/true", - Interval: 10 * time.Second, + ScriptArgs: []string{"/bin/true"}, + Interval: 10 * time.Second, } file := filepath.Join(a.Config.DataDir, checksDir, checkIDHash(check.CheckID)) @@ -1473,7 +1473,7 @@ func TestAgent_PurgeCheckOnDuplicate(t *testing.T) { id = "mem" name = "memory check" notes = "my cool notes" - script = "/bin/check-redis.py" + args = ["/bin/check-redis.py"] interval = "30s" } `) diff --git a/agent/config/builder.go b/agent/config/builder.go index 644bd0583ad4..7318e7ab32d2 100644 --- a/agent/config/builder.go +++ b/agent/config/builder.go @@ -967,7 +967,6 @@ func (b *Builder) checkVal(v *CheckDefinition) *structs.CheckDefinition { ServiceID: b.stringVal(v.ServiceID), Token: b.stringVal(v.Token), Status: b.stringVal(v.Status), - Script: b.stringVal(v.Script), ScriptArgs: v.ScriptArgs, HTTP: b.stringVal(v.HTTP), Header: v.Header, diff --git a/agent/config/config.go b/agent/config/config.go index 5447f95c4a6d..e92b76a453c7 100644 --- a/agent/config/config.go +++ b/agent/config/config.go @@ -331,7 +331,6 @@ type CheckDefinition struct { ServiceID *string `json:"service_id,omitempty" hcl:"service_id" mapstructure:"service_id"` Token *string `json:"token,omitempty" hcl:"token" mapstructure:"token"` Status *string `json:"status,omitempty" hcl:"status" mapstructure:"status"` - Script *string `json:"script,omitempty" hcl:"script" mapstructure:"script"` ScriptArgs []string `json:"args,omitempty" hcl:"args" mapstructure:"args"` HTTP *string `json:"http,omitempty" hcl:"http" mapstructure:"http"` Header map[string][]string `json:"header,omitempty" hcl:"header" mapstructure:"header"` diff --git a/agent/config/runtime_test.go b/agent/config/runtime_test.go index 55a3c4d50443..cc8deca9baa7 100644 --- a/agent/config/runtime_test.go +++ b/agent/config/runtime_test.go @@ -1883,17 +1883,17 @@ func TestConfigFlagsAndEdgecases(t *testing.T) { `-data-dir=` + dataDir, }, json: []string{ - `{ "check": { "name": "a", "script": "/bin/true" } }`, - `{ "check": { "name": "b", "script": "/bin/false" } }`, + `{ "check": { "name": "a", "args": ["/bin/true"] } }`, + `{ "check": { "name": "b", "args": ["/bin/false"] } }`, }, hcl: []string{ - `check = { name = "a" script = "/bin/true" }`, - `check = { name = "b" script = "/bin/false" }`, + `check = { name = "a" args = ["/bin/true"] }`, + `check = { name = "b" args = ["/bin/false"] }`, }, patch: func(rt *RuntimeConfig) { rt.Checks = []*structs.CheckDefinition{ - &structs.CheckDefinition{Name: "a", Script: "/bin/true"}, - &structs.CheckDefinition{Name: "b", Script: "/bin/false"}, + &structs.CheckDefinition{Name: "a", ScriptArgs: []string{"/bin/true"}}, + &structs.CheckDefinition{Name: "b", ScriptArgs: []string{"/bin/false"}}, } rt.DataDir = dataDir }, @@ -2265,7 +2265,6 @@ func TestFullConfig(t *testing.T) { "service_id": "L8G0QNmR", "token": "oo4BCTgJ", "status": "qLykAl5u", - "script": "dhGfIF8n", "args": ["f3BemRjy", "e5zgpef7"], "http": "29B93haH", "header": { @@ -2290,7 +2289,6 @@ func TestFullConfig(t *testing.T) { "service_id": "lSulPcyz", "token": "toO59sh8", "status": "9RlWsXMV", - "script": "8qbd8tWw", "args": ["4BAJttck", "4D2NPtTQ"], "http": "dohLcyQ2", "header": { @@ -2314,7 +2312,6 @@ func TestFullConfig(t *testing.T) { "service_id": "CmUUcRna", "token": "a3nQzHuy", "status": "irj26nf3", - "script": "FJsI1oXt", "args": ["9s526ogY", "gSlOHj1w"], "http": "yzhgsQ7Y", "header": { @@ -2449,7 +2446,6 @@ func TestFullConfig(t *testing.T) { "name": "iehanzuq", "status": "rCvn53TH", "notes": "fti5lfF3", - "script": "rtj34nfd", "args": ["16WRUmwS", "QWk7j7ae"], "http": "dl3Fgme3", "header": { @@ -2472,7 +2468,6 @@ func TestFullConfig(t *testing.T) { "name": "sgV4F7Pk", "notes": "yP5nKbW0", "status": "7oLMEyfu", - "script": "NlUQ3nTE", "args": ["5wEZtZpv", "0Ihyk8cS"], "http": "KyDjGY9H", "header": { @@ -2494,7 +2489,6 @@ func TestFullConfig(t *testing.T) { "name": "IEqrzrsd", "notes": "SVqApqeM", "status": "XXkVoZXt", - "script": "IXLZTM6E", "args": ["wD05Bvao", "rLYB7kQC"], "http": "kyICZsn8", "header": { @@ -2527,7 +2521,6 @@ func TestFullConfig(t *testing.T) { "name": "atDGP7n5", "status": "pDQKEhWL", "notes": "Yt8EDLev", - "script": "MDu7wjlD", "args": ["81EDZLPa", "bPY5X8xd"], "http": "qzHYvmJO", "header": { @@ -2559,7 +2552,6 @@ func TestFullConfig(t *testing.T) { "name": "9OOS93ne", "notes": "CQy86DH0", "status": "P0SWDvrk", - "script": "6BhLJ7R9", "args": ["EXvkYIuG", "BATOyt6h"], "http": "u97ByEiW", "header": { @@ -2581,7 +2573,6 @@ func TestFullConfig(t *testing.T) { "name": "PQSaPWlT", "notes": "jKChDOdl", "status": "5qFz6OZn", - "script": "PbdxFZ3K", "args": ["NMtYWlT9", "vj74JXsm"], "http": "1LBDJhw4", "header": { @@ -2706,7 +2697,6 @@ func TestFullConfig(t *testing.T) { service_id = "L8G0QNmR" token = "oo4BCTgJ" status = "qLykAl5u" - script = "dhGfIF8n" args = ["f3BemRjy", "e5zgpef7"] http = "29B93haH" header = { @@ -2731,7 +2721,6 @@ func TestFullConfig(t *testing.T) { service_id = "lSulPcyz" token = "toO59sh8" status = "9RlWsXMV" - script = "8qbd8tWw" args = ["4BAJttck", "4D2NPtTQ"] http = "dohLcyQ2" header = { @@ -2755,7 +2744,6 @@ func TestFullConfig(t *testing.T) { service_id = "CmUUcRna" token = "a3nQzHuy" status = "irj26nf3" - script = "FJsI1oXt" args = ["9s526ogY", "gSlOHj1w"] http = "yzhgsQ7Y" header = { @@ -2890,7 +2878,6 @@ func TestFullConfig(t *testing.T) { name = "iehanzuq" status = "rCvn53TH" notes = "fti5lfF3" - script = "rtj34nfd" args = ["16WRUmwS", "QWk7j7ae"] http = "dl3Fgme3" header = { @@ -2913,7 +2900,6 @@ func TestFullConfig(t *testing.T) { name = "sgV4F7Pk" notes = "yP5nKbW0" status = "7oLMEyfu" - script = "NlUQ3nTE" args = ["5wEZtZpv", "0Ihyk8cS"] http = "KyDjGY9H" header = { @@ -2935,7 +2921,6 @@ func TestFullConfig(t *testing.T) { name = "IEqrzrsd" notes = "SVqApqeM" status = "XXkVoZXt" - script = "IXLZTM6E" args = ["wD05Bvao", "rLYB7kQC"] http = "kyICZsn8" header = { @@ -2968,7 +2953,6 @@ func TestFullConfig(t *testing.T) { name = "atDGP7n5" status = "pDQKEhWL" notes = "Yt8EDLev" - script = "MDu7wjlD" args = ["81EDZLPa", "bPY5X8xd"] http = "qzHYvmJO" header = { @@ -3000,7 +2984,6 @@ func TestFullConfig(t *testing.T) { name = "9OOS93ne" notes = "CQy86DH0" status = "P0SWDvrk" - script = "6BhLJ7R9" args = ["EXvkYIuG", "BATOyt6h"] http = "u97ByEiW" header = { @@ -3022,7 +3005,6 @@ func TestFullConfig(t *testing.T) { name = "PQSaPWlT" notes = "jKChDOdl" status = "5qFz6OZn" - script = "PbdxFZ3K" args = ["NMtYWlT9", "vj74JXsm"] http = "1LBDJhw4" header = { @@ -3286,7 +3268,6 @@ func TestFullConfig(t *testing.T) { ServiceID: "lSulPcyz", Token: "toO59sh8", Status: "9RlWsXMV", - Script: "8qbd8tWw", ScriptArgs: []string{"4BAJttck", "4D2NPtTQ"}, HTTP: "dohLcyQ2", Header: map[string][]string{ @@ -3310,7 +3291,6 @@ func TestFullConfig(t *testing.T) { ServiceID: "CmUUcRna", Token: "a3nQzHuy", Status: "irj26nf3", - Script: "FJsI1oXt", ScriptArgs: []string{"9s526ogY", "gSlOHj1w"}, HTTP: "yzhgsQ7Y", Header: map[string][]string{ @@ -3334,7 +3314,6 @@ func TestFullConfig(t *testing.T) { ServiceID: "L8G0QNmR", Token: "oo4BCTgJ", Status: "qLykAl5u", - Script: "dhGfIF8n", ScriptArgs: []string{"f3BemRjy", "e5zgpef7"}, HTTP: "29B93haH", Header: map[string][]string{ @@ -3454,7 +3433,6 @@ func TestFullConfig(t *testing.T) { Name: "atDGP7n5", Status: "pDQKEhWL", Notes: "Yt8EDLev", - Script: "MDu7wjlD", ScriptArgs: []string{"81EDZLPa", "bPY5X8xd"}, HTTP: "qzHYvmJO", Header: map[string][]string{ @@ -3487,7 +3465,6 @@ func TestFullConfig(t *testing.T) { Name: "9OOS93ne", Notes: "CQy86DH0", Status: "P0SWDvrk", - Script: "6BhLJ7R9", ScriptArgs: []string{"EXvkYIuG", "BATOyt6h"}, HTTP: "u97ByEiW", Header: map[string][]string{ @@ -3509,7 +3486,6 @@ func TestFullConfig(t *testing.T) { Name: "PQSaPWlT", Notes: "jKChDOdl", Status: "5qFz6OZn", - Script: "PbdxFZ3K", ScriptArgs: []string{"NMtYWlT9", "vj74JXsm"}, HTTP: "1LBDJhw4", Header: map[string][]string{ @@ -3543,7 +3519,6 @@ func TestFullConfig(t *testing.T) { Name: "sgV4F7Pk", Notes: "yP5nKbW0", Status: "7oLMEyfu", - Script: "NlUQ3nTE", ScriptArgs: []string{"5wEZtZpv", "0Ihyk8cS"}, HTTP: "KyDjGY9H", Header: map[string][]string{ @@ -3565,7 +3540,6 @@ func TestFullConfig(t *testing.T) { Name: "IEqrzrsd", Notes: "SVqApqeM", Status: "XXkVoZXt", - Script: "IXLZTM6E", ScriptArgs: []string{"wD05Bvao", "rLYB7kQC"}, HTTP: "kyICZsn8", Header: map[string][]string{ @@ -3587,7 +3561,6 @@ func TestFullConfig(t *testing.T) { Name: "iehanzuq", Status: "rCvn53TH", Notes: "fti5lfF3", - Script: "rtj34nfd", ScriptArgs: []string{"16WRUmwS", "QWk7j7ae"}, HTTP: "dl3Fgme3", Header: map[string][]string{ @@ -4007,7 +3980,6 @@ func TestSanitize(t *testing.T) { "Method": "", "Name": "zoo", "Notes": "", - "Script": "", "ScriptArgs": [], "ServiceID": "", "Shell": "", @@ -4139,7 +4111,6 @@ func TestSanitize(t *testing.T) { "Method": "", "Name": "blurb", "Notes": "", - "Script": "", "ScriptArgs": [], "Shell": "", "Status": "", diff --git a/agent/structs/check_definition.go b/agent/structs/check_definition.go index 364c6b3d6872..0ee6c20495c9 100644 --- a/agent/structs/check_definition.go +++ b/agent/structs/check_definition.go @@ -21,7 +21,6 @@ type CheckDefinition struct { // // ID (CheckID), Name, Status, Notes // - Script string ScriptArgs []string HTTP string Header map[string][]string @@ -63,7 +62,6 @@ func (c *CheckDefinition) CheckType() *CheckType { Status: c.Status, Notes: c.Notes, - Script: c.Script, ScriptArgs: c.ScriptArgs, HTTP: c.HTTP, GRPC: c.GRPC, diff --git a/agent/structs/check_definition_test.go b/agent/structs/check_definition_test.go index c7fdae81ca49..af240aa956c8 100644 --- a/agent/structs/check_definition_test.go +++ b/agent/structs/check_definition_test.go @@ -83,7 +83,7 @@ func TestCheckDefinitionToCheckType(t *testing.T) { ServiceID: "svcid", Token: "tok", - Script: "/bin/foo", + ScriptArgs: []string{"/bin/foo"}, HTTP: "someurl", TCP: "host:port", Interval: 1 * time.Second, @@ -100,7 +100,7 @@ func TestCheckDefinitionToCheckType(t *testing.T) { Status: "green", Notes: "notes", - Script: "/bin/foo", + ScriptArgs: []string{"/bin/foo"}, HTTP: "someurl", TCP: "host:port", Interval: 1 * time.Second, diff --git a/agent/structs/check_type.go b/agent/structs/check_type.go index ea5b10aa00b0..23a68307775c 100644 --- a/agent/structs/check_type.go +++ b/agent/structs/check_type.go @@ -25,7 +25,6 @@ type CheckType struct { // fields copied to CheckDefinition // Update CheckDefinition when adding fields here - Script string ScriptArgs []string HTTP string Header map[string][]string @@ -70,7 +69,7 @@ func (c *CheckType) Empty() bool { // IsScript checks if this is a check that execs some kind of script. func (c *CheckType) IsScript() bool { - return c.Script != "" || len(c.ScriptArgs) > 0 + return len(c.ScriptArgs) > 0 } // IsTTL checks if this is a TTL type diff --git a/agent/structs/service_definition_test.go b/agent/structs/service_definition_test.go index 12a9ef99afcc..d3bab4a08f23 100644 --- a/agent/structs/service_definition_test.go +++ b/agent/structs/service_definition_test.go @@ -14,8 +14,8 @@ func TestAgentStructs_CheckTypes(t *testing.T) { // Singular Check field works svc.Check = CheckType{ - Script: "/foo/bar", - Interval: 10 * time.Second, + ScriptArgs: []string{"/foo/bar"}, + Interval: 10 * time.Second, } // Returns HTTP checks @@ -26,8 +26,8 @@ func TestAgentStructs_CheckTypes(t *testing.T) { // Returns Script checks svc.Checks = append(svc.Checks, &CheckType{ - Script: "/foo/bar", - Interval: 10 * time.Second, + ScriptArgs: []string{"/foo/bar"}, + Interval: 10 * time.Second, }) // Returns TTL checks diff --git a/api/agent.go b/api/agent.go index 772948ad1ee5..23690d48a4e2 100644 --- a/api/agent.go +++ b/api/agent.go @@ -86,7 +86,6 @@ type AgentServiceCheck struct { CheckID string `json:",omitempty"` Name string `json:",omitempty"` Args []string `json:"ScriptArgs,omitempty"` - Script string `json:",omitempty"` // Deprecated, use Args. DockerContainerID string `json:",omitempty"` Shell string `json:",omitempty"` // Only supported for Docker. Interval string `json:",omitempty"` diff --git a/api/agent_test.go b/api/agent_test.go index a05c4faf1ae7..b195fed29325 100644 --- a/api/agent_test.go +++ b/api/agent_test.go @@ -694,7 +694,7 @@ func TestAPI_AgentChecks_Docker(t *testing.T) { ServiceID: "redis", AgentServiceCheck: AgentServiceCheck{ DockerContainerID: "f972c95ebf0e", - Script: "/bin/true", + Args: []string{"/bin/true"}, Shell: "/bin/bash", Interval: "10s", }, diff --git a/website/source/docs/agent/checks.html.md b/website/source/docs/agent/checks.html.md index 42065e2799c5..a563de5778a5 100644 --- a/website/source/docs/agent/checks.html.md +++ b/website/source/docs/agent/checks.html.md @@ -247,11 +247,6 @@ In Consul 0.9.0 and later, the agent must be configured with [`enable_script_checks`](/docs/agent/options.html#_enable_script_checks) set to `true` in order to enable script checks. -Prior to Consul 1.0, checks used a single `script` field to define the command to run, and -would always run in a shell. In Consul 1.0, the `args` array was added so that checks can be -run without a shell. The `script` field is deprecated, and you should include the shell in -the `args` to run under a shell, eg. `"args": ["sh", "-c", "..."]`. - ## Initial Health Check Status By default, when checks are registered against a Consul agent, the state is set diff --git a/website/source/docs/agent/services.html.md b/website/source/docs/agent/services.html.md index 4cb6873a0952..bfac46d4d76f 100644 --- a/website/source/docs/agent/services.html.md +++ b/website/source/docs/agent/services.html.md @@ -32,7 +32,7 @@ A service definition is a script that looks like: "enable_tag_override": false, "checks": [ { - "script": "/usr/local/bin/check_redis.py", + "args": ["/usr/local/bin/check_redis.py"], "interval": "10s" } ] @@ -80,7 +80,7 @@ node has any failing system-level check, the DNS interface will omit that node from any service query. The check must be of the script, HTTP, TCP or TTL type. If it is a script type, -`script` and `interval` must be provided. If it is a HTTP type, `http` and +`args` and `interval` must be provided. If it is a HTTP type, `http` and `interval` must be provided. If it is a TCP type, `tcp` and `interval` must be provided. If it is a TTL type, then only `ttl` must be provided. The check name is automatically generated as `service:`. If there are multiple @@ -142,7 +142,7 @@ Multiple services definitions can be provided at once using the plural "port": 6000, "checks": [ { - "script": "/bin/check_redis -p 6000", + "args": ["/bin/check_redis", "-p", "6000"], "interval": "5s", "ttl": "20s" } @@ -159,7 +159,7 @@ Multiple services definitions can be provided at once using the plural "port": 7000, "checks": [ { - "script": "/bin/check_redis -p 7000", + "args": ["/bin/check_redis", "-p", "7000"], "interval": "30s", "ttl": "60s" }