193 lines
6.5 KiB
Ruby
193 lines
6.5 KiB
Ruby
class PerconaServer < Formula
|
|
desc "Drop-in MySQL replacement"
|
|
homepage "https://www.percona.com"
|
|
url "https://www.percona.com/downloads/Percona-Server-8.0/Percona-Server-8.0.19-10/source/tarball/percona-server-8.0.19-10.tar.gz"
|
|
sha256 "b819d81b9cdef497dd5fd1044ddb033d222b986cf610cb5d4bb1fa5010dba580"
|
|
|
|
livecheck do
|
|
url "https://www.percona.com/downloads/Percona-Server-LATEST/"
|
|
regex(/value=.*?Percona-Server[._-]v?(\d+(?:\.\d+)+-\d+)["' >]/i)
|
|
end
|
|
|
|
bottle do
|
|
rebuild 1
|
|
sha256 arm64_big_sur: "e5c4e639848be2d3c0821c4b53ae5a9d1cff182e31416378b27937c5d8cda47c"
|
|
sha256 big_sur: "9047fd11394d720736b4b866be2f62d3e676243b17c10fda3d649eecc2da257d"
|
|
sha256 catalina: "156224d81ec50f401b366051de9a5c02b3921f54f61ebed2d6897edb5c313ef0"
|
|
sha256 mojave: "ee1f35b9a3817d3cab87034cbfb04867bf5366a0f0ad5cce539d9bb71812f03d"
|
|
end
|
|
|
|
pour_bottle? do
|
|
reason "The bottle needs a var/mysql datadir (yours is var/percona)."
|
|
satisfy { datadir == var/"mysql" }
|
|
end
|
|
|
|
depends_on "cmake" => :build
|
|
depends_on "openssl@1.1"
|
|
|
|
conflicts_with "mariadb", "mysql",
|
|
because: "percona, mariadb, and mysql install the same binaries"
|
|
conflicts_with "protobuf", because: "both install libprotobuf(-lite) libraries"
|
|
conflicts_with "percona-xtrabackup", because: "both install comp_err.1 man page"
|
|
|
|
# https://bugs.mysql.com/bug.php?id=86711
|
|
# https://github.com/Homebrew/homebrew-core/pull/20538
|
|
fails_with :clang do
|
|
build 800
|
|
cause "Wrong inlining with Clang 8.0, see MySQL Bug #86711"
|
|
end
|
|
|
|
resource "boost" do
|
|
url "https://dl.bintray.com/boostorg/release/1.70.0/source/boost_1_70_0.tar.bz2"
|
|
sha256 "430ae8354789de4fd19ee52f3b1f739e1fba576f0aded0897c3c2bc00fb38778"
|
|
end
|
|
|
|
# Where the database files should be located. Existing installs have them
|
|
# under var/percona, but going forward they will be under var/mysql to be
|
|
# shared with the mysql and mariadb formulae.
|
|
def datadir
|
|
@datadir ||= (var/"percona").directory? ? var/"percona" : var/"mysql"
|
|
end
|
|
|
|
def install
|
|
# -DINSTALL_* are relative to `CMAKE_INSTALL_PREFIX` (`prefix`)
|
|
args = %W[
|
|
-DFORCE_INSOURCE_BUILD=1
|
|
-DCOMPILATION_COMMENT=Homebrew
|
|
-DDEFAULT_CHARSET=utf8mb4
|
|
-DDEFAULT_COLLATION=utf8mb4_0900_ai_ci
|
|
-DINSTALL_DOCDIR=share/doc/#{name}
|
|
-DINSTALL_INCLUDEDIR=include/mysql
|
|
-DINSTALL_INFODIR=share/info
|
|
-DINSTALL_MANDIR=share/man
|
|
-DINSTALL_MYSQLSHAREDIR=share/mysql
|
|
-DINSTALL_PLUGINDIR=lib/percona-server/plugin
|
|
-DMYSQL_DATADIR=#{datadir}
|
|
-DSYSCONFDIR=#{etc}
|
|
-DWITH_SSL=yes
|
|
-DWITH_UNIT_TESTS=OFF
|
|
-DWITH_EMBEDDED_SERVER=ON
|
|
-DENABLED_LOCAL_INFILE=1
|
|
-DWITH_INNODB_MEMCACHED=ON
|
|
-DWITH_EDITLINE=system
|
|
]
|
|
|
|
# MySQL >5.7.x mandates Boost as a requirement to build & has a strict
|
|
# version check in place to ensure it only builds against expected release.
|
|
# This is problematic when Boost releases don't align with MySQL releases.
|
|
(buildpath/"boost").install resource("boost")
|
|
args << "-DWITH_BOOST=#{buildpath}/boost"
|
|
|
|
# Percona MyRocks does not compile on macOS
|
|
# https://bugs.launchpad.net/percona-server/+bug/1741639
|
|
args.concat %w[-DWITHOUT_ROCKSDB=1]
|
|
|
|
# TokuDB does not compile on macOS
|
|
# https://bugs.launchpad.net/percona-server/+bug/1531446
|
|
args.concat %w[-DWITHOUT_TOKUDB=1]
|
|
|
|
system "cmake", ".", *std_cmake_args, *args
|
|
system "make"
|
|
system "make", "install"
|
|
|
|
(prefix/"mysql-test").cd do
|
|
system "./mysql-test-run.pl", "status", "--vardir=#{Dir.mktmpdir}"
|
|
end
|
|
|
|
# Remove the tests directory
|
|
rm_rf prefix/"mysql-test"
|
|
|
|
# Don't create databases inside of the prefix!
|
|
# See: https://github.com/Homebrew/homebrew/issues/4975
|
|
rm_rf prefix/"data"
|
|
|
|
# Fix up the control script and link into bin.
|
|
inreplace "#{prefix}/support-files/mysql.server",
|
|
/^(PATH=".*)(")/,
|
|
"\\1:#{HOMEBREW_PREFIX}/bin\\2"
|
|
bin.install_symlink prefix/"support-files/mysql.server"
|
|
|
|
# Install my.cnf that binds to 127.0.0.1 by default
|
|
(buildpath/"my.cnf").write <<~EOS
|
|
# Default Homebrew MySQL server config
|
|
[mysqld]
|
|
# Only allow connections from localhost
|
|
bind-address = 127.0.0.1
|
|
EOS
|
|
etc.install "my.cnf"
|
|
end
|
|
|
|
def post_install
|
|
# Make sure the var/mysql directory exists
|
|
(var/"mysql").mkpath
|
|
|
|
# Don't initialize database, it clashes when testing other MySQL-like implementations.
|
|
return if ENV["HOMEBREW_GITHUB_ACTIONS"]
|
|
|
|
unless (datadir/"mysql/user.frm").exist?
|
|
ENV["TMPDIR"] = nil
|
|
system bin/"mysqld", "--initialize-insecure", "--user=#{ENV["USER"]}",
|
|
"--basedir=#{prefix}", "--datadir=#{datadir}", "--tmpdir=/tmp"
|
|
end
|
|
end
|
|
|
|
def caveats
|
|
s = <<~EOS
|
|
We've installed your MySQL database without a root password. To secure it run:
|
|
mysql_secure_installation
|
|
MySQL is configured to only allow connections from localhost by default
|
|
To connect run:
|
|
mysql -uroot
|
|
EOS
|
|
if (my_cnf = ["/etc/my.cnf", "/etc/mysql/my.cnf"].find { |x| File.exist? x })
|
|
s += <<~EOS
|
|
A "#{my_cnf}" from another install may interfere with a Homebrew-built
|
|
server starting up correctly.
|
|
EOS
|
|
end
|
|
s
|
|
end
|
|
|
|
plist_options manual: "mysql.server start"
|
|
|
|
def plist
|
|
<<~EOS
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
<plist version="1.0">
|
|
<dict>
|
|
<key>KeepAlive</key>
|
|
<true/>
|
|
<key>Label</key>
|
|
<string>#{plist_name}</string>
|
|
<key>ProgramArguments</key>
|
|
<array>
|
|
<string>#{opt_bin}/mysqld_safe</string>
|
|
<string>--datadir=#{datadir}</string>
|
|
</array>
|
|
<key>RunAtLoad</key>
|
|
<true/>
|
|
<key>WorkingDirectory</key>
|
|
<string>#{datadir}</string>
|
|
</dict>
|
|
</plist>
|
|
EOS
|
|
end
|
|
|
|
test do
|
|
(testpath/"mysql").mkpath
|
|
(testpath/"tmp").mkpath
|
|
system bin/"mysqld", "--no-defaults", "--initialize-insecure", "--user=#{ENV["USER"]}",
|
|
"--basedir=#{prefix}", "--datadir=#{testpath}/mysql", "--tmpdir=#{testpath}/tmp"
|
|
port = free_port
|
|
fork do
|
|
system "#{bin}/mysqld", "--no-defaults", "--user=#{ENV["USER"]}",
|
|
"--datadir=#{testpath}/mysql", "--port=#{port}", "--tmpdir=#{testpath}/tmp"
|
|
end
|
|
sleep 5
|
|
assert_match "information_schema",
|
|
shell_output("#{bin}/mysql --port=#{port} --user=root --password= --execute='show databases;'")
|
|
system "#{bin}/mysqladmin", "--port=#{port}", "--user=root", "--password=", "shutdown"
|
|
end
|
|
end
|