The MySQL upstart job does not monitor the mysqld process anymore. Instead it is shut down by mysqladmin tool in the postStop phase. Under high load, upstart may send a KILL signal to the mysql daemon, which may cause data corruption.
svn path=/nixos/trunk/; revision=31621
This commit is contained in:
parent
5d12152b13
commit
d4b6aa3553
@ -80,49 +80,49 @@ in
|
|||||||
initialDatabases = mkOption {
|
initialDatabases = mkOption {
|
||||||
default = [];
|
default = [];
|
||||||
description = "List of database names and their initial schemas that should be used to create databases on the first startup of MySQL";
|
description = "List of database names and their initial schemas that should be used to create databases on the first startup of MySQL";
|
||||||
example = [
|
example = [
|
||||||
{ name = "foodatabase"; schema = ./foodatabase.sql; }
|
{ name = "foodatabase"; schema = ./foodatabase.sql; }
|
||||||
{ name = "bardatabase"; schema = ./bardatabase.sql; }
|
{ name = "bardatabase"; schema = ./bardatabase.sql; }
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
initialScript = mkOption {
|
initialScript = mkOption {
|
||||||
default = null;
|
default = null;
|
||||||
description = "A file containing SQL statements to be executed on the first startup. Can be used for granting certain permissions on the database";
|
description = "A file containing SQL statements to be executed on the first startup. Can be used for granting certain permissions on the database";
|
||||||
};
|
};
|
||||||
|
|
||||||
rootPassword = mkOption {
|
rootPassword = mkOption {
|
||||||
default = null;
|
default = null;
|
||||||
description = "Path to a file containing the root password, modified on the first startup. Not specifying a root password will leave the root password empty.";
|
description = "Path to a file containing the root password, modified on the first startup. Not specifying a root password will leave the root password empty.";
|
||||||
};
|
};
|
||||||
|
|
||||||
replication = {
|
replication = {
|
||||||
role = mkOption {
|
role = mkOption {
|
||||||
default = "none";
|
default = "none";
|
||||||
description = "Role of the MySQL server instance. Can be either: master, slave or none";
|
description = "Role of the MySQL server instance. Can be either: master, slave or none";
|
||||||
};
|
};
|
||||||
|
|
||||||
serverId = mkOption {
|
serverId = mkOption {
|
||||||
default = 1;
|
default = 1;
|
||||||
description = "Id of the MySQL server instance. This number must be unique for each instance";
|
description = "Id of the MySQL server instance. This number must be unique for each instance";
|
||||||
};
|
};
|
||||||
|
|
||||||
masterHost = mkOption {
|
masterHost = mkOption {
|
||||||
description = "Hostname of the MySQL master server";
|
description = "Hostname of the MySQL master server";
|
||||||
};
|
};
|
||||||
|
|
||||||
masterUser = mkOption {
|
masterUser = mkOption {
|
||||||
description = "Username of the MySQL replication user";
|
description = "Username of the MySQL replication user";
|
||||||
};
|
};
|
||||||
|
|
||||||
masterPassword = mkOption {
|
masterPassword = mkOption {
|
||||||
description = "Password of the MySQL replication user";
|
description = "Password of the MySQL replication user";
|
||||||
};
|
};
|
||||||
|
|
||||||
masterPort = mkOption {
|
masterPort = mkOption {
|
||||||
default = 3306;
|
default = 3306;
|
||||||
description = "Port number on which the MySQL master server runs";
|
description = "Port number on which the MySQL master server runs";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -151,17 +151,14 @@ in
|
|||||||
mkdir -m 0700 -p ${cfg.dataDir}
|
mkdir -m 0700 -p ${cfg.dataDir}
|
||||||
chown -R ${cfg.user} ${cfg.dataDir}
|
chown -R ${cfg.user} ${cfg.dataDir}
|
||||||
${mysql}/bin/mysql_install_db ${mysqldOptions}
|
${mysql}/bin/mysql_install_db ${mysqldOptions}
|
||||||
touch /tmp/mysql_init
|
touch /tmp/mysql_init
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mkdir -m 0700 -p ${cfg.pidDir}
|
mkdir -m 0700 -p ${cfg.pidDir}
|
||||||
chown -R ${cfg.user} ${cfg.pidDir}
|
chown -R ${cfg.user} ${cfg.pidDir}
|
||||||
'';
|
|
||||||
|
${mysql}/libexec/mysqld --defaults-extra-file=${myCnf} ${mysqldOptions} &
|
||||||
|
|
||||||
exec = "${mysql}/libexec/mysqld --defaults-extra-file=${myCnf} ${mysqldOptions}";
|
|
||||||
|
|
||||||
postStart =
|
|
||||||
''
|
|
||||||
# Wait until the MySQL server is available for use
|
# Wait until the MySQL server is available for use
|
||||||
count=0
|
count=0
|
||||||
while [ ! -e /tmp/mysql.sock ]
|
while [ ! -e /tmp/mysql.sock ]
|
||||||
@ -169,7 +166,7 @@ in
|
|||||||
if [ $count -eq 30 ]
|
if [ $count -eq 30 ]
|
||||||
then
|
then
|
||||||
echo "Tried 30 times, giving up..."
|
echo "Tried 30 times, giving up..."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "MySQL daemon not yet started. Waiting for 1 second..."
|
echo "MySQL daemon not yet started. Waiting for 1 second..."
|
||||||
@ -177,48 +174,49 @@ in
|
|||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ -f /tmp/mysql_init ]
|
if [ -f /tmp/mysql_init ]
|
||||||
then
|
then
|
||||||
# Create initial databases
|
|
||||||
|
|
||||||
${concatMapStrings (database:
|
${concatMapStrings (database:
|
||||||
''
|
''
|
||||||
|
# Create initial databases
|
||||||
if ! test -e "${cfg.dataDir}/${database.name}"; then
|
if ! test -e "${cfg.dataDir}/${database.name}"; then
|
||||||
echo "Creating initial database: ${database.name}"
|
echo "Creating initial database: ${database.name}"
|
||||||
( echo "create database ${database.name};"
|
( echo "create database ${database.name};"
|
||||||
echo "use ${database.name};"
|
echo "use ${database.name};"
|
||||||
if [ -f "${database.schema}" ]
|
|
||||||
then
|
if [ -f "${database.schema}" ]
|
||||||
|
then
|
||||||
cat ${database.schema}
|
cat ${database.schema}
|
||||||
elif [ -d "${database.schema}" ]
|
elif [ -d "${database.schema}" ]
|
||||||
then
|
then
|
||||||
cat ${database.schema}/mysql-databases/*.sql
|
cat ${database.schema}/mysql-databases/*.sql
|
||||||
fi
|
fi
|
||||||
) | ${mysql}/bin/mysql -u root -N
|
) | ${mysql}/bin/mysql -u root -N
|
||||||
fi
|
fi
|
||||||
'') cfg.initialDatabases}
|
'') cfg.initialDatabases}
|
||||||
|
|
||||||
# Execute initial script
|
${optionalString (cfg.initialScript != null)
|
||||||
|
''
|
||||||
|
# Execute initial script
|
||||||
|
cat ${cfg.initialScript} | ${mysql}/bin/mysql -u root -N
|
||||||
|
''}
|
||||||
|
|
||||||
${optionalString (cfg.initialScript != null)
|
${optionalString (cfg.rootPassword != null)
|
||||||
''
|
''
|
||||||
cat ${cfg.initialScript} | ${mysql}/bin/mysql -u root -N
|
# Change root password
|
||||||
''}
|
|
||||||
|
( echo "use mysql;"
|
||||||
|
echo "update user set Password=password('$(cat ${cfg.rootPassword})') where User='root';"
|
||||||
|
echo "flush privileges;"
|
||||||
|
) | ${mysql}/bin/mysql -u root -N
|
||||||
|
''}
|
||||||
|
|
||||||
# Change root password
|
rm /tmp/mysql_init
|
||||||
|
fi
|
||||||
${optionalString (cfg.rootPassword != null)
|
'';
|
||||||
''
|
|
||||||
( echo "use mysql;"
|
|
||||||
echo "update user set Password=password('$(cat ${cfg.rootPassword})') where User='root';"
|
|
||||||
echo "flush privileges;"
|
|
||||||
) | ${mysql}/bin/mysql -u root -N
|
|
||||||
''}
|
|
||||||
|
|
||||||
rm /tmp/mysql_init
|
|
||||||
fi
|
|
||||||
'';
|
|
||||||
|
|
||||||
|
postStop = "${mysql}/bin/mysqladmin --user=root --password=\"$(cat ${cfg.rootPassword})\" shutdown";
|
||||||
|
|
||||||
# !!! Need a postStart script to wait until mysqld is ready to
|
# !!! Need a postStart script to wait until mysqld is ready to
|
||||||
# accept connections.
|
# accept connections.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user