sous-chefs / jenkins

Development repository for the jenkins cookbook
https://supermarket.chef.io/cookbooks/jenkins
Apache License 2.0
424 stars 636 forks source link

Service does not reinstall cleanly on Windows 7 #542

Open philipdouglas opened 7 years ago

philipdouglas commented 7 years ago

Cookbook version

4.1.2

Chef-client version

12.9.41

Platform Details

Windows 7 I have been unable to reproduce it on Windows Server 2012 R2 or Windows 10

Scenario:

The service config xml file is updated and the service is automatically uninstalled and recreated with the new settings.

Steps to Reproduce:

Expected Result:

The client should spot the config file has changed, correct it and then reinstall the service to pick up any new settings.

Actual Result:

Chef spots the change and updates the file. This triggers the reinstall, which appears to stop and uninstall the service, but then fails to install it because it already exists. By the time the run ends, the service is gone.

I was able to fix the problem by replacing jenkins-slave.exe stop with net stop jenkins-slave in the batch resource.

The console output:

================================================================================
    Error executing action `create` on resource 'jenkins_windows_slave[NODE]'
    ================================================================================

    Mixlib::ShellOut::ShellCommandFailed
    ------------------------------------
    batch[install-jenkins-slave] (dynamically defined) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected proc
ess to exit with [0], but received '-1'
    ---- Begin output of "C:\Windows\system32\cmd.exe" /c "C:/Users/username/AppData/Local/Temp/4/chef-script20161129-60
988-1up67c1.bat" ----
    STDOUT: C:\j>IF "jenkins-slave" == "jenkins-slave" (
    jenkins-slave.exe stop
     jenkins-slave.exe uninstall
    )

    C:\j>jenkins-slave.exe install
    Service with id 'jenkins-slave' already exists
    To install the service, delete the existing one or change service Id in the configuration file
    STDERR: System.Exception: Installation failure: Service with id 'jenkins-slave' already exists
       at winsw.WrapperService.Run(String[] _args, ServiceDescriptor descriptor)
       at winsw.WrapperService.Main(String[] args)
    ---- End output of "C:\Windows\system32\cmd.exe" /c "C:/Users/username/AppData/Local/Temp/4/chef-script20161129-6098
8-1up67c1.bat" ----
    Ran "C:\Windows\system32\cmd.exe" /c "C:/Users/username/AppData/Local/Temp/4/chef-script20161129-60988-1up67c1.bat"
returned -1

    Cookbook Trace:
    ---------------
    c:/chef/cache/cookbooks/jenkins/libraries/slave_windows.rb:88:in `action_create'
    c:/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/runner.rb:78:in `run_action'
    c:/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/runner.rb:106:in `block (2 levels)
in converge'
    c:/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/runner.rb:106:in `each'
    c:/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/runner.rb:106:in `block in converge
'
    c:/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/runner.rb:105:in `converge'
lovasekhar-virtusa commented 6 years ago

we are facing similar issue when installing two different jenkins with different service names. we modified jenikins.xml withe new service name but still showing Service with id 'jenkins-slave' already exists To install the service, delete the existing one or change service Id in the configuration file STDERR: System.Exception: Installation failure: Service with id 'jenkins-slave' already exists at winsw.WrapperService.Run(String[] _args, ServiceDescriptor descriptor) at winsw.WrapperService.Main(String[] args)