diff --git a/recipes/server.rb b/recipes/server.rb index 2a7e9a69..0270d39b 100644 --- a/recipes/server.rb +++ b/recipes/server.rb @@ -34,22 +34,35 @@ include_recipe "#{cookbook_name}::config" # move the datadir if needed -if node['mariadb']['mysqld']['datadir'] \ - != node['mariadb']['mysqld']['default_datadir'] \ - && !File.symlink?(node['mariadb']['mysqld']['default_datadir']) - template '/etc/mysql/move_datadir' do - source 'move_datadir.erb' - owner 'root' - group 'root' - mode '0600' - notifies :run, 'execute[move-datadir]', :immediately +if node['mariadb']['mysqld']['datadir'] != + node['mariadb']['mysqld']['default_datadir'] + + service 'mysql' do + action :nothing end - execute 'move-datadir' do + + bash 'move-datadir' do user 'root' - command '/bin/bash /etc/mysql/move_datadir' - only_if { File.exist?('/etc/mysql/move_datadir') } + code <<-EOH + /bin/cp -a #{node['mariadb']['mysqld']['default_datadir']}/* \ + #{node['mariadb']['mysqld']['datadir']} && + /bin/rm -r #{node['mariadb']['mysqld']['default_datadir']} && + /bin/ln -s #{node['mariadb']['mysqld']['datadir']} \ + #{node['mariadb']['mysqld']['default_datadir']} + EOH action :nothing end + + directory node['mariadb']['mysqld']['datadir'] do + owner 'mysql' + group 'mysql' + mode 00750 + action :create + notifies :stop, 'service[mysql]', :immediately + notifies :run, 'bash[move-datadir]', :immediately + notifies :start, 'service[mysql]', :immediately + only_if { !File.symlink?(node['mariadb']['mysqld']['default_datadir']) } + end end # restart the service if needed diff --git a/templates/default/move_datadir.erb b/templates/default/move_datadir.erb deleted file mode 100644 index e6bc2ce5..00000000 --- a/templates/default/move_datadir.erb +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -# Generated by CHEF -# Local modification will be overriden - -/usr/sbin/service mysql stop -/bin/mv <%= node['mariadb']['mysqld']['default_datadir'] %> <%= node['mariadb']['mysqld']['datadir'] %> -/bin/ln -s <%= node['mariadb']['mysqld']['datadir'] %> <%= node['mariadb']['mysqld']['default_datadir'] %> -/usr/sbin/service mysql start