11require  'win32/service' 
2- require  'win32/service' 
32
43ENV [ 'PATH' ]  += ";#{ node [ 'mysql' ] [ 'windows' ] [ 'bin_dir' ] }  
5- package_file  =  Chef ::Config [ :file_cache_path ]  + node [ 'mysql' ] [ 'windows' ] [ 'package_file' ] 
4+ package_file  =  Chef ::Config [ :file_cache_path ]  + File :: ALT_SEPARATOR  +  node [ 'mysql' ] [ 'windows' ] [ 'package_file' ] 
65install_dir  =  win_friendly_path ( node [ 'mysql' ] [ 'windows' ] [ 'basedir' ] ) 
76
8- def  package ( *args ,  &blk ) 
9-   windows_package ( *args ,  &blk ) 
10- end 
11- 
12- #---- 
137windows_path  node [ 'mysql' ] [ 'windows' ] [ 'bin_dir' ]  do 
148  action  :add 
159end 
@@ -25,99 +19,46 @@ def package(*args, &blk)
2519  notifies  :run ,  'execute[install mysql service]' ,  :immediately 
2620end 
2721
28- #--- FIX ME - directories 
29- 
30- #---- 
31- execute  'install mysql service'  do 
32-   command  %Q["#{ node [ 'mysql' ] [ 'windows' ] [ 'bin_dir' ] } \\ mysqld.exe" --install "#{ node [ 'mysql' ] [ 'server' ] [ 'service_name' ] }  
33-   not_if  {  ::Win32 ::Service . exists? ( node [ 'mysql' ] [ 'windows' ] [ 'service_name' ] )  } 
34- end 
35- 
36- #---- 
37- template  'initial-my.cnf'  do 
38-   path  "#{ node [ 'mysql' ] [ 'windows' ] [ 'conf_dir' ] }  
39-   source  'my.cnf.erb' 
40-   mode  '0644' 
41-   notifies  :reload ,  node [ 'mysql' ] [ 'windows' ] [ 'service_name' ] ,  :delayed 
42- end 
43- 
44- #---- 
45- 
46- windows_path  node [ 'mysql' ] [ 'bin_dir' ]  do 
47-   action  :add 
48- end 
49- 
50- windows_batch  'install mysql service'  do 
51-   command  "\" #{ node [ 'mysql' ] [ 'bin_dir' ] } \\ mysqld.exe\"  --install #{ node [ 'mysql' ] [ 'service_name' ] }  
52-   not_if   {  Win32 ::Service . exists? ( node [ 'mysql' ] [ 'service_name' ] )  } 
53- end 
54- 
55- #---- 
56- 
57- src_dir  =  win_friendly_path ( "#{ node [ 'mysql' ] [ 'basedir' ] } \\ data" ) 
58- target_dir  =  win_friendly_path ( node [ 'mysql' ] [ 'data_dir' ] ) 
59- 
60- %w{ mysql  performance_schema } . each  do  |db |
61-   execute  'mysql-move-db'  do 
62-     command  %Q[move "#{ src_dir } \\ #{ db } #{ target_dir }  
63-     action  :run 
64-     not_if  {  File . exists? ( node [ 'mysql' ] [ 'data_dir' ]  + '/mysql/user.frm' )  } 
65-   end 
22+ template  'my.ini'  do 
23+   path  "#{ node [ 'mysql' ] [ 'windows' ] [ 'bin_dir' ] } \\ my.ini" 
24+   source  'my.ini.erb' 
25+   notifies  :restart ,  "service[mysql]" 
6626end 
6727
68- #---- 
69- 
70- execute  'mysql-install-db'  do 
71-   command  'mysql_install_db' 
72-   action  :run 
73-   not_if  {  File . exists? ( node [ 'mysql' ] [ 'data_dir' ]  + '/mysql/user.frm' )  } 
28+ execute  'install mysql service'  do 
29+   command  %Q["#{ node [ 'mysql' ] [ 'windows' ] [ 'bin_dir' ] } \\ mysqld.exe" --install "#{ node [ 'mysql' ] [ 'server' ] [ 'service_name' ] } #{ node [ 'mysql' ] [ 'windows' ] [ 'bin_dir' ] } \\ my.ini"] 
30+   not_if  {  ::Win32 ::Service . exists? ( node [ 'mysql' ] [ 'server' ] [ 'service_name' ] )  } 
7431end 
7532
7633service  'mysql'  do 
77-   service_name  node [ 'mysql' ] [ 'service_name' ] 
78-   provider      Chef ::Provider ::Service ::Upstart  if  node [ 'mysql' ] [ 'use_upstart' ] 
79-   supports      :status  =>  true ,  :restart  =>  true ,  :reload  =>  true 
80-   action        :enable 
81- end 
82- 
83- template  'final-my.cnf'  do 
84-   path  "#{ node [ 'mysql' ] [ 'conf_dir' ] }  
85-   source  'my.cnf.erb' 
86-   mode  '0644' 
87-   notifies  :restart ,  'service[mysql]' ,  :immediately 
34+   service_name  node [ 'mysql' ] [ 'server' ] [ 'service_name' ] 
35+   action        [ :enable ,  :start ] 
8836end 
8937
90- #---- 
91- 
9238execute  'assign-root-password'  do 
93-   command  %Q["#{ node [ 'mysql' ] [ 'mysqladmin_bin' ] } ' #{ node [ 'mysql' ] [ 'server_root_password' ] } ' ] 
39+   command  %Q["#{ node [ 'mysql' ] [ 'windows'  ] [ ' mysqladmin_bin'] } #{ node [ 'mysql' ] [ 'server_root_password' ] }  
9440  action  :run 
95-   only_if  %Q["#{ node [ 'mysql' ] [ 'mysql_bin' ] }  
41+   # only_if %Q["#{node['mysql']['windows']['mysql_bin']}" -u root -e 'show databases;'] # unreliable due to CHEF-4783; always returns 0 when run in Chef 
42+   not_if  {  node [ 'mysql' ] [ 'root_password_set' ]  } 
43+   notifies  :run ,  "ruby_block[root-password-set]" ,  :immediately 
9644end 
9745
98- #---- 
99- 
100- grants_path  =  node [ 'mysql' ] [ 'grants_path' ] 
101- 
102- begin 
103-   resources ( "template[#{ grants_path }  ) 
104- rescue 
105-   Chef ::Log . info ( 'Could not find previously defined grants.sql resource' ) 
106-   template  grants_path  do 
107-     source  'grants.sql.erb' 
108-     mode    '0600' 
109-     action  :create 
46+ ruby_block  'root-password-set'  do 
47+   block  do 
48+     node . set [ 'mysql' ] [ 'root_password_set' ]  =  true 
11049  end 
50+   action  :nothing 
11151end 
11252
113- #---- 
114- windows_batch  'mysql-install-privileges'  do 
115-   command  "\" #{ node [ 'mysql' ] [ 'mysql_bin' ] } \"  -u root #{ node [ 'mysql' ] [ 'server_root_password' ] . empty?  ? ''  : '-p'  } \" #{ node [ 'mysql' ] [ 'server_root_password' ] } \"  < \" #{ grants_path } \" " 
116-   action  :nothing 
117-   subscribes  :run ,  resources ( "template[#{ grants_path }  ) ,  :immediately 
53+ grants_path  =  node [ 'mysql' ] [ 'windows' ] [ 'grants_path' ] 
54+ 
55+ template  grants_path  do 
56+   source  'grants.sql.erb' 
57+   action  :create 
58+   notifies  :run ,  "execute[mysql-install-privileges]" ,  :immediately 
11859end 
11960
120- service  'mysql-start '  do 
121-   service_name   node [ 'mysql' ] [ 'server ' ] [ 'service_name'  ] 
122-   action  :start  
61+ execute  'mysql-install-privileges '  do 
62+   command   " \" #{ node [ 'mysql' ] [ 'windows ' ] [ 'mysql_bin'  ] } \"  -u root  #{ node [ 'mysql' ] [ 'server_root_password' ] . empty?  ?  ''  :  '-p'   } \" #{ node [ 'mysql' ] [ 'server_root_password' ] } \"  <  \" #{ grants_path } \" " 
63+   action  :nothing  
12364end 
0 commit comments