aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorIgor Pashev <pashev.igor@gmail.com>2017-01-20 11:57:56 +0300
committerIgor Pashev <pashev.igor@gmail.com>2017-01-20 12:23:58 +0300
commit26d266fe9ef63622294bfe6f615e79906f988469 (patch)
tree9163a0c68becfde57c772b05ccac3be3bde60389 /modules
parentd684a77fd887bf6a62a166f6ccc34501d614de3b (diff)
downloadnixsap-26d266fe9ef63622294bfe6f615e79906f988469.tar.gz
mariadb: use explicit package
Diffstat (limited to 'modules')
-rw-r--r--modules/apps/mariadb/default.nix38
-rw-r--r--modules/apps/mariadb/roles.nix9
-rw-r--r--modules/apps/mariadb/slave-watchdog.nix36
3 files changed, 41 insertions, 42 deletions
diff --git a/modules/apps/mariadb/default.nix b/modules/apps/mariadb/default.nix
index 5610ede..b3701d1 100644
--- a/modules/apps/mariadb/default.nix
+++ b/modules/apps/mariadb/default.nix
@@ -116,9 +116,9 @@ let
await = pkgs.writeBashScript "await" ''
count=0
- while ! mysql -e ';' 2>/dev/null; do
+ while ! ${cfg.package}/bin/mysql -e ';' 2>/dev/null; do
if ! (( count % 60 )); then
- mysql -e ';'
+ ${cfg.package}/bin/mysql -e ';'
fi
sleep 5s
(( ++count ))
@@ -133,22 +133,22 @@ let
${optionalString (cfg.configure' != "") ''
tmp=$(mktemp)
trap 'rm -f "$tmp"' EXIT
- mysql -N mysql < ${pkgs.writeText "mariadb-make-conf2.sql" cfg.configure'} > "$tmp"
- mysql -v mysql < "$tmp"
+ ${cfg.package}/bin/mysql -N mysql < ${pkgs.writeText "mariadb-make-conf2.sql" cfg.configure'} > "$tmp"
+ ${cfg.package}/bin/mysql -v mysql < "$tmp"
''}
- mysql -v mysql < ${pkgs.writeText "mariadb-conf.sql" cfg.configure}
+ ${cfg.package}/bin/mysql -v mysql < ${pkgs.writeText "mariadb-conf.sql" cfg.configure}
'';
maintenance = pkgs.writeBashScriptBin "mariadb-maint" ''
set -euo pipefail
trap "" SIGHUP
${await}
- ${optionalString hasMasters "mysql -e 'STOP ALL SLAVES SQL_THREAD'"}
- mysql_upgrade --user=${cfg.user}
- mysql_tzinfo_to_sql "$TZDIR" | mysql mysql
- mysql mysql < ${./procedures.sql}
+ ${optionalString hasMasters "${cfg.package}/bin/mysql -e 'STOP ALL SLAVES SQL_THREAD'"}
+ ${cfg.package}/bin/mysql_upgrade --user=${cfg.user}
+ ${cfg.package}/bin/mysql_tzinfo_to_sql "$TZDIR" | ${cfg.package}/bin/mysql mysql
+ ${cfg.package}/bin/mysql mysql < ${./procedures.sql}
- cat <<'__SQL__' | mysql -N mysql | mysql -v mysql
+ cat <<'__SQL__' | ${cfg.package}/bin/mysql -N mysql | ${cfg.package}/bin/mysql -v mysql
SELECT CONCAT("DROP USER IF EXISTS '", User, "'@'", Host, "';")
FROM user
WHERE User IN ('root', ${"''"})
@@ -156,14 +156,14 @@ let
;
__SQL__
- cat <<'__SQL__' | mysql -v mysql
+ cat <<'__SQL__' | ${cfg.package}/bin/mysql -v mysql
DROP DATABASE IF EXISTS test;
${concatMapStrings (db: ''
CREATE DATABASE IF NOT EXISTS `${db}`;
'') cfg.databases}
__SQL__
- ${optionalString hasMasters "mysql -e 'START ALL SLAVES'"}
+ ${optionalString hasMasters "${cfg.package}/bin/mysql -e 'START ALL SLAVES'"}
'';
changeMaster =
@@ -197,7 +197,7 @@ let
cnf = "${rundir}/master-${ch}.cnf";
mysqldumpOptions = filterAttrs (n: _: n != "password-file" && n != "path")
(explicit opts.mysqldump);
- binary = if opts.mysqldump.path != null then opts.mysqldump.path else "mysqldump";
+ binary = if opts.mysqldump.path != null then opts.mysqldump.path else "${cfg.package}/bin/mysqldump";
mysqldump = concatStringsSep " " (
[ binary "--defaults-file=${cnf}" "--skip-comments" "--force" ]
++ mapAttrsToList (n: v: "--${n}=${show n v}") mysqldumpOptions);
@@ -225,7 +225,7 @@ let
);
watchdog = pkgs.writeBashScript "slave-watchdog"
- (import ./slave-watchdog.nix {inherit importDump changeMaster;});
+ (import ./slave-watchdog.nix {inherit cfg importDump changeMaster;});
slaves =
let
@@ -244,16 +244,16 @@ let
touch ${old}
chmod 0600 ${old}
trap 'rm -f ${old}' EXIT
- mysql -e 'SHOW ALL SLAVES STATUS\G' \
+ ${cfg.package}/bin/mysql -e 'SHOW ALL SLAVES STATUS\G' \
| awk '/Connection_name:/ {printf $2 ":"}; /Master_Host:/ {print $2}' \
| sort > ${old}
obsolete=$(comm -23 ${old} ${new} | cut -d: -f1)
for ch in $obsolete; do
echo "Deleting obsolete slave $ch"
- mysql -e "CALL mysql.resetSlave('$ch')"
+ ${cfg.package}/bin/mysql -e "CALL mysql.resetSlave('$ch')"
done
${optionalString hasMasters ''
- mysql -f < ${truncateIgnored} || echo '(errors ignored)' >&2
+ ${cfg.package}/bin/mysql -f < ${truncateIgnored} || echo '(errors ignored)' >&2
export PARALLEL_SHELL=${pkgs.bash}/bin/bash
export HOME='${rundir}'
{
@@ -380,7 +380,7 @@ in {
requires = [ "mariadb.service" ];
after = [ "mariadb.service" "mariadb-maintenance.service" ];
wantedBy = [ "multi-user.target" ];
- path = with pkgs; [ gnused gawk cfg.package utillinux parallel ];
+ path = with pkgs; [ gnused gawk utillinux parallel ];
serviceConfig = {
ExecStart = "${slaves}/bin/mariadb-slaves";
User = cfg.user;
@@ -397,7 +397,6 @@ in {
description = "MariaDB maintenance";
after = [ "mariadb.service" ];
wantedBy = [ "multi-user.target" ];
- path = [ cfg.package ];
serviceConfig = {
ExecStart = "${maintenance}/bin/mariadb-maint";
User = cfg.user;
@@ -410,7 +409,6 @@ in {
description = "MariaDB configuration";
after = [ "mariadb.service" "mariadb-maintenance.service" ];
wantedBy = [ "multi-user.target" ];
- path = [ cfg.package ];
serviceConfig = {
ExecStart = "${conf}/bin/mariadb-conf";
User = cfg.user;
diff --git a/modules/apps/mariadb/roles.nix b/modules/apps/mariadb/roles.nix
index 0e10cf9..3ee7852 100644
--- a/modules/apps/mariadb/roles.nix
+++ b/modules/apps/mariadb/roles.nix
@@ -9,6 +9,8 @@ let
inherit (types)
attrsOf either listOf str submodule ;
+ cfg = config.nixsap.apps.mariadb;
+
explicit = filterAttrs (n: v: n != "_module" && v != null);
inherit (config.nixsap.apps.mariadb) roles;
@@ -127,13 +129,13 @@ let
}
while true; do
- while ! mysql -e ';'; do
+ while ! ${cfg.package}/bin/mysql -e ';'; do
sleep 5s
done
tmp=$(mktemp)
trap 'rm -f "$tmp"' EXIT
- mysql -N mysql < ${refreshRolesSQL} >> "$tmp"
- mysql -v mysql < "$tmp"
+ ${cfg.package}/bin/mysql -N mysql < ${refreshRolesSQL} >> "$tmp"
+ ${cfg.package}/bin/mysql -v mysql < "$tmp"
doze
done
'';
@@ -238,7 +240,6 @@ in {
description = "refresh MariaDB basic roles";
after = [ "mariadb.service" "mariadb-maintenance.service" ];
wantedBy = [ "multi-user.target" ];
- path = [ pkgs.mariadb ];
serviceConfig = {
ExecStart = "${refreshRoles}/bin/refreshRoles";
User = config.nixsap.apps.mariadb.user;
diff --git a/modules/apps/mariadb/slave-watchdog.nix b/modules/apps/mariadb/slave-watchdog.nix
index 8d1147e..74cf7ef 100644
--- a/modules/apps/mariadb/slave-watchdog.nix
+++ b/modules/apps/mariadb/slave-watchdog.nix
@@ -1,4 +1,4 @@
-{ changeMaster, importDump }: ''
+{ cfg, changeMaster, importDump }: ''
set -euo pipefail
ch="$1"
@@ -6,11 +6,11 @@ status=$(mktemp)
trap 'rm -f "$status"' EXIT
slave_status () {
- if ! mysql -e ';'; then
+ if ! ${cfg.package}/bin/mysql -e ';'; then
echo unknown; return
fi
- if mysql -e "SHOW SLAVE '$1' STATUS\\G" | sed 's,^ *,,' > "$status"; then
+ if ${cfg.package}/bin/mysql -e "SHOW SLAVE '$1' STATUS\\G" | sed 's,^ *,,' > "$status"; then
if grep -oE '\bMaster_Server_Id:\s*[1-9][0-9]*' "$status" >&2; then
io_errno=$(awk '/Last_IO_Errno:/ {print $2}' "$status")
sql_errno=$(awk '/Last_SQL_Errno:/ {print $2}' "$status")
@@ -53,44 +53,44 @@ while true; do
sleep 1m
continue
fi
- mysql -v -N -e "CALL mysql.resetSlave('$ch')" >&2
- ${changeMaster} "$ch" | mysql
- if ${importDump} "$ch" | mysql; then
- mysql -v -N -e "CALL mysql.startSlave('$ch')" >&2
+ ${cfg.package}/bin/mysql -v -N -e "CALL mysql.resetSlave('$ch')" >&2
+ ${changeMaster} "$ch" | ${cfg.package}/bin/mysql
+ if ${importDump} "$ch" | ${cfg.package}/bin/mysql; then
+ ${cfg.package}/bin/mysql -v -N -e "CALL mysql.startSlave('$ch')" >&2
exit
else
echo 'Import failed. Starting over' >&2
- mysql -v -N -e "CALL mysql.resetSlave('$ch')" >&2
+ ${cfg.package}/bin/mysql -v -N -e "CALL mysql.resetSlave('$ch')" >&2
exit 1
fi
;;
io_error:*)
echo "status: $st" >&2
- mysql -v -N -e "CALL mysql.stopSlave('$ch')" >&2
- ${changeMaster} "$ch" | mysql
- mysql -v -N -e "CALL mysql.startSlave('$ch')" >&2
+ ${cfg.package}/bin/mysql -v -N -e "CALL mysql.stopSlave('$ch')" >&2
+ ${changeMaster} "$ch" | ${cfg.package}/bin/mysql
+ ${cfg.package}/bin/mysql -v -N -e "CALL mysql.startSlave('$ch')" >&2
exit 1
;;
sql_error:1205) # Lock wait timeout exceeded
echo "status: $st" >&2
- mysql -v -N -e "CALL mysql.startSlave('$ch')" >&2
+ ${cfg.package}/bin/mysql -v -N -e "CALL mysql.startSlave('$ch')" >&2
exit 1
;;
sql_error:*)
(( ++sql_errors ))
echo "status: $st (count: $sql_errors)" >&2
if [ "$sql_errors" -le 1 ]; then
- mysql -v -N -e "CALL mysql.pauseSlave('$ch')" >&2
+ ${cfg.package}/bin/mysql -v -N -e "CALL mysql.pauseSlave('$ch')" >&2
sleep 1s
- mysql -v -N -e "CALL mysql.startSlave('$ch')" >&2
+ ${cfg.package}/bin/mysql -v -N -e "CALL mysql.startSlave('$ch')" >&2
elif [ "$sql_errors" -le 2 ]; then
- mysql -v -N -e "CALL mysql.stopSlave('$ch')" >&2
+ ${cfg.package}/bin/mysql -v -N -e "CALL mysql.stopSlave('$ch')" >&2
# this *unlikely* *may* change replication option (ignore tables, etc.)
- ${changeMaster} "$ch" | mysql
- mysql -v -N -e "CALL mysql.startSlave('$ch')" >&2
+ ${changeMaster} "$ch" | ${cfg.package}/bin/mysql
+ ${cfg.package}/bin/mysql -v -N -e "CALL mysql.startSlave('$ch')" >&2
else
echo '!!! Resetting slave !!!' >&2
- mysql -v -N -e "CALL mysql.resetSlave('$ch')" >&2
+ ${cfg.package}/bin/mysql -v -N -e "CALL mysql.resetSlave('$ch')" >&2
exit 1
fi
sleep 2m