Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

service resource restart not working as described in documentation #8250

Open
kmf opened this Issue Feb 23, 2019 · 2 comments

Comments

Projects
None yet
2 participants
@kmf
Copy link

kmf commented Feb 23, 2019

Description

I've read in the docs that if I specify a service with no property for restarting it will try and stop and start the service.

This is the expected behavior, according to the docs and it's not working.

Chef Version

Chef 14.10.9

Platform Version

RHEL 6.10

Replication Case

If I create a file restart a service, if I don't nothing happens

    file '/etc/datadog-agent/conf.d/someservice.d/conf.yaml' do
        content "something"
        owner 'dd-agent'
        group 'dd-agent'
        mode '0644'
        action :create
        notifies :restart, 'service[datadog-agent]'
    end

    service 'datadog-agent' do
      supports :status => true,:stop => true, :start => true
      start_command     "/usr/bin/datadog-agent run"
      status_command    "/usr/bin/datadog-agent status"
      stop_command      "/usr/bin/datadog-agent stop"
      action :nothing
    end

I'm calling a custom service that out of the box does not support a service resource, according to the docs https://docs.chef.io/resource_service.html#properties

For :restart, the init script or other service provider can use a restart command; if :restart is not specified, the chef-client attempts to stop and then start a service.

Client Output

* service[datadog-agent] action restart
    * service[datadog-agent]: No custom command for restart specified and unable to locate the init.d script!
    ================================================================================
    Error executing action `restart` on resource 'service[datadog-agent]'
    ================================================================================

    Chef::Exceptions::Service
    -------------------------
    service[datadog-agent]: No custom command for restart specified and unable to locate the init.d script!

    Resource Declaration:
    ---------------------
    # In /var/chef/cache/cookbooks/something/recipes/some_recipe.rb

    147:     service 'datadog-agent' do
    148:       supports :status => true,:stop => true, :start => true
    149:       start_command     "/usr/bin/datadog-agent run"
    150:       status_command    "/usr/bin/datadog-agent status"
    151:       stop_command      "/usr/bin/datadog-agent stop"
    152:       action :nothing
    153:     end
    154: end

    Compiled Resource:
    ------------------
    # Declared in /var/chef/cache/cookbooks/obsidian/recipes/datadog_zimbra.rb:147:in `from_file'

    service("datadog-agent") do
      action [:nothing]
      default_guard_interpreter :default
      service_name "datadog-agent"
      enabled nil
      running nil
      masked nil
      pattern "datadog-agent"
      start_command "/usr/bin/datadog-agent run"
      stop_command "/usr/bin/datadog-agent stop"
      status_command "/usr/bin/datadog-agent status"
      declared_type :service
      cookbook_name "obsidian"
      recipe_name "datadog_zimbra"
      supports {:status=>true, :stop=>true, :start=>true}
    end

    System Info:
    ------------
    chef_version=14.10.9
    platform=centos
    platform_version=6.10
    ruby=ruby 2.5.3p105 (2018-10-18 revision 65156) [x86_64-linux]
    program_name=/usr/bin/chef-client
    executable=/opt/chef/bin/chef-client

Stacktrace

Generated at 2019-02-23 09:35:51 +0200
Chef::Exceptions::Service: service[datadog-agent] (obsidian::datadog_zimbra line 147) had an error: Chef::Exceptions::Service: service[datadog-agent]: No custom command for restart specified and unable to locate the init.d script!
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.10.9/lib/chef/mixin/why_run.rb:238:in `run'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.10.9/lib/chef/mixin/why_run.rb:316:in `block in run'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.10.9/lib/chef/mixin/why_run.rb:315:in `each'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.10.9/lib/chef/mixin/why_run.rb:315:in `run'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.10.9/lib/chef/provider.rb:192:in `process_resource_requirements'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.10.9/lib/chef/provider.rb:170:in `run_action'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.10.9/lib/chef/resource.rb:578:in `run_action'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.10.9/lib/chef/runner.rb:70:in `run_action'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.10.9/lib/chef/runner.rb:128:in `run_delayed_notification'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.10.9/lib/chef/runner.rb:116:in `block in run_delayed_notifications'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.10.9/lib/chef/runner.rb:115:in `each'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.10.9/lib/chef/runner.rb:115:in `run_delayed_notifications'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.10.9/lib/chef/runner.rb:105:in `converge'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.10.9/lib/chef/client.rb:720:in `block in converge'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.10.9/lib/chef/client.rb:715:in `catch'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.10.9/lib/chef/client.rb:715:in `converge'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.10.9/lib/chef/client.rb:754:in `converge_and_save'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.10.9/lib/chef/client.rb:286:in `run'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.10.9/lib/chef/application.rb:303:in `run_with_graceful_exit_option'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.10.9/lib/chef/application.rb:279:in `block in run_chef_client'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.10.9/lib/chef/local_mode.rb:44:in `with_server_connectivity'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.10.9/lib/chef/application.rb:261:in `run_chef_client'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.10.9/lib/chef/application/client.rb:444:in `run_application'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.10.9/lib/chef/application.rb:66:in `run'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.10.9/bin/chef-client:25:in `<top (required)>'
/usr/bin/chef-client:74:in `load'
/usr/bin/chef-client:74:in `<main>'

>>>> Caused by Chef::Exceptions::Service: service[datadog-agent]: No custom command for restart specified and unable to locate the init.d script!
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.10.9/lib/chef/mixin/why_run.rb:238:in `run'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.10.9/lib/chef/mixin/why_run.rb:316:in `block in run'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.10.9/lib/chef/mixin/why_run.rb:315:in `each'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.10.9/lib/chef/mixin/why_run.rb:315:in `run'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.10.9/lib/chef/provider.rb:192:in `process_resource_requirements'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.10.9/lib/chef/provider.rb:170:in `run_action'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.10.9/lib/chef/resource.rb:578:in `run_action'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.10.9/lib/chef/runner.rb:70:in `run_action'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.10.9/lib/chef/runner.rb:128:in `run_delayed_notification'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.10.9/lib/chef/runner.rb:116:in `block in run_delayed_notifications'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.10.9/lib/chef/runner.rb:115:in `each'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.10.9/lib/chef/runner.rb:115:in `run_delayed_notifications'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.10.9/lib/chef/runner.rb:105:in `converge'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.10.9/lib/chef/client.rb:720:in `block in converge'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.10.9/lib/chef/client.rb:715:in `catch'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.10.9/lib/chef/client.rb:715:in `converge'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.10.9/lib/chef/client.rb:754:in `converge_and_save'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.10.9/lib/chef/client.rb:286:in `run'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.10.9/lib/chef/application.rb:303:in `run_with_graceful_exit_option'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.10.9/lib/chef/application.rb:279:in `block in run_chef_client'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.10.9/lib/chef/local_mode.rb:44:in `with_server_connectivity'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.10.9/lib/chef/application.rb:261:in `run_chef_client'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.10.9/lib/chef/application/client.rb:444:in `run_application'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.10.9/lib/chef/application.rb:66:in `run'
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.10.9/bin/chef-client:25:in `<top (required)>'
/usr/bin/chef-client:74:in `load'
/usr/bin/chef-client:74:in `<main>'
@lamont-granquist

This comment has been minimized.

Copy link
Contributor

lamont-granquist commented Feb 25, 2019

You are getting a Chef::Resource::Service::Redhat object as your provider. You probably want to use provider Chef::Resource::Service::Simple to bypass all of that. There's probably a doc bug in there to fix, but I wouldn't even know how to write up the inheritance hierarchy here into something which a normal person would be able to consume.

@kmf

This comment has been minimized.

Copy link
Author

kmf commented Feb 25, 2019

thanks?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.