postgresql: Add initialScript for initial SQL.
Just like in the MySQL service module it really makes sense to provide a way to inject SQL on the first start of the database cluster. Signed-off-by: aszlig <aszlig@redmoonstudios.org>
This commit is contained in:
parent
ec1f3e7832
commit
d5f0183153
@ -87,6 +87,14 @@ in
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
initialScript = mkOption {
|
||||||
|
default = null;
|
||||||
|
type = types.nullOr types.path;
|
||||||
|
description = ''
|
||||||
|
A file containing SQL statements to execute on first startup.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
authMethod = mkOption {
|
authMethod = mkOption {
|
||||||
default = " ident sameuser ";
|
default = " ident sameuser ";
|
||||||
description = ''
|
description = ''
|
||||||
@ -166,6 +174,7 @@ in
|
|||||||
chown -R postgres ${cfg.dataDir}
|
chown -R postgres ${cfg.dataDir}
|
||||||
su -s ${pkgs.stdenv.shell} postgres -c 'initdb -U root'
|
su -s ${pkgs.stdenv.shell} postgres -c 'initdb -U root'
|
||||||
rm -f ${cfg.dataDir}/*.conf
|
rm -f ${cfg.dataDir}/*.conf
|
||||||
|
touch "${cfg.dataDir}/.first_startup"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ln -sfn ${configFile} ${cfg.dataDir}/postgresql.conf
|
ln -sfn ${configFile} ${cfg.dataDir}/postgresql.conf
|
||||||
@ -193,6 +202,13 @@ in
|
|||||||
if ! kill -0 "$MAINPID"; then exit 1; fi
|
if ! kill -0 "$MAINPID"; then exit 1; fi
|
||||||
sleep 0.1
|
sleep 0.1
|
||||||
done
|
done
|
||||||
|
|
||||||
|
if test -e "${cfg.dataDir}/.first_startup"; then
|
||||||
|
${optionalString (cfg.initialScript != null) ''
|
||||||
|
cat "${cfg.initialScript}" | psql postgres
|
||||||
|
''}
|
||||||
|
rm -f "${cfg.dataDir}/.first_startup"
|
||||||
|
fi
|
||||||
'';
|
'';
|
||||||
|
|
||||||
unitConfig.RequiresMountsFor = "${cfg.dataDir}";
|
unitConfig.RequiresMountsFor = "${cfg.dataDir}";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user