我有一个执行端点,它运行一个子进程,然后运行一个rancher-compose命令来在rancher上的主机中启动一些容器。当我从节点应用程序中点击此/execute
端点时,它可以正常工作并按预期启动容器。当通过/execute
命令从bash脚本命中cURL
端点时,它会失败,并在下面给出错误。我不明白为什么它会抛出一个错误,它只是在命令通过bash脚本运行时无法解组我的yaml
文件。这让我相信这不是我的yaml
文件的问题。下面我把错误和失败的命令以及我正在使用的cURL
命令。
我绝对迷失了,非常感谢任何帮助!
错误启动作业,无法运行容器部署的子进程。 >错误=错误:命令失败:/ rancher-tools / rancher-compose --project-name mic-iwbl3g97 --verbose --file docker-compose-job-submitter.yml up -d
作业部署输出:time =“2016-12-05T04:35:49Z”level = debug msg =“来自文件的环境上下文:map []”time =“2016-12-05T04:35:49Z”level = debug msg =“打开撰写文件:docker-compose-job-submitter.yml”time =“2016-12-05T04:35:49Z”level = debug msg =“寻找堆栈mic-iwbl3g97”time =“2016-12 -05T04:35:49Z“level = info msg =”创建堆栈mic-iwbl3g97“time =”2016-12-05T04:35:49Z“level = error msg =”无法解组:yaml:unmarshal errors:\ n line 15:无法解组!! str NaN进入int64 \ n第16行:无法解组!! str NaN进入int64 \ n命令:\ n-mic-iwbl3g97 \ n- NaN \ n- $ input_csv_file \ n- $ start_year \ n- $ end_year \ ncontainer-name:mic-iwbl3g97 \ ncpu_shares:25 \ nimage:$ repo_name:$ tag \ nlabels:\ n io.rancher.container.pull_image:always \ n io.rancher.container.start_once:true \ n io。 rancher.scheduler.affinity:host_label:MIC-Use = TPC_Modeling \ n io.rancher.sidekicks:locking,input,output,param,input-helper \ nmem_limit:NaN \ nmemswap_limit:NaN \ nnetwork_mode:none \ nvolumes_from:\ n-在put \ n- output \ n-param \ n- locking \ n“
curl -s -X POST -H "Content-Type: application/json" -d '{"S3_param_file":"$input_csv_file", "memory_constraint":"$memory_constraint", "time_constraint":"$time_constraint", "start_year":"$start_year", "end_year":"$end_year", "tag":"$tag", "repo":"$repo_name"}' http://my_ip_address:3000/execute
答案 0 :(得分:1)
变量不会在单引号中展开,请使用双引号展开:
curl -s -X POST \
-H "Content-Type: application/json" \
-d '{"S3_param_file":"'"$input_csv_file"'", "memory_constraint":"'"$memory_constraint"'", "time_constraint":"'"$time_constraint"'", "start_year":"'"$start_year"'", "end_year":"'"$end_year"'", "tag":"'"$tag"'", "repo":"'"$repo_name"'"}' \
http://my_ip_address:3000/execute
了解我如何在单引号和双引号之间切换:
'{"json_here": "'"$parameter_here"'"}'
sssssssssssssssssdddddddddddddddddssss
s
代表单引号,d
代表双引号。
如上所述,它很快变得一团糟,但是可以使用jq来创建JSON:
$ jq -n --arg a "a val" --arg b 'b val' '{$a, $b}'
{
"a": "a val",
"b": "b val"
}