Skip to content

Commit

Permalink
use chef notifiers to stop, move datadir and start instead of an exte…
Browse files Browse the repository at this point in the history
…rnal script
  • Loading branch information
stissot committed Oct 21, 2014
1 parent 6ea9741 commit ed6a83d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
37 changes: 25 additions & 12 deletions recipes/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 0 additions & 8 deletions templates/default/move_datadir.erb

This file was deleted.

0 comments on commit ed6a83d

Please sign in to comment.