如何使用puppet安装/卸载Windows服务?

Ano*_*ous 2 windows-services puppet

我想在 Puppet 上安装/卸载 Windows 服务,但找不到执行此操作的内置函数。我想出了下面的脚本,它运行良好,但很丑陋。

exec{ "install_service" :
    command => "${Sys32}\\cmd.exe /c installutil -i /LogFile=\"${logFile}\" \"${sourcePath}\" | exit 0",
    path => $Framework4x64,
}
Run Code Online (Sandbox Code Playgroud)

有更好的方法吗?我尝试搜索插件,但尚未找到。

Ans*_*ers 5

我认为 Puppet 中没有内置任何东西。在 Windows 中“手动”创建服务的通用方法是使用该实用程序(请注意字符后面的sc.exe空格和字符前面的空格):=

exec { "install_service" :
    command => "${Sys32}\\sc.exe create MyService start= auto binPath= \"C:\\path\\to\\your.exe\"",
    path    => $Framework4x64,
    unless  => "${Sys32}\\sc.exe query MyService",
}
Run Code Online (Sandbox Code Playgroud)

或 PowerShell(最好使用PowerShell 提供程序):

exec { "install_service" :
    command  => "New-Service -Name MyService -StartupType Automatic -BinaryPathName \"C:\\path\\to\\your.exe\"",
    path     => $Framework4x64,
    provider => 'powershell',
    unless   => "Get-Service MyService; exit (1-[int]$?)",
}
Run Code Online (Sandbox Code Playgroud)