Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

failed parsing command: only single commands supported on windows #1513

Closed
carldai0106 opened this issue Sep 7, 2021 · 6 comments
Closed
Labels

Comments

@carldai0106
Copy link

carldai0106 commented Sep 7, 2021

Please note that the Consul Template issue tracker is reserved
for bug reports and enhancements. For general usage questions,
please use the Consul Community Portal or the Consul mailing list:

https://discuss.hashicorp.com/c/consul
https://groups.google.com/forum/#!forum/consul-tool

Please try to simplify the issue as much as possible and include all the
details to replicate it. The shorter and simpler the bug is to reproduce the
quicker it can be addressed. Thanks.

Consul Template version

consul-template version is 0.27.0

Configuration

consul {
  address = "127.0.0.1:8500"
  
  retry {
    enabled  = true
    attempts = 12
    backoff  = "250ms"
  }
}

template {
  source      = "./template.tpl"
  destination = "../conf/loadbalance/upstreams.conf"
  perms       = 0600
  command     = "nginx -s reload"
}

Command

D:\dpa\nginx\consul-template>.\consul-template -config nginx.hcl -log-level=trace

Debug output

D:\dpa\nginx\consul-template>.\consul-template -config nginx.hcl -log-level=trace
2021-09-07T15:50:10.156+0800 [INFO] consul-template v0.27.0 (d4af0222)
2021-09-07T15:50:10.221+0800 [INFO] (runner) creating new runner (dry: false, once: false)
2021-09-07T15:50:10.222+0800 [DEBUG] (runner) final config: {"Consul":{"Address":"127.0.0.1:8500","Namespace":"","Auth":{"Enabled":false,"Username":"","Password":""},"Retry":{"Attempts":12,"Backoff":250000000,"MaxBackoff":60000000000,"Enabled":true},"SSL":{"CaCert":"","CaPath":"","Cert":"","Enabled":false,"Key":"","ServerName":"","Verify":true},"Token":"","Transport":{"DialKeepAlive":30000000000,"DialTimeout":30000000000,"DisableKeepAlives":false,"IdleConnTimeout":90000000000,"MaxIdleConns":100,"MaxIdleConnsPerHost":5,"TLSHandshakeTimeout":10000000000}},"Dedup":{"Enabled":false,"MaxStale":2000000000,"Prefix":"consul-template/dedup/","TTL":15000000000,"BlockQueryWaitTime":60000000000},"DefaultDelims":{"Left":null,"Right":null},"Exec":{"Command":"","Enabled":false,"Env":{"Denylist":[],"Custom":[],"Pristine":false,"Allowlist":[]},"KillSignal":2,"KillTimeout":30000000000,"ReloadSignal":null,"Splay":0,"Timeout":0},"KillSignal":2,"LogLevel":"trace","MaxStale":2000000000,"PidFile":"","ReloadSignal":1,"Syslog":{"Enabled":false,"Facility":"LOCAL0","Name":"consul-template"},"Templates":[{"Backup":false,"Command":"nginx -s reload","CommandTimeout":30000000000,"Contents":"","CreateDestDirs":true,"Destination":"../conf/loadbalance/upstreams.conf","ErrMissingKey":false,"Exec":{"Command":"nginx -s reload","Enabled":true,"Env":{"Denylist":[],"Custom":[],"Pristine":false,"Allowlist":[]},"KillSignal":2,"KillTimeout":30000000000,"ReloadSignal":null,"Splay":0,"Timeout":30000000000},"Perms":384,"Source":"./template.tpl","Wait":{"Enabled":false,"Min":0,"Max":0},"LeftDelim":"","RightDelim":"","FunctionDenylist":[],"SandboxPath":""}],"Vault":{"Address":"","Enabled":false,"Namespace":"","RenewToken":false,"Retry":{"Attempts":12,"Backoff":250000000,"MaxBackoff":60000000000,"Enabled":true},"SSL":{"CaCert":"","CaPath":"","Cert":"","Enabled":true,"Key":"","ServerName":"","Verify":true},"Transport":{"DialKeepAlive":30000000000,"DialTimeout":30000000000,"DisableKeepAlives":false,"IdleConnTimeout":90000000000,"MaxIdleConns":100,"MaxIdleConnsPerHost":5,"TLSHandshakeTimeout":10000000000},"UnwrapToken":false,"DefaultLeaseDuration":300000000000},"Wait":{"Enabled":false,"Min":0,"Max":0},"Once":false,"BlockQueryWaitTime":60000000000}
2021-09-07T15:50:10.223+0800 [INFO] (runner) creating watcher
2021-09-07T15:50:10.224+0800 [INFO] (runner) starting
2021-09-07T15:50:10.224+0800 [DEBUG] (runner) running initial templates
2021-09-07T15:50:10.224+0800 [DEBUG] (runner) initiating run
2021-09-07T15:50:10.224+0800 [DEBUG] (runner) checking template cc5ad5d7cd555774e20b76b96abda908
2021-09-07T15:50:10.224+0800 [DEBUG] (runner) missing data for 1 dependencies
2021-09-07T15:50:10.225+0800 [DEBUG] (runner) missing dependency: catalog.services
2021-09-07T15:50:10.225+0800 [DEBUG] (runner) add used dependency catalog.services to missing since isLeader but do not have a watcher
2021-09-07T15:50:10.225+0800 [DEBUG] (runner) was not watching 1 dependencies
2021-09-07T15:50:10.225+0800 [DEBUG] (watcher) adding catalog.services
2021-09-07T15:50:10.225+0800 [TRACE] (watcher) catalog.services starting
2021-09-07T15:50:10.225+0800 [DEBUG] (runner) diffing and updating dependencies
2021-09-07T15:50:10.225+0800 [DEBUG] (runner) watching 1 dependencies
2021-09-07T15:50:10.225+0800 [TRACE] (view) catalog.services starting fetch
2021-09-07T15:50:10.226+0800 [TRACE] catalog.services: GET /v1/catalog/services?stale=true&wait=1m0s
2021-09-07T15:50:10.230+0800 [TRACE] catalog.services: returned 2 results
2021-09-07T15:50:10.233+0800 [TRACE] (view) catalog.services marking successful data response
2021-09-07T15:50:10.233+0800 [TRACE] (view) catalog.services successful contact, resetting retries
2021-09-07T15:50:10.340+0800 [TRACE] (view) catalog.services received data
2021-09-07T15:50:10.342+0800 [TRACE] (view) catalog.services starting fetch
2021-09-07T15:50:10.342+0800 [DEBUG] (runner) receiving dependency catalog.services
2021-09-07T15:50:10.342+0800 [DEBUG] (runner) initiating run
2021-09-07T15:50:10.342+0800 [DEBUG] (runner) checking template cc5ad5d7cd555774e20b76b96abda908
2021-09-07T15:50:10.343+0800 [TRACE] catalog.services: GET /v1/catalog/services?index=1260&stale=true&wait=1m0s
2021-09-07T15:50:10.343+0800 [DEBUG] (runner) missing data for 1 dependencies
2021-09-07T15:50:10.344+0800 [DEBUG] (runner) missing dependency: health.service(APIDemo|passing)
2021-09-07T15:50:10.344+0800 [DEBUG] (runner) add used dependency health.service(APIDemo|passing) to missing since isLeader but do not have a watcher
2021-09-07T15:50:10.344+0800 [DEBUG] (runner) was not watching 1 dependencies
2021-09-07T15:50:10.344+0800 [DEBUG] (watcher) adding health.service(APIDemo|passing)
2021-09-07T15:50:10.344+0800 [TRACE] (watcher) health.service(APIDemo|passing) starting
2021-09-07T15:50:10.344+0800 [DEBUG] (runner) diffing and updating dependencies
2021-09-07T15:50:10.344+0800 [DEBUG] (runner) catalog.services is still needed
2021-09-07T15:50:10.344+0800 [DEBUG] (runner) watching 2 dependencies
2021-09-07T15:50:10.345+0800 [TRACE] (view) health.service(APIDemo|passing) starting fetch
2021-09-07T15:50:10.345+0800 [TRACE] health.service(APIDemo|passing): GET /v1/health/service/APIDemo?stale=true&wait=1m0s
2021-09-07T15:50:10.349+0800 [TRACE] health.service(APIDemo|passing): returned 2 results
2021-09-07T15:50:10.349+0800 [TRACE] health.service(APIDemo|passing): returned 2 results after filtering
2021-09-07T15:50:10.349+0800 [TRACE] (view) health.service(APIDemo|passing) marking successful data response
2021-09-07T15:50:10.349+0800 [TRACE] (view) health.service(APIDemo|passing) successful contact, resetting retries
2021-09-07T15:50:10.466+0800 [TRACE] (view) health.service(APIDemo|passing) received data
2021-09-07T15:50:10.467+0800 [TRACE] (view) health.service(APIDemo|passing) starting fetch
2021-09-07T15:50:10.469+0800 [TRACE] health.service(APIDemo|passing): GET /v1/health/service/APIDemo?index=1261&stale=true&wait=1m0s
2021-09-07T15:50:10.469+0800 [DEBUG] (runner) receiving dependency health.service(APIDemo|passing)
2021-09-07T15:50:10.469+0800 [DEBUG] (runner) initiating run
2021-09-07T15:50:10.469+0800 [DEBUG] (runner) checking template cc5ad5d7cd555774e20b76b96abda908
2021-09-07T15:50:10.470+0800 [DEBUG] (runner) rendering "./template.tpl" => "../conf/loadbalance/upstreams.conf"
2021-09-07T15:50:10.470+0800 [DEBUG] (runner) diffing and updating dependencies
2021-09-07T15:50:10.470+0800 [DEBUG] (runner) catalog.services is still needed
2021-09-07T15:50:10.470+0800 [DEBUG] (runner) health.service(APIDemo|passing) is still needed
2021-09-07T15:50:10.470+0800 [DEBUG] (runner) watching 2 dependencies
2021-09-07T15:50:10.470+0800 [DEBUG] (runner) all templates rendered
2021-09-07T15:50:20.139+0800 [TRACE] catalog.services: returned 2 results
2021-09-07T15:50:20.139+0800 [TRACE] (view) catalog.services marking successful data response
2021-09-07T15:50:20.141+0800 [TRACE] (view) catalog.services no new data (contents were the same)
2021-09-07T15:50:20.141+0800 [TRACE] catalog.services: GET /v1/catalog/services?index=1292&stale=true&wait=1m0s
2021-09-07T15:50:20.141+0800 [TRACE] (view) catalog.services successful contact, resetting retries
2021-09-07T15:50:20.141+0800 [TRACE] health.service(APIDemo|passing): returned 1 results
2021-09-07T15:50:20.142+0800 [TRACE] health.service(APIDemo|passing): returned 1 results after filtering
2021-09-07T15:50:20.142+0800 [TRACE] (view) health.service(APIDemo|passing) marking successful data response
2021-09-07T15:50:20.142+0800 [TRACE] (view) health.service(APIDemo|passing) successful contact, resetting retries
2021-09-07T15:50:20.142+0800 [TRACE] (view) health.service(APIDemo|passing) received data
2021-09-07T15:50:20.142+0800 [TRACE] (view) health.service(APIDemo|passing) starting fetch
2021-09-07T15:50:20.142+0800 [TRACE] health.service(APIDemo|passing): GET /v1/health/service/APIDemo?index=1292&stale=true&wait=1m0s
2021-09-07T15:50:20.143+0800 [DEBUG] (runner) receiving dependency health.service(APIDemo|passing)
2021-09-07T15:50:20.143+0800 [DEBUG] (runner) initiating run
2021-09-07T15:50:20.143+0800 [DEBUG] (runner) checking template cc5ad5d7cd555774e20b76b96abda908
2021-09-07T15:50:20.143+0800 [DEBUG] (runner) rendering "./template.tpl" => "../conf/loadbalance/upstreams.conf"
2021-09-07T15:50:20.175+0800 [INFO] (runner) rendered "./template.tpl" => "../conf/loadbalance/upstreams.conf"
2021-09-07T15:50:20.175+0800 [DEBUG] (runner) appending command "nginx -s reload" from "./template.tpl" => "../conf/loadbalance/upstreams.conf"
2021-09-07T15:50:20.175+0800 [DEBUG] (runner) diffing and updating dependencies
2021-09-07T15:50:20.175+0800 [DEBUG] (runner) catalog.services is still needed
2021-09-07T15:50:20.175+0800 [DEBUG] (runner) health.service(APIDemo|passing) is still needed
2021-09-07T15:50:20.175+0800 [INFO] (runner) executing command "nginx -s reload" from "./template.tpl" => "../conf/loadbalance/upstreams.conf"
2021-09-07T15:50:20.176+0800 [ERR] (cli) 1 error occurred:
        * failed to execute command "nginx -s reload" from "./template.tpl" => "../conf/loadbalance/upstreams.conf": failed parsing command: only single commands supported on windows

Actual behavior

I am running consul-template to windows 10 using powershell.
When a service was off-line. then upstreams.conf will update and the same time to reload nginx config file.
but it can not run nginx -s reload on windows system.

@eikenb
Copy link
Contributor

eikenb commented Sep 7, 2021

Hey @carldai0106, thanks for taking the time to file an issue.

In 0.27.0 we stopped using a shell parsing library that was the constant source of bugs. Unfortunately to eliminate it we had to change some behaviors, primarily the parsing of the command to run.

To handle shell parsing on *nix systems we run the command using a shell directly (sh -c ...). On windows (and *nix systems without a system shell) we have no option but to not parse the command. So starting in 0.27.0 a single command (ie. no spaces to parse) is required unless you are running CT on *nix with a system shell.

TLDR; to get your command working put it in a windows batch file or PowerShell script and run that.

Alternatively if you happen to know of a Windows equivalent of a *nix shell (sh -c ...) call we could look into adding support for it.

@eikenb eikenb added the question label Sep 7, 2021
@eikenb
Copy link
Contributor

eikenb commented Nov 1, 2021

I've added supporting a command list feature to the roadmap for v0.28.0. That will allow you to explicitly support any command needed by providing a pre-parsed command list to the system call. This should address any issues remaining issues with command calls on any platform.

@rba1-source
Copy link

Can you please elaborate on this for Windows? You suggested to run a Powershell script but if you're passing the value of the "command" key just to a shell, for example:
command = "C:\Temp\myscript.ps1"

then that won't execute the Powershell script. Thanks.

@eikenb
Copy link
Contributor

eikenb commented Dec 2, 2021

Hey @rba1-source, thanks for the question.

Do you mean you have to pass a command parameter when calling a powershell script? That it is not possible to create a script that is directly executable? I was under the impression that was possible.

If that is not possible maybe the old .bat file type script would work?

If that isn't... the next best thing I can offer is to say that for 0.28.0 I'll be adding support for command-lists which will allow you to provide a command with arguments in a pre-parsed form. I'm starting work on the remaining open tickets pretty much today and will be releasing it once those are complete.

Thanks.

@rba1-source
Copy link

I got this working quite clumsily by creating a .bat file that has my 1 line of:
powershell C:\Temp\myscript.ps1 -argumentlist <my-args>

This works because the "command" has no spaces in, since you can call a .bat file from cmd directly by using the filename.

@eikenb
Copy link
Contributor

eikenb commented Dec 7, 2021

Glad you got it working! For updates on the command list handling mentioned above, see ticket #1518.

@eikenb eikenb closed this as completed Dec 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants