[PUP-9021] [Resource Type: service][Enhancement] Allow a Systemd service to be reload from a notify instead of restart Created: 2018/07/26  Updated: 2018/07/30  Resolved: 2018/07/30

Status: Closed
Project: Puppet
Component/s: Types and Providers
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Normal
Reporter: Vincent Lours Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

All OS using the provider systemd


Issue Links:
Duplicate
duplicates PUP-1054 Services should support 'reload' in a... Accepted
Relates
relates to PUP-3483 Systemd provider doesn't scan for cha... Closed
Template:
QA Risk Assessment: Needs Assessment

 Description   

Module Version: Resource Type: service
Puppet Version: Puppet Enterprise agent, all versions before 2018.1.2
OS Name/Version: Centos 7

Can you add an option to allow a Systemd service to be reloaded instead of restarted when Notify (refreshable).

Because some of the Systemd service have a reload option to avoid the service to be restarted, and only reload the config.
As example "httpd", that you want to keep alive instead of killing/starting all children process.

Desired Behavior:
Something like:

notify => Service[httpd = {:refresh_option => 'reload'}, service2, service3 = {:refresh_option => 'restart'} ] 

which can be checked in /opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/type/service.rb file
with something like (It's just an example as I'm not a Ruby expert and I was not able to follow the full workflow of the Resource Type Service):

      feature :refreshable, "The provider can restart the service.",
      :methods => :refreshable[:refresh_option] == 'reload' ? [:reload] : [:restart]

And match a new function in /opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/provider/service/systemd.rb

  def reloadcmd
    daemon_reload? #This line can be a new feature requested from PUP-3483
    [command(:systemctl), "reload", @resource[:name]]
  end
 
  def reload
    begin
      super
    rescue Puppet::Error => e
      raise Puppet::Error.new(prepare_error_message(@resource[:name], 'restart', e))
    end
  end

Actual Behavior:
notify => Service[httpd]
Which has only one action defined in the puppet agent code: /opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/type/service.rb

  Type.newtype(:service) do
    @doc = "Manage running services.  Service support unfortunately varies
      widely by platform --- some platforms have very little if any concept of a
      running service, and some have a very codified and powerful concept.
      Puppet's service support is usually capable of doing the right thing, but
      the more information you can provide, the better behaviour you will get.
 
      Puppet 2.7 and newer expect init scripts to have a working status command.
      If this isn't the case for any of your services' init scripts, you will
      need to set `hasstatus` to false and possibly specify a custom status
      command in the `status` attribute. As a last resort, Puppet will attempt to
      search the process table by calling whatever command is listed in the `ps`
      fact. The default search pattern is the name of the service, but you can
      specify it with the `pattern` attribute.
 
      **Refresh:** `service` resources can respond to refresh events (via
      `notify`, `subscribe`, or the `~>` arrow). If a `service` receives an
      event from another resource, Puppet will restart the service it manages.
      The actual command used to restart the service depends on the platform and
      can be configured:
 
      * If you set `hasrestart` to true, Puppet will use the init script's restart command.
      * You can provide an explicit command for restarting with the `restart` attribute.
      * If you do neither, the service's stop and start commands will be used."
 
    feature :refreshable, "The provider can restart the service.",
      :methods => [:restart]



 Comments   
Comment by Vincent Lours [ 2018/07/26 ]

The Issue PUP-3483 - "Systemd provider doesn't scan for changed units" was the initial reference for my Systemd enhancement.
I've submitted a updated code to fix the "deamon-reload" refresh on Systemd Servers.
Which make me thought about the missing reload from systemd services.

Comment by Eric Sorenson [ 2018/07/30 ]

Good idea. This is a duplicate of an old ticket, so I'll link this and close it as a duplicate so we can track your design suggestion. Check out PUP-1054 for the previous discussion on this enhancement request.

Comment by Eric Sorenson [ 2018/07/30 ]

Dup of PUP-1054

Generated at Tue Aug 11 00:49:29 PDT 2020 using Jira 8.5.2#805002-sha1:a66f9354b9e12ac788984e5d84669c903a370049.