如何对Chef批处理资源的not_if和run_if进行评估?我想创建一个新的Windows服务,除非它已经存在
action :enable do
batch "install Windows service nexus3_nexus" do
code "c:/Nexus3/nexus-3.14.0-04/nexus.exe /install nexus3_nexus"
action :run
not_if "sc.exe query nexus3_nexus"
end
据我了解文档,如果“ sc.exe query nexus3_nexus”退出代码为<> 0-字符串作为shell命令执行,则应运行批处理命令。如果命令返回0,则应用防护。 但是,似乎该命令虽然返回0,但仍会应用该代码:
c:\Nexus3\nexus-3.14.0-04\bin>sc.exe query nexus3_ne
SERVICE_NAME: nexus3_nexus
TYPE : 110 WIN32_OWN_PROCESS
STATE : 4 RUNNING
(STOPPABLE, NOT_PAUS
WIN32_EXIT_CODE : 0 (0x0)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x0
c:\Nexus3\nexus-3.14.0-04\bin>echo %errorlevel%
0
在Chef-client-run的输出下方:
* batch[install Windows service nexus3_nexus] action run[2018-12-[12T11:16:30+01:00] INFO: Processing batch[install Windows service nexus3_nexus] action run (c:/chef/cache/cookbooks/my_nexus/resources/service_windows.rb line 11)
[2018-12-12T11:16:30+01:00] INFO: Processing batch[install Windows service nexus3_nexus] action run (c:/chef/cache/cookbooks/my_nexus/resources/service_windows.rb line 11)
[2018-12-12T11:16:30+01:00] INFO: Processing batch[Guard resource] action run (dynamically defined)
[2018-12-12T11:16:30+01:00] INFO: Processing batch[Guard resource] action run (dynamically defined)
================================================================================
Error executing action `run` on resource 'batch[install Windows service nexus3_nexus]'
================================================================================
Mixlib::ShellOut::ShellCommandFailed
------------------------------------
Expected process to exit with [0], but received '1'