- Implemented rootPassword option to automatically configure the root password (by default it's empty, which you usually don't want)
- Implemented initialScript option to configure database properties on first startup (such as granting permissions) svn path=/nixos/trunk/; revision=21135
This commit is contained in:
parent
94e36ec1c7
commit
1c9eb048c9
|
@ -61,7 +61,7 @@ in
|
||||||
pidDir = mkOption {
|
pidDir = mkOption {
|
||||||
default = "/var/run/mysql";
|
default = "/var/run/mysql";
|
||||||
description = "Location of the file which stores the PID of the MySQL server";
|
description = "Location of the file which stores the PID of the MySQL server";
|
||||||
};
|
};
|
||||||
|
|
||||||
initialDatabases = mkOption {
|
initialDatabases = mkOption {
|
||||||
default = [];
|
default = [];
|
||||||
|
@ -71,6 +71,16 @@ in
|
||||||
{ name = "bardatabase"; schema = ./bardatabase.sql; }
|
{ name = "bardatabase"; schema = ./bardatabase.sql; }
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
initialScript = mkOption {
|
||||||
|
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";
|
||||||
|
};
|
||||||
|
|
||||||
|
rootPassword = mkOption {
|
||||||
|
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.";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -98,6 +108,7 @@ 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
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mkdir -m 0700 -p ${cfg.pidDir}
|
mkdir -m 0700 -p ${cfg.pidDir}
|
||||||
|
@ -114,35 +125,57 @@ in
|
||||||
do
|
do
|
||||||
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..."
|
||||||
count=$((count++))
|
count=$((count++))
|
||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
|
|
||||||
# Create initial databases
|
if [ -f /tmp/mysql_init ]
|
||||||
|
then
|
||||||
|
# Create initial databases
|
||||||
|
|
||||||
${concatMapStrings (database:
|
${concatMapStrings (database:
|
||||||
''
|
''
|
||||||
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}" ]
|
if [ -f "${database.schema}" ]
|
||||||
then
|
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
|
||||||
|
fi
|
||||||
|
'') cfg.initialDatabases}
|
||||||
|
|
||||||
|
# Execute initial script
|
||||||
|
|
||||||
|
${optionalString (cfg.initialScript != null)
|
||||||
|
''
|
||||||
|
cat ${cfg.initialScript} | ${mysql}/bin/mysql -u root -N
|
||||||
|
''}
|
||||||
|
|
||||||
|
# Change root password
|
||||||
|
|
||||||
|
${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
|
) | ${mysql}/bin/mysql -u root -N
|
||||||
fi
|
''}
|
||||||
'') cfg.initialDatabases}
|
|
||||||
|
rm /tmp/mysql_init
|
||||||
|
fi
|
||||||
'';
|
'';
|
||||||
|
|
||||||
# !!! 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…
Reference in New Issue