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

Setting 'service_name' fails to change the service name defined in providers/default.rb #17

Open
electric opened this issue Jul 16, 2018 · 1 comment

Comments

@electric
Copy link

When trying to use this cookbook and changing the node.default['mysqld']['service_name'] value, I get the following error

==> db: ================================================================================
==> db: Error executing action restart on resource 'service[mysql]'
==> db: ================================================================================
==> db:
==> db: Mixlib::ShellOut::ShellCommandFailed
==> db: ------------------------------------
==> db: Expected process to exit with [0], but received '5'
==> db: ---- Begin output of /bin/systemctl restart mysql ----
==> db: STDOUT:
==> db: STDERR: Failed to restart mysql.service: Unit not found.
==> db: ---- End output of /bin/systemctl restart mysql ----
==> db: Ran /bin/systemctl restart mysql returned 5
==> db:
==> db: Resource Declaration:
==> db: ---------------------
==> db: # In /tmp/vagrant-chef/824d535e25710db30ed17d906f18aa01/cookbooks/mysqld/providers/default.rb
==> db:
==> db: 48: service new_resource.service_name do
==> db: 49: # Use --wsrep-new-cluster if this is an initial galera startup
==> db: 50: if new_resource.galera_init
==> db: 51: start_command "service #{new_resource.service_name} start --wsrep-new-cluster --wsrep_cluster_address=gcomm://"
==> db: 52: end
==> db: 53:
==> db:
==> db: Compiled Resource:
==> db: ------------------
==> db: # Declared in /tmp/vagrant-chef/824d535e25710db30ed17d906f18aa01/cookbooks/mysqld/providers/default.rb:48:in `block in class_from_file'
==> db:
==> db: service("mysql") do
==> db: action [:enable, :start]
==> db: supports {:restart=>nil, :reload=>nil, :status=>nil}
==> db: retries 0
==> db: retry_delay 2
==> db: default_guard_interpreter :default
==> db: service_name "mysql"
==> db: pattern "mysql"
==> db: declared_type :service
==> db: cookbook_name :mysqld
==> db: not_if { #code block }
==> db: end

It looks as though the service name is still "mysql" instead of the value I pass through as node.default['mysqld']['service_name'] - in this instance, "mysqld"

@chr4
Copy link
Member

chr4 commented Jul 16, 2018

Thanks for the report!

I suppose you are using the default recipe?
I found overriding the attributes in Chef sometimes rather weird, can you try node.override instead of node.default? Does that make a difference?

I personally found it a good practise to always use wrapper cookbooks and then use the providers, like so:

mysqld 'default' do
  service_name 'mysqld'
end

It might be a good idea to change https://github.com/chr4-cookbooks/mysqld/blob/master/attributes/defaults.rb#L35 to select the default service name according to the used distribution/ version. Pull request welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants