chr4-cookbooks / mysqld

chef cookbook for installing and configuring mysql, only changing explicitly given options from the systems defaults
4 stars 11 forks source link

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

Open electric opened 6 years ago

electric commented 6 years ago

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 commented 6 years ago

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!