Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-29496

Windows service: Add support of the Delayed Start option

      Currently the service starts in the "Automatic" mode, so there can be conflicts with other services like login service, shared directory mappers, etc. "Automatic (Delayed start)" could resolve this issue by allowing other services to start before Jenkins master/slave starts the initialization.

      The change requires https://github.com/kohsuke/winsw/releases/tag/winsw-1.17 at least (not merged into Jenkins core)

          [JENKINS-29496] Windows service: Add support of the Delayed Start option

          James Nord added a comment -

          The service should not use delayed start as this will slow down the startup of Jenkins.

          If anything the service dependencies should be set correctly - but how do you know that you need the "Workstation" service only if you are running on a shared home/workspace.
          Some installations may have disabled this for security.

          A delayed start by default (IIRC) will keep a salve offline for 2 minutes. AFAICT there is only a global setting for delayed start and changing this will affect services other than Jenkins.

          James Nord added a comment - The service should not use delayed start as this will slow down the startup of Jenkins. If anything the service dependencies should be set correctly - but how do you know that you need the "Workstation" service only if you are running on a shared home/workspace. Some installations may have disabled this for security. A delayed start by default (IIRC) will keep a salve offline for 2 minutes. AFAICT there is only a global setting for delayed start and changing this will affect services other than Jenkins.

          James Nord added a comment -

          this implies that we should not be using winsw to install itself, but Jenkins should install itself ant it needs to tweak the options depending on if the slave/master has been configured with any UNC paths - or that if you use UNC etc etc that you need to update the dependencies with

          sc config nameOfJenkinsService depend= nameOfServiceAYouDependOn/nameOfServiceAYouDependOn

          James Nord added a comment - this implies that we should not be using winsw to install itself, but Jenkins should install itself ant it needs to tweak the options depending on if the slave/master has been configured with any UNC paths - or that if you use UNC etc etc that you need to update the dependencies with sc config nameOfJenkinsService depend= nameOfServiceAYouDependOn/nameOfServiceAYouDependOn

          Oleg Nenashev added a comment -

          @James
          I agree that the delayed start may cause additional delays, but...

          • There is one well-known use-case with shared directories
          • Another known use case is a Windows event system, which starts as a service. If Jenkins starts before it, we may lose events in monitoring systems
          • There is a potential risk for user jobs, because currently Jenkins may start executing them on slave machines without fully initialized services => undefined behavior even for standard Windows CLI tools

          My opinion is that the "Delayed start" should be enabled by default. If a user knows what he is doing, he can switch the mode an set dependencies on other services. Would you agree with such approach?

          > A delayed start by default (IIRC) will keep a slave offline for 2 minutes. AFAICT there is only a global setting for delayed start and changing this will affect services other than Jenkins.

          No, Windows will start "delayed" services shortly after starting other ones with automatic start. AFAIK there's no hardcoded timeout.

          > this implies that we should not be using winsw to install itself

          Service startup mode can be passed via the configuration XML file, which is being used to instal the Jenkins service

          Oleg Nenashev added a comment - @James I agree that the delayed start may cause additional delays, but... There is one well-known use-case with shared directories Another known use case is a Windows event system, which starts as a service. If Jenkins starts before it, we may lose events in monitoring systems There is a potential risk for user jobs, because currently Jenkins may start executing them on slave machines without fully initialized services => undefined behavior even for standard Windows CLI tools My opinion is that the "Delayed start" should be enabled by default. If a user knows what he is doing, he can switch the mode an set dependencies on other services. Would you agree with such approach? > A delayed start by default (IIRC) will keep a slave offline for 2 minutes. AFAICT there is only a global setting for delayed start and changing this will affect services other than Jenkins. No, Windows will start "delayed" services shortly after starting other ones with automatic start. AFAIK there's no hardcoded timeout. > this implies that we should not be using winsw to install itself Service startup mode can be passed via the configuration XML file, which is being used to instal the Jenkins service

          James Nord added a comment -

          No, Windows will start "delayed" services shortly after starting other ones with automatic start. AFAIK there's no hardcoded timeout.

          Nope - there is a system wide setting (at least in some versions of Windows) and it defaults to 120 seconds.

          HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\AutoStartDelay

          • There is one well-known use-case with shared directories
          • Another known use case is a Windows event system, which starts as a service. If Jenkins starts before it, we may lose events in monitoring systems
          • There is a potential risk for user jobs, because currently Jenkins may start executing them on slave machines without fully initialized services => undefined behavior even for standard Windows CLI tools

          Which is why I said you need to install the service with dependencies set, not delayed start. If Jenkins needs service X to be alive it should have a dependency on it to ensure it is started after that service.
          The result is the service will still start after the services it needs are started, but it will not be artificially delayed but the AutoStartDelay.

          You need shared directories - add a service dependency on Workstation, you need the event system (you shouldn't), depend on EventLog, you need to make sure antivirus is running add a dependency on WinDefend etc etc...

          James Nord added a comment - No, Windows will start "delayed" services shortly after starting other ones with automatic start. AFAIK there's no hardcoded timeout. Nope - there is a system wide setting (at least in some versions of Windows) and it defaults to 120 seconds . HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\AutoStartDelay There is one well-known use-case with shared directories Another known use case is a Windows event system, which starts as a service. If Jenkins starts before it, we may lose events in monitoring systems There is a potential risk for user jobs, because currently Jenkins may start executing them on slave machines without fully initialized services => undefined behavior even for standard Windows CLI tools Which is why I said you need to install the service with dependencies set , not delayed start. If Jenkins needs service X to be alive it should have a dependency on it to ensure it is started after that service. The result is the service will still start after the services it needs are started, but it will not be artificially delayed but the AutoStartDelay. You need shared directories - add a service dependency on Workstation , you need the event system (you shouldn't), depend on EventLog , you need to make sure antivirus is running add a dependency on WinDefend etc etc...

          Oleg Nenashev added a comment -

          I still think that a default delayed start would be preferable for users, who would like to get a working infrastructure out-of-the-box. All service configuration steps may require much time from users, who have no appropriate qualification.

          My proposals:

          • Enable "Delayed start" by default
          • Add a Wiki page describing Windows service configuration for "Advanced" users

          Oleg Nenashev added a comment - I still think that a default delayed start would be preferable for users, who would like to get a working infrastructure out-of-the-box. All service configuration steps may require much time from users, who have no appropriate qualification. My proposals: Enable "Delayed start" by default Add a Wiki page describing Windows service configuration for "Advanced" users

          James Nord added a comment -

          Most people probably don't use UNC paths for storage[1] - and then you are impacting the majority of users with a slow startup to fix the minority of users.

          If you want to fix 80% of the minority without impacting the majority you could just depend on the "workstation" service.

          Anyone that wants anything more complex can suck it themselves.

          [1] based on nothing other than gut feeling and finger in the air - and that we still have huge amount of users that run builds on master!

          James Nord added a comment - Most people probably don't use UNC paths for storage [1] - and then you are impacting the majority of users with a slow startup to fix the minority of users. If you want to fix 80% of the minority without impacting the majority you could just depend on the "workstation" service. Anyone that wants anything more complex can suck it themselves. [1] based on nothing other than gut feeling and finger in the air - and that we still have huge amount of users that run builds on master!

          Oleg Nenashev added a comment -

          We agreed to move the discussion to Jenkins CI Dev list

          Oleg Nenashev added a comment - We agreed to move the discussion to Jenkins CI Dev list

          Oleg Nenashev added a comment - - edited

          teilo After some reconsideration I have decided not to enable it by default, but to provide a proper feature in WinSW: https://github.com/kohsuke/winsw/pull/205 . So anyone will be able to enable it if he wants.

          Would it work for you?

          Oleg Nenashev added a comment - - edited teilo After some reconsideration I have decided not to enable it by default, but to provide a proper feature in WinSW: https://github.com/kohsuke/winsw/pull/205 . So anyone will be able to enable it if he wants. Would it work for you?

          Oleg Nenashev added a comment -

          Closing as Resolved. The option is there since 2.60, but it is an opt-in behavior

          Oleg Nenashev added a comment - Closing as Resolved. The option is there since 2.60, but it is an opt-in behavior

            oleg_nenashev Oleg Nenashev
            oleg_nenashev Oleg Nenashev
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: