PageRenderTime 27ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/Library/Formula/mysql-cluster.rb

https://github.com/steingrd/homebrew
Ruby | 326 lines | 255 code | 44 blank | 27 comment | 7 complexity | cf0e3aab6152c5e5331639b4e4f61fb5 MD5 | raw file
  1. require 'formula'
  2. class MysqlNotInstalled < Requirement
  3. def message; <<-EOS.undent
  4. You need to disable the mysql formula with
  5. launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
  6. brew unlink mysql
  7. before installing MySQL Cluster.
  8. EOS
  9. end
  10. def satisfied?
  11. not File.exists?(HOMEBREW_PREFIX+'bin/mysqld')
  12. end
  13. def fatal?
  14. true
  15. end
  16. end
  17. class MysqlCluster < Formula
  18. homepage 'http://www.mysql.com/cluster/'
  19. url 'http://mysql.llarian.net/Downloads/MySQL-Cluster-7.2/mysql-cluster-gpl-7.2.6.tar.gz'
  20. sha1 'f5523f877391b95a2428f37047028df6361251f0'
  21. depends_on MysqlNotInstalled.new
  22. depends_on 'cmake' => :build
  23. depends_on 'readline'
  24. depends_on 'pidof'
  25. fails_with :clang do
  26. build 318
  27. cause "http://article.gmane.org/gmane.comp.db.mysql.cluster/2085"
  28. end
  29. def options
  30. [
  31. ['--with-tests', "Build with unit tests."],
  32. ['--with-embedded', "Build the embedded server."],
  33. ['--with-libedit', "Compile with EditLine wrapper instead of readline"],
  34. ['--with-archive-storage-engine', "Compile with the ARCHIVE storage engine enabled"],
  35. ['--with-blackhole-storage-engine', "Compile with the BLACKHOLE storage engine enabled"],
  36. ['--universal', "Make mysql a universal binary"],
  37. ['--enable-local-infile', "Build with local infile loading support"]
  38. ]
  39. end
  40. # Remove optimization flags from `mysql_config --cflags`
  41. # This facilitates easy compilation of gems using a brewed mysql
  42. # CMake patch needed for CMake 2.8.8.
  43. # Reported here: http://bugs.mysql.com/bug.php?id=65050
  44. # See also the mysql formula.
  45. def patches; DATA; end
  46. def install
  47. # Make sure the var/mysql-cluster directory exists
  48. (var+"mysql-cluster").mkpath
  49. args = [".",
  50. "-DCMAKE_INSTALL_PREFIX=#{prefix}",
  51. "-DMYSQL_DATADIR=#{var}/mysql-cluster",
  52. "-DINSTALL_MANDIR=#{man}",
  53. "-DINSTALL_DOCDIR=#{doc}",
  54. "-DINSTALL_INFODIR=#{info}",
  55. # CMake prepends prefix, so use share.basename
  56. "-DINSTALL_MYSQLSHAREDIR=#{share.basename}/mysql",
  57. "-DWITH_SSL=yes",
  58. "-DDEFAULT_CHARSET=utf8",
  59. "-DDEFAULT_COLLATION=utf8_general_ci",
  60. "-DSYSCONFDIR=#{etc}"]
  61. # To enable unit testing at build, we need to download the unit testing suite
  62. if ARGV.include? '--with-tests'
  63. args << "-DENABLE_DOWNLOADS=ON"
  64. else
  65. args << "-DWITH_UNIT_TESTS=OFF"
  66. end
  67. # Build the embedded server
  68. args << "-DWITH_EMBEDDED_SERVER=ON" if ARGV.include? '--with-embedded'
  69. # Compile with readline unless libedit is explicitly chosen
  70. args << "-DWITH_READLINE=yes" unless ARGV.include? '--with-libedit'
  71. # Compile with ARCHIVE engine enabled if chosen
  72. args << "-DWITH_ARCHIVE_STORAGE_ENGINE=1" if ARGV.include? '--with-archive-storage-engine'
  73. # Compile with BLACKHOLE engine enabled if chosen
  74. args << "-DWITH_BLACKHOLE_STORAGE_ENGINE=1" if ARGV.include? '--with-blackhole-storage-engine'
  75. # Make universal for binding to universal applications
  76. args << "-DCMAKE_OSX_ARCHITECTURES='i386;x86_64'" if ARGV.build_universal?
  77. # Build with local infile loading support
  78. args << "-DENABLED_LOCAL_INFILE=1" if ARGV.include? '--enable-local-infile'
  79. system "cmake", *args
  80. system "make"
  81. system "make install"
  82. # Create default directories and configuration files
  83. (var+"mysql-cluster/ndb_data").mkpath
  84. (var+"mysql-cluster/mysqld_data").mkpath
  85. (var+"mysql-cluster/conf").mkpath
  86. (var+"mysql-cluster/conf/my.cnf").write my_cnf unless File.exists? var+"mysql-cluster/conf/my.cnf"
  87. (var+"mysql-cluster/conf/config.ini").write config_ini unless File.exists? var+"mysql-cluster/conf/config.ini"
  88. plist_path('ndb_mgmd').write ndb_mgmd_startup_plist('ndb_mgmd')
  89. plist_path('ndb_mgmd').chmod 0644
  90. plist_path('ndbd').write ndbd_startup_plist('ndbd')
  91. plist_path('ndbd').chmod 0644
  92. plist_path('mysqld').write mysqld_startup_plist('mysqld')
  93. plist_path('mysqld').chmod 0644
  94. # Don't create databases inside of the prefix!
  95. # See: https://github.com/mxcl/homebrew/issues/4975
  96. rm_rf prefix+'data'
  97. # Link the setup script into bin
  98. ln_s prefix+'scripts/mysql_install_db', bin+'mysql_install_db'
  99. # Fix up the control script and link into bin
  100. inreplace "#{prefix}/support-files/mysql.server" do |s|
  101. s.gsub!(/^(PATH=".*)(")/, "\\1:#{HOMEBREW_PREFIX}/bin\\2")
  102. end
  103. ln_s "#{prefix}/support-files/mysql.server", bin
  104. end
  105. def caveats; <<-EOS.undent
  106. To get started with MySQL Cluster, read MySQL Cluster Quick Start at
  107. http://dev.mysql.com/downloads/cluster/
  108. Default configuration files have been created inside:
  109. #{var}/mysql-cluster
  110. Note that in a production system there are other parameters
  111. that you would set to tune the configuration.
  112. Launchd plists templates to automatically load the various nodes can be copied from:
  113. #{plist_path('ndb_mgmd')}
  114. #{plist_path('ndbd')}
  115. #{plist_path('mysqld')}
  116. For a first cluster, you may start with a single MySQL Server (mysqld),
  117. a pair of Data Nodes (ndbd) and a single management node (ndb_mgmd):
  118. mysql_install_db --no-defaults --basedir=#{prefix} --datadir=#{var}/mysql-cluster/mysqld_data
  119. ndb_mgmd -f #{var}/mysql-cluster/conf/config.ini --initial --configdir=#{var}/mysql-cluster/conf/
  120. ndbd -c localhost:1186
  121. ndbd -c localhost:1186
  122. mkdir -p ~/Library/LaunchAgents
  123. cp #{plist_path('mysqld')} ~/Library/LaunchAgents/
  124. launchctl load -w ~/Library/LaunchAgents/#{plist_path('mysqld').basename}
  125. mysql -h 127.0.0.1 -P 5000 -u root -p
  126. (Leave the password empty and press Enter)
  127. create database clusterdb;
  128. use clusterdb;
  129. create table simples (id int not null primary key) engine=ndb;
  130. insert into simples values (1),(2),(3),(4);
  131. select * from simples;
  132. To shutdown everything:
  133. launchctl unload -w ~/Library/LaunchAgents/#{plist_path('mysqld').basename}
  134. ndb_mgm -e shutdown
  135. EOS
  136. end
  137. def my_cnf; <<-EOCNF.undent
  138. [mysqld]
  139. ndbcluster
  140. datadir=#{var}/mysql-cluster/mysqld_data
  141. basedir=#{prefix}
  142. port=5000
  143. EOCNF
  144. end
  145. def config_ini; <<-EOCNF.undent
  146. [ndb_mgmd]
  147. hostname=localhost
  148. datadir=#{var}/mysql-cluster/ndb_data
  149. NodeId=1
  150. [ndbd default]
  151. noofreplicas=2
  152. datadir=#{var}/mysql-cluster/ndb_data
  153. [ndbd]
  154. hostname=localhost
  155. NodeId=3
  156. [ndbd]
  157. hostname=localhost
  158. NodeId=4
  159. [mysqld]
  160. NodeId=50
  161. EOCNF
  162. end
  163. # Override Formula#plist_name
  164. def plist_name(extra = nil)
  165. (extra) ? super()+'-'+extra : super()
  166. end
  167. # Override Formula#plist_path
  168. def plist_path(extra = nil)
  169. (extra) ? super().dirname+(plist_name(extra)+'.plist') : super()
  170. end
  171. def mysqld_startup_plist(name); <<-EOPLIST.undent
  172. <?xml version="1.0" encoding="UTF-8"?>
  173. <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  174. <plist version="1.0">
  175. <dict>
  176. <key>KeepAlive</key>
  177. <true/>
  178. <key>Label</key>
  179. <string>#{plist_name(name)}</string>
  180. <key>ProgramArguments</key>
  181. <array>
  182. <string>#{HOMEBREW_PREFIX}/bin/mysqld</string>
  183. <string>--defaults-file=#{var}/mysql-cluster/conf/my.cnf</string>
  184. </array>
  185. <key>RunAtLoad</key>
  186. <true/>
  187. <key>UserName</key>
  188. <string>#{`whoami`.chomp}</string>
  189. <key>WorkingDirectory</key>
  190. <string>#{var}</string>
  191. </dict>
  192. </plist>
  193. EOPLIST
  194. end
  195. def ndb_mgmd_startup_plist(name); <<-EOPLIST.undent
  196. <?xml version="1.0" encoding="UTF-8"?>
  197. <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  198. <plist version="1.0">
  199. <dict>
  200. <key>KeepAlive</key>
  201. <true/>
  202. <key>Label</key>
  203. <string>#{plist_name(name)}</string>
  204. <key>ProgramArguments</key>
  205. <array>
  206. <string>#{HOMEBREW_PREFIX}/bin/ndb_mgmd</string>
  207. <string>--nodaemon</string>
  208. <string>-f</string>
  209. <string>#{var}/mysql-cluster/conf/config.ini</string>
  210. <string>--initial</string>
  211. <string>--configdir=#{var}/mysql-cluster/conf/</string>
  212. </array>
  213. <key>RunAtLoad</key>
  214. <true/>
  215. <key>UserName</key>
  216. <string>#{`whoami`.chomp}</string>
  217. <key>WorkingDirectory</key>
  218. <string>#{var}</string>
  219. <key>StandardOutPath</key>
  220. <string>#{var}/mysql-cluster/#{name}.log</string>
  221. </dict>
  222. </plist>
  223. EOPLIST
  224. end
  225. def ndbd_startup_plist(name); <<-EOPLIST.undent
  226. <?xml version="1.0" encoding="UTF-8"?>
  227. <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  228. <plist version="1.0">
  229. <dict>
  230. <key>KeepAlive</key>
  231. <true/>
  232. <key>Label</key>
  233. <string>#{plist_name(name)}</string>
  234. <key>ProgramArguments</key>
  235. <array>
  236. <string>#{HOMEBREW_PREFIX}/bin/ndbd</string>
  237. <string>--nodaemon</string>
  238. <string>-c</string>
  239. <string>localhost:1186</string>
  240. </array>
  241. <key>RunAtLoad</key>
  242. <true/>
  243. <key>UserName</key>
  244. <string>#{`whoami`.chomp}</string>
  245. <key>WorkingDirectory</key>
  246. <string>#{var}</string>
  247. <key>StandardOutPath</key>
  248. <string>#{var}/mysql-cluster/#{name}.log</string>
  249. </dict>
  250. </plist>
  251. EOPLIST
  252. end
  253. end
  254. __END__
  255. diff --git a/configure.cmake b/configure.cmake
  256. index 6d90b78..3d6118c 100644
  257. --- a/configure.cmake
  258. +++ b/configure.cmake
  259. @@ -151,7 +151,9 @@ IF(UNIX)
  260. SET(CMAKE_REQUIRED_LIBRARIES
  261. ${LIBM} ${LIBNSL} ${LIBBIND} ${LIBCRYPT} ${LIBSOCKET} ${LIBDL} ${CMAKE_THREAD_LIBS_INIT} ${LIBRT})
  262. - LIST(REMOVE_DUPLICATES CMAKE_REQUIRED_LIBRARIES)
  263. + IF(CMAKE_REQUIRED_LIBRARIES)
  264. + LIST(REMOVE_DUPLICATES CMAKE_REQUIRED_LIBRARIES)
  265. + ENDIF()
  266. LINK_LIBRARIES(${CMAKE_THREAD_LIBS_INIT})
  267. OPTION(WITH_LIBWRAP "Compile with tcp wrappers support" OFF)
  268. diff --git a/scripts/mysql_config.sh b/scripts/mysql_config.sh
  269. index b62386a..2e8bf44 100644
  270. --- a/scripts/mysql_config.sh
  271. +++ b/scripts/mysql_config.sh
  272. @@ -137,7 +137,9 @@ for remove in DDBUG_OFF DSAFE_MUTEX DUNIV_MUST_NOT_INLINE DFORCE_INIT_OF_VARS \
  273. DEXTRA_DEBUG DHAVE_purify O 'O[0-9]' 'xO[0-9]' 'W[-A-Za-z]*' \
  274. 'mtune=[-A-Za-z0-9]*' 'mcpu=[-A-Za-z0-9]*' 'march=[-A-Za-z0-9]*' \
  275. Xa xstrconst "xc99=none" AC99 \
  276. - unroll2 ip mp restrict
  277. + unroll2 ip mp restrict \
  278. + mmmx 'msse[0-9.]*' 'mfpmath=sse' w pipe 'fomit-frame-pointer' 'mmacosx-version-min=10.[0-9]' \
  279. + aes Os
  280. do
  281. # The first option we might strip will always have a space before it because
  282. # we set -I$pkgincludedir as the first option