Jira (PUP-6382) Add "Automatic (delayed start)" as option for Service Resource on Windows

13 views
Skip to first unread message

Nathanael Cole (JIRA)

unread,
Jun 2, 2016, 3:44:03 PM6/2/16
to puppe...@googlegroups.com
Nathanael Cole created an issue
 
Puppet / New Feature PUP-6382
Add "Automatic (delayed start)" as option for Service Resource on Windows
Issue Type: New Feature New Feature
Assignee: Unassigned
Components: Windows
Created: 2016/06/02 12:43 PM
Priority: Normal Normal
Reporter: Nathanael Cole

The service resource does not currently support an option to set a Windows service to the "Automatic (delayed start)" status. Please add this support.

Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v6.4.13#64028-sha1:b7939e9)
Atlassian logo

Rob Reynolds (JIRA)

unread,
Jun 2, 2016, 3:52:03 PM6/2/16
to puppe...@googlegroups.com
Rob Reynolds updated an issue
Change By: Rob Reynolds
CS Priority: Needs Priority
Labels: service windows
Sprint: Windows Triage
Scrum Team: Windows
Component/s: Types and Providers

Nathanael Cole (JIRA)

unread,
Jun 2, 2016, 4:00:02 PM6/2/16
to puppe...@googlegroups.com

Craig Gomes (JIRA)

unread,
Jul 11, 2016, 5:01:05 PM7/11/16
to puppe...@googlegroups.com

Moses Mendoza (JIRA)

unread,
Sep 22, 2016, 5:14:04 PM9/22/16
to puppe...@googlegroups.com
Moses Mendoza updated an issue
Change By: Moses Mendoza
Labels: manage- service  service  windows
This message was sent by Atlassian JIRA (v6.4.14#64029-sha1:ae256fe)
Atlassian logo

Moses Mendoza (JIRA)

unread,
Sep 22, 2016, 5:14:12 PM9/22/16
to puppe...@googlegroups.com

Ethan Brown (JIRA)

unread,
May 16, 2017, 7:17:04 PM5/16/17
to puppe...@googlegroups.com
Ethan Brown updated an issue
Change By: Ethan Brown
Labels: manage-service service  triaged  windows

Branan Riley (JIRA)

unread,
May 10, 2018, 9:18:03 PM5/10/18
to puppe...@googlegroups.com
Branan Riley updated an issue
Change By: Branan Riley
Labels: manage- service service triaged type_and_provider windows
This message was sent by Atlassian JIRA (v7.7.1#77002-sha1:e75ca93)
Atlassian logo

Ryan Anderson (JIRA)

unread,
Apr 4, 2019, 6:14:04 PM4/4/19
to puppe...@googlegroups.com
Ryan Anderson commented on New Feature PUP-6382
 
Re: Add "Automatic (delayed start)" as option for Service Resource on Windows

Our organization is very interested in having the ability to set this startup state on Windows services. It was submitted some time ago, might some development resources be given to this?

Thomas Kishel (JIRA)

unread,
Jul 24, 2019, 12:00:04 PM7/24/19
to puppe...@googlegroups.com
Thomas Kishel commented on New Feature PUP-6382

We could implement this with something like ...

 

lib/puppet/type/service.rb

 newproperty(:enable, :required_features => :enableable) do
  ...
 newvalue(:delayed, :event => :service_delayed_start) do
   provider.delayed_start
 end

lib/puppet/provider/service/windows.rb

  def delayed_start
    enable
    Puppet::Util::Windows::Service.set_startup_mode_delayed( @resource[:name] )
  rescue => detail
    raise Puppet::Error.new(_("Cannot enable %{resource_name} for delayed start, error was: %{detail}") % { resource_name: @resource[:name], detail: detail }, detail )
  end

lib/puppet/util/windows/service.rb

    # Delay the startup of a windows service
    #
    # @param [string] service_name the name of the service to modify
    def set_startup_mode_delayed(service_name)
      `REG ADD HKLM\SYSTEM\ControlSet\Services\#{service_name} /t REG_DWORD /f /v DelayedAutostart /d 1`
      if $? != 0
        raise Puppet::Util::Windows::Error.new(_("Failed to fetch services"))
      end
    end
    module_function :set_startup_mode_delayed

Since we use already ChangeServiceConfig, the REG ADD in the above should be replaced with a call to ChangeServiceConfig2 as per:

https://docs.microsoft.com/en-us/windows/win32/services/automatically-starting-services
https://docs.microsoft.com/en-us/windows/win32/api/winsvc/ns-winsvc-_service_delayed_auto_start_info
https://docs.microsoft.com/en-us/windows/win32/api/winsvc/nf-winsvc-changeserviceconfig2a

Thomas Kishel (JIRA)

unread,
Aug 6, 2019, 3:22:04 PM8/6/19
to puppe...@googlegroups.com
Thomas Kishel commented on New Feature PUP-6382

Maybe ...

    # Service config codes
    # https://docs.microsoft.com/en-us/windows/win32/api/winsvc/nf-winsvc-changeserviceconfig2w
    SERVICE_CONFIG_DESCRIPTION              = 0x00000001
    SERVICE_CONFIG_FAILURE_ACTIONS          = 0x00000002
    SERVICE_CONFIG_DELAYED_AUTO_START       = 0x00000003
    SERVICE_CONFIG_FAILURE_ACTIONS_FLAG     = 0x00000004
    SERVICE_CONFIG_SERVICE_SID_INFO         = 0x00000005
    SERVICE_CONFIG_REQUIRED_PRIVILEGES_INFO = 0x00000006
    SERVICE_CONFIG_PRESHUTDOWN_INFO         = 0x00000007
    SERVICE_CONFIG_TRIGGER_INFO             = 0x00000008
    SERVICE_CONFIG_PREFERRED_NODE           = 0x00000009
    SERVICE_CONFIG_LAUNCH_PROTECTED         = 0x00000012
 
    SERVICE_CONFIG_CHANGES = {
      SERVICE_CONFIG_DELAYED_AUTO_START => :SERVICE_CONFIG_DELAYED_AUTO_START
    }
 
    class SERVICE_DELAYED_AUTO_START < FFI::Struct
      layout(
        :fDelayedAutostart, :win32_bool
      )
    end
 
    def set_startup_mode_delayed(service_name)
      change_code = SERVICE_CONFIG_CHANGES.key('SERVICE_CONFIG_DELAYED_AUTO_START')
      change_ptr = FFI::Pointer.new(SERVICE_DELAYED_AUTO_START, SERVICE_DELAYED_AUTO_START.size)
      open_service(service_name, SC_MANAGER_CONNECT, SERVICE_CHANGE_CONFIG) do |service|
        success = ChangeServiceConfig2W (
          service,
          change_code, # dwInfoLevel
          change_ptr   # lpInfo
        )
        if success == FFI::WIN32_FALSE
          raise Puppet::Util::Windows::Error.new(_("Failed to update service delayed_auto_start configuration"))
        end
      end
    end
    module_function :set_startup_mode_delayed

Chris Webster (JIRA)

unread,
Aug 13, 2019, 1:17:04 PM8/13/19
to puppe...@googlegroups.com

Chris Webster (JIRA)

unread,
Aug 13, 2019, 1:20:05 PM8/13/19
to puppe...@googlegroups.com
Chris Webster commented on New Feature PUP-6382
 
Re: Add "Automatic (delayed start)" as option for Service Resource on Windows
  • Going to be refracting tested code to be implemented correctly. 
  • Going to be working with Tom when he is back from PTO to implement testing of new code. 

Dirk Heinrichs (JIRA)

unread,
Sep 5, 2019, 7:33:03 AM9/5/19
to puppe...@googlegroups.com

Will it be available in P6 only or also backported to P5?

 

Mihai Buzgau (JIRA)

unread,
Sep 18, 2019, 10:00:07 AM9/18/19
to puppe...@googlegroups.com

Mihai Buzgau (JIRA)

unread,
Sep 18, 2019, 10:00:08 AM9/18/19
to puppe...@googlegroups.com

Mihai Buzgau (JIRA)

unread,
Sep 18, 2019, 10:00:08 AM9/18/19
to puppe...@googlegroups.com

Mihai Buzgau (JIRA)

unread,
Sep 23, 2019, 7:48:05 AM9/23/19
to puppe...@googlegroups.com

Mihai Buzgau (JIRA)

unread,
Sep 23, 2019, 12:19:04 PM9/23/19
to puppe...@googlegroups.com
Mihai Buzgau commented on New Feature PUP-6382
 
Re: Add "Automatic (delayed start)" as option for Service Resource on Windows

Dirk Heinrichs it will be available on all the agent streams starting with P5

Dirk Heinrichs (JIRA)

unread,
Sep 24, 2019, 1:37:03 AM9/24/19
to puppe...@googlegroups.com

Gabriel Nagy (JIRA)

unread,
Sep 27, 2019, 5:40:03 AM9/27/19
to puppe...@googlegroups.com
Gabriel Nagy updated an issue
 
Change By: Gabriel Nagy
Release Notes Summary: Puppet is now able to manage the "delayed" service start property of Windows services. This can be accessed by setting the "enable" parameter of a service to "delayed".
Release Notes: New Feature

Josh Cooper (JIRA)

unread,
Oct 4, 2019, 7:01:04 PM10/4/19
to puppe...@googlegroups.com
Josh Cooper updated an issue
Change By: Josh Cooper
Fix Version/s: PUP 6.y
Fix Version/s: PUP 6.10.1
Fix Version/s: PUP 6.4.4

Jean Bond (JIRA)

unread,
Oct 9, 2019, 7:37:05 PM10/9/19
to puppe...@googlegroups.com
Jean Bond updated an issue
Change By: Jean Bond
Labels: resolved-issue-added service type_and_provider windows

Dirk Heinrichs (Jira)

unread,
Mar 9, 2020, 10:06:02 AM3/9/20
to puppe...@googlegroups.com
 
Re: Add "Automatic (delayed start)" as option for Service Resource on Windows

BTW: It's not yet documented. Does this count as "Resolved", then?

This message was sent by Atlassian Jira (v8.5.2#805002-sha1:a66f935)
Atlassian logo

Chris Payne (Jira)

unread,
May 9, 2023, 2:38:03 PM5/9/23
to puppe...@googlegroups.com
Chris Payne commented on New Feature PUP-6382

This doesn't seem to work properly. I have enable => delayed and I see this running puppet agent -t:

 

Notice: /Stage[main]/Profile::Myservice/Service[svc test]/enable: enable changed 'true' to 'delayed' (corrective) 

But the actual service goes to "Automatic," not "Automatic (Delayed)." 

The registry key that should be modified is Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\svc test\DelayedAutostart

But puppet doesn't seem to do anything here. 

 

This message was sent by Atlassian Jira (v8.20.11#820011-sha1:0629dd8)
Atlassian logo

Chris Payne (Jira)

unread,
May 10, 2023, 9:10:03 AM5/10/23
to puppe...@googlegroups.com
Chris Payne commented on New Feature PUP-6382

Addendum to my last comment. I could not get puppet to change this status properly at all, whether by using something like this:

service { "${serviceName}":
  enable        => delayed, 

or by using a "require" parameter that executed powershell to manually change the start type. It seems that the service resource ALWAYS resets "delayed" to equal "automatic" no matter what - just being very stubborn I guess. 

However, I was able to get this to work by using an exec statement AFTER the service resource, like so:

$serviceEnableStatus = "delayed-auto"
 
exec { "change_${serviceName}_starttype":
  command     => "sc.exe config '${serviceName}' start= '${serviceEnableStatus}'",
  provider    => powershell,
}
 
service { "${serviceName}":
  ...
  before        => Exec["change_${serviceName}_starttype"],
}

In case this helps anyone. 

Reply all
Reply to author
Forward
0 new messages