json consul watch handler 的配置

json configuration of consul watch handler

我想 运行 一个 sudo 模式的脚本作为我的 consul watch 处理程序,我可以 运行 使用命令

consul watch -type key -key mykey sudo -u myaccount /scripts/myscript.sh

但我不知道如何在json配置中定义它,我在下面试过但它不起作用

{
  "watches":[{
    "type":"key",
    "key":"mykey",
    "handler_type":"script",
    "args":["sh","-c","sudo","-u","myaccount","/scripts/myscript.sh"]
  }]
}

我正在使用 consul 1.5.2,这是错误:

[ERR] agent: Failed to run watch handler '[sh -c sudo -u myaccount /scripts/myscript.sh]': exit status 1

谁能告诉我我的 json 配置有什么问题?

我移动了sh -c

我可以使用它:

"watches":[{
  "type":"key",
  "key":"mykey",
  "handler_type":"script",
  "args":["/bin/sudo","-u","consul","/bin/sh","-c","/home/testscript.sh"]
}]

-c 要求脚本可执行。您还需要正确的 sudo 权限。当脚本可执行时,您甚至可以完全删除 sh -c