On Fri, Oct 30, 2015 at 8:50 AM, Aaron <aaron.ma...@gmail.com> wrote:
> I have a question and hopefully someone can help me resolve it - > > In windows, I have custom services that I need to manage. I've been > running this code for a while, and it works well for several custom Windows > services, but the problem is I cannot run it on a bare server without > manual intervention (i.e. manually running the installer powershell script > to create the Service before puppet will complete successfully after > that). It will fail because the Detect does not see the service, so the > Uninstall cannot succeed. I am trying to figure out how to use an ELSE off > of the Detect Exec block, but am not sure how to make that work. And I am > unsure if there is anything clever I can do with the NOTIFY in the detect > block. > > Can anyone offer some assistance? > > FYI I do not have installers, I have the bare files that are moved into > place in the first File block, and then the Detect runs if any changes are > made to any files in the service. Hopefully that remains clear in my > attempt to make this generic. > > class FooService::install { > > if $::osfamily == 'windows' { > File { source_permissions => ignore } > } > > file { 'C:\\Services\\Win\\FooServiceConsumerSvc\\': > ensure => present, > source => 'puppet:///modules/FooService/FooService', > recurse => true, > purge => true, > force => true, > } > > exec { 'Detect FooService Service': > command => 'if ((Get-Service -name "FooService") -ne $null)', > You could add more to the command to run here. > provider => powershell, > subscribe => File['C:\\Services\\Win\\FooServiceConsumerSvc\\'], > refreshonly => true, > notify => Exec['Uninstall Old FooService Service'], > returns => 0, > } > > exec { 'Uninstall Old FooService Service': > command => > 'C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe /Logfile= > /InstallStateDir="C:\Services\Logs\Win" /uninstall > "C:\Services\Win\FooServiceConsumerSvc\FooService.exe"', > provider => powershell, > refreshonly => true, > notify => Exec['Install New FooService Service'], > } > > exec { 'Install New FooService Service': > command => > 'C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe > /username=AD\user /password=password /Logfile= > /InstallStateDir="C:\Services\Logs\Win" > "C:\Services\Win\FooServiceConsumerSvc\FooService.exe"', > provider => powershell, > refreshonly => true, > } > I would move this from a refresh only and introduce onlyif or unless where you check to see if the service is installed. And if it is not, then install it. For an example of unless see https://github.com/chocolatey/puppet-chocolatey/blob/3cce9e59d01f774ac48c40ec452b04eee9a81ebb/manifests/config.pp#L20-L25 > > } > > > -- > You received this message because you are subscribed to the Google Groups > "Puppet Users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to puppet-users+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/puppet-users/7aba5a95-c27b-4bf3-a568-9f5e785ab9ce%40googlegroups.com > <https://groups.google.com/d/msgid/puppet-users/7aba5a95-c27b-4bf3-a568-9f5e785ab9ce%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- Rob Reynolds Developer, Puppet Labs -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/CAMJiBK4WEry764QsNi63B5TZwZHQH4pLzOH0vhUHSZ3NpUkVrw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.