Uploaded image for project: 'Puppet'
  1. Puppet
  2. PUP-9021

[Resource Type: service][Enhancement] Allow a Systemd service to be reload from a notify instead of restart

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Normal
    • Resolution: Duplicate
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Types and Providers
    • Labels:
      None
    • Environment:

      All OS using the provider systemd

    • 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]
      

        Attachments

          Issue Links

            Activity

              jsd-sla-details-panel

                People

                • Assignee:
                  Unassigned
                  Reporter:
                  vincentl Vincent Lours
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  2 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: