Reputation: 1434
Here is the requirement : I am trying to install a windows service from a remote machine using chef. The script should validate whether that service is already installed or not. If installed then delete and reinstall it.Since i am new to chef am having a tough time finding a solution.
This is what i have tried:
execute 'Installing Service TestService' do
command "sc create \"TestService\" binPath= D:/Deploy/TestService.exe "
action :run
end
it installed the service but I am not able to implement the validation/check if it exists and reinstall. Even I don’t know whether the above script is a standard one. Can someone please help here. Also it'll be great if someone can suggest a beginner level chef tutorial for windows dotNet developer?
Upvotes: 2
Views: 1483
Reputation: 4185
Try removing the service if it already exists with a powershell_script
block and notifies the execute
block to install/reinstall the service. This way the installation will only fire after the service is removed.
powershell_script 'delete_if_exist' do
code <<-EOH
$Service = Get-WmiObject -Class Win32_Service -Filter "Name='TestService'"
if ($Service) {
$Service.Delete()
}
EOH
notifies :run, 'execute[Installing Service TestService]', :immediately
end
execute 'Installing Service TestService' do
command "sc create \"TestService\" binPath= D:/Deploy/TestService.exe "
action :nothing
end
Upvotes: 2