Add a PostgreSQL service container provider
This commit is contained in:
parent
1ac650cf36
commit
9d44a383e5
|
@ -6,11 +6,12 @@
|
|||
, tmpDir
|
||||
, forceDisableUserChange
|
||||
, processManager
|
||||
, ids ? {}
|
||||
}:
|
||||
|
||||
let
|
||||
constructors = import ../services-agnostic/constructors.nix {
|
||||
inherit pkgs stateDir logDir runtimeDir cacheDir tmpDir forceDisableUserChange processManager;
|
||||
inherit pkgs stateDir logDir runtimeDir cacheDir tmpDir forceDisableUserChange processManager ids;
|
||||
};
|
||||
in
|
||||
{
|
||||
|
@ -38,6 +39,14 @@ in
|
|||
});
|
||||
};
|
||||
|
||||
postgresql = import ./postgresql.nix {
|
||||
inherit runtimeDir;
|
||||
postgresqlConstructorFun = constructors.postgresql;
|
||||
dysnomia = pkgs.dysnomia.override (origArgs: {
|
||||
enablePostgreSQLDatabase = true;
|
||||
});
|
||||
};
|
||||
|
||||
simpleMongodb = import ./simplemongodb.nix {
|
||||
inherit (pkgs) stdenv;
|
||||
mongodbConstructorFun = constructors.simpleMongodb;
|
||||
|
|
|
@ -1,5 +1,12 @@
|
|||
{supervisordConstructorFun, stdenv, dysnomia, stateDir}:
|
||||
{instanceSuffix ? "", instanceName ? "supervisord${instanceSuffix}", containerName ? "supervisord-program${instanceSuffix}", inetHTTPServerPort ? 9001, postInstall ? "", type}:
|
||||
|
||||
{ instanceSuffix ? "", instanceName ? "supervisord${instanceSuffix}"
|
||||
, containerName ? "supervisord-program${instanceSuffix}"
|
||||
, inetHTTPServerPort ? 9001
|
||||
, postInstall ? ""
|
||||
, type
|
||||
, properties ? {}
|
||||
}:
|
||||
|
||||
let
|
||||
supervisordTargetDir = "${stateDir}/lib/${instanceName}/conf.d";
|
||||
|
@ -23,4 +30,4 @@ in
|
|||
name = instanceName;
|
||||
inherit pkg type supervisordTargetDir;
|
||||
providesContainer = containerName;
|
||||
}
|
||||
} // properties
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
{mysqlConstructorFun, dysnomia, runtimeDir}:
|
||||
{port ? 3306, instanceSuffix ? "", instanceName ? "mysql${instanceSuffix}", containerName ? "mysql-database${instanceSuffix}", type}:
|
||||
|
||||
{ instanceSuffix ? "", instanceName ? "mysql${instanceSuffix}"
|
||||
, port ? 3306
|
||||
, containerName ? "mysql-database${instanceSuffix}"
|
||||
, type
|
||||
, properties ? {}
|
||||
}:
|
||||
|
||||
let
|
||||
# By default, the socket file resides in $runtimeDir/mysqld/mysqld.sock.
|
||||
|
@ -41,4 +47,4 @@ rec {
|
|||
inherit pkg type mysqlSocket mysqlUsername;
|
||||
|
||||
providesContainer = containerName;
|
||||
}
|
||||
} // properties
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
{postgresqlConstructorFun, dysnomia, runtimeDir}:
|
||||
|
||||
{ instanceSuffix ? "", instanceName ? "postgresql${instanceSuffix}"
|
||||
, containerName ? "postgresql-database${instanceSuffix}"
|
||||
, port ? 5432
|
||||
, type
|
||||
, properties ? {}
|
||||
}:
|
||||
|
||||
let
|
||||
username = instanceName;
|
||||
|
||||
pkg = postgresqlConstructorFun {
|
||||
inherit instanceName instanceSuffix port;
|
||||
postInstall = ''
|
||||
# Add Dysnomia container configuration file for PostgreSQL
|
||||
mkdir -p $out/etc/dysnomia/containers
|
||||
cat > $out/etc/dysnomia/containers/${containerName} <<EOF
|
||||
postgresqlPort=${toString port}
|
||||
postgresqlRuntimeDir=${runtimeDir}/${instanceName}
|
||||
postgresqlUsername=${username}
|
||||
EOF
|
||||
|
||||
# Copy the Dysnomia module that manages a PostgreSQL database
|
||||
mkdir -p $out/libexec/dysnomia
|
||||
ln -s ${dysnomia}/libexec/dysnomia/postgresql-database $out/libexec/dysnomia
|
||||
'';
|
||||
};
|
||||
in
|
||||
rec {
|
||||
name = instanceName;
|
||||
postgresqlPort = port;
|
||||
postgresqlUsername = username;
|
||||
|
||||
inherit pkg type;
|
||||
|
||||
providesContainer = containerName;
|
||||
} // properties
|
|
@ -1,5 +1,14 @@
|
|||
{tomcatConstructorFun, dysnomia, stateDir}:
|
||||
{instanceSuffix ? "", instanceName ? "tomcat${instanceSuffix}", containerName ? "tomcat-webapplication${instanceSuffix}", serverPort ? 8005, httpPort ? 8080, httpsPort ? 8443, ajpPort ? 8009, commonLibs ? [], type}:
|
||||
|
||||
{ instanceSuffix ? ""
|
||||
, instanceName ? "tomcat${instanceSuffix}"
|
||||
, containerName ? "tomcat-webapplication${instanceSuffix}"
|
||||
, serverPort ? 8005
|
||||
, httpPort ? 8080, httpsPort ? 8443, ajpPort ? 8009
|
||||
, commonLibs ? []
|
||||
, type
|
||||
, properties ? {}
|
||||
}:
|
||||
|
||||
let
|
||||
catalinaBaseDir = "${stateDir}/${instanceName}";
|
||||
|
@ -28,4 +37,4 @@ rec {
|
|||
tomcatPort = httpPort;
|
||||
|
||||
providesContainer = containerName;
|
||||
}
|
||||
} // properties
|
||||
|
|
|
@ -1,5 +1,18 @@
|
|||
{apacheConstructorFun, dysnomia, forceDisableUserChange}:
|
||||
{instanceSuffix ? "", instanceName ? "apache${instanceSuffix}", containerName ? "apache-webapplication${instanceSuffix}", port ? 80, modules ? [], serverName ? "localhost", serverAdmin, documentRoot ? ./webapp, extraConfig ? "", enableCGI ? false, enablePHP ? false, filesetOwner ? null, type}:
|
||||
|
||||
{ instanceSuffix ? "", instanceName ? "apache${instanceSuffix}"
|
||||
, containerName ? "apache-webapplication${instanceSuffix}"
|
||||
, port ? 80
|
||||
, modules ? [], serverName ? "localhost"
|
||||
, serverAdmin
|
||||
, documentRoot ? ./webapp
|
||||
, extraConfig ? ""
|
||||
, enableCGI ? false
|
||||
, enablePHP ? false
|
||||
, filesetOwner ? null
|
||||
, type
|
||||
, properties ? {}
|
||||
}:
|
||||
|
||||
let
|
||||
pkg = apacheConstructorFun {
|
||||
|
@ -24,4 +37,4 @@ in
|
|||
providesContainer = containerName;
|
||||
} // (if forceDisableUserChange || filesetOwner == null then {} else {
|
||||
inherit filesetOwner;
|
||||
})
|
||||
}) // properties
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{influxdbConstructorFun, dysnomia}:
|
||||
{instanceSuffix ? "", instanceName ? "influxdb${instanceSuffix}", containerName ? "influx-database${instanceSuffix}", rpcBindIP ? "127.0.0.1", rpcPort ? 8088, httpBindIP ? "", httpPort ? 8086, extraConfig ? "", type}:
|
||||
{instanceSuffix ? "", instanceName ? "influxdb${instanceSuffix}", containerName ? "influx-database${instanceSuffix}", rpcBindIP ? "127.0.0.1", rpcPort ? 8088, httpBindIP ? "", httpPort ? 8086, extraConfig ? "", type, properties ? {}}:
|
||||
|
||||
let
|
||||
pkg = influxdbConstructorFun {
|
||||
|
@ -21,4 +21,4 @@ rec {
|
|||
name = instanceName;
|
||||
inherit pkg type httpPort;
|
||||
providesContainer = containerName;
|
||||
}
|
||||
} // properties
|
||||
|
|
|
@ -1,5 +1,14 @@
|
|||
{mongodbConstructorFun, stdenv, dysnomia}:
|
||||
{instanceSuffix ? "", instanceName ? "mongodb${instanceSuffix}", containerName ? "mongo-database${instanceSuffix}", bindIP ? "127.0.0.1", port ? 27017, mongoDumpArgs ? null, mongoRestoreArgs ? null, type}:
|
||||
|
||||
{ instanceSuffix ? "", instanceName ? "mongodb${instanceSuffix}"
|
||||
, containerName ? "mongo-database${instanceSuffix}"
|
||||
, bindIP ? "127.0.0.1"
|
||||
, port ? 27017
|
||||
, mongoDumpArgs ? null
|
||||
, mongoRestoreArgs ? null
|
||||
, type
|
||||
, properties ? {}
|
||||
}:
|
||||
|
||||
let
|
||||
pkg = mongodbConstructorFun {
|
||||
|
@ -8,8 +17,9 @@ let
|
|||
# Add Dysnomia container configuration file for MongoDB
|
||||
mkdir -p $out/etc/dysnomia/containers
|
||||
cat > $out/etc/dysnomia/containers/${containerName} <<EOF
|
||||
${stdenv.lib.optionalString (mongoDumpArgs != null) (toString mongoDumpArgs)}"}
|
||||
${stdenv.lib.optionalString (mongoRestoreArgs != null) (toString mongoRestoreArgs)}"}
|
||||
mongoPort=${toString port}
|
||||
${stdenv.lib.optionalString (mongoDumpArgs != null) (toString mongoDumpArgs)}
|
||||
${stdenv.lib.optionalString (mongoRestoreArgs != null) (toString mongoRestoreArgs)}
|
||||
EOF
|
||||
|
||||
# Copy the Dysnomia module that manages a Mongo database
|
||||
|
@ -21,10 +31,10 @@ in
|
|||
{
|
||||
name = instanceName;
|
||||
inherit pkg type bindIP port;
|
||||
|
||||
mongoPort = port;
|
||||
providesContainer = containerName;
|
||||
} // (if mongoDumpArgs == null then {} else {
|
||||
inherit mongoDumpArgs;
|
||||
}) // (if mongoRestoreArgs == null then {} else {
|
||||
inherit mongoRestoreArgs;
|
||||
})
|
||||
}) // properties
|
||||
|
|
|
@ -1,5 +1,13 @@
|
|||
{svnserveConstructorFun, dysnomia}:
|
||||
{instanceSuffix ? "", instanceName ? "svnserve${instanceSuffix}", containerName ? "subversion-repository${instanceSuffix}", port ? 3690, svnBaseDir, svnGroup ? "root", type}:
|
||||
|
||||
{ instanceSuffix ? "", instanceName ? "svnserve${instanceSuffix}"
|
||||
, containerName ? "subversion-repository${instanceSuffix}"
|
||||
, port ? 3690
|
||||
, svnBaseDir
|
||||
, svnGroup ? "root"
|
||||
, type
|
||||
, properties ? {}
|
||||
}:
|
||||
|
||||
let
|
||||
pkg = svnserveConstructorFun {
|
||||
|
@ -22,4 +30,4 @@ in
|
|||
name = instanceName;
|
||||
inherit pkg type svnGroup svnBaseDir;
|
||||
providesContainer = containerName;
|
||||
}
|
||||
} // properties
|
||||
|
|
|
@ -32,7 +32,7 @@ in
|
|||
|
||||
postgresql = import ./postgresql.nix {
|
||||
inherit createManagedProcess stateDir runtimeDir forceDisableUserChange;
|
||||
inherit (pkgs) stdenv postgresql;
|
||||
inherit (pkgs) stdenv postgresql su;
|
||||
};
|
||||
|
||||
tomcat = import ./tomcat.nix {
|
||||
|
|
|
@ -1,15 +1,18 @@
|
|||
{createManagedProcess, stdenv, postgresql, stateDir, runtimeDir, forceDisableUserChange}:
|
||||
{port ? 5432, instanceSuffix ? "", instanceName ? "postgresql${instanceSuffix}"}:
|
||||
{createManagedProcess, stdenv, postgresql, su, stateDir, runtimeDir, forceDisableUserChange}:
|
||||
{port ? 5432, instanceSuffix ? "", instanceName ? "postgresql${instanceSuffix}", postInstall ? ""}:
|
||||
|
||||
let
|
||||
dataDir = "${stateDir}/db/${instanceName}/data";
|
||||
postgresqlStateDir = "${stateDir}/db/${instanceName}";
|
||||
dataDir = "${postgresqlStateDir}/data";
|
||||
socketDir = "${runtimeDir}/${instanceName}";
|
||||
|
||||
user = instanceName;
|
||||
group = instanceName;
|
||||
in
|
||||
createManagedProcess rec {
|
||||
name = instanceName;
|
||||
inherit instanceName user;
|
||||
inherit instanceName user postInstall;
|
||||
path = [ postgresql su ];
|
||||
initialize = ''
|
||||
mkdir -m0700 -p ${socketDir}
|
||||
mkdir -m0700 -p ${dataDir}
|
||||
|
@ -21,7 +24,7 @@ createManagedProcess rec {
|
|||
|
||||
if [ ! -e "${dataDir}/PG_VERSION" ]
|
||||
then
|
||||
${postgresql}/bin/initdb -D ${dataDir} --no-locale
|
||||
${stdenv.lib.optionalString (!forceDisableUserChange) "su ${user} -c '"}${postgresql}/bin/initdb -D ${dataDir} --no-locale${stdenv.lib.optionalString (!forceDisableUserChange) "'"}
|
||||
fi
|
||||
'';
|
||||
|
||||
|
@ -34,6 +37,8 @@ createManagedProcess rec {
|
|||
};
|
||||
users = {
|
||||
"${user}" = {
|
||||
homeDir = postgresqlStateDir;
|
||||
createHomeDir = true;
|
||||
inherit group;
|
||||
description = "PostgreSQL user";
|
||||
};
|
||||
|
@ -48,6 +53,7 @@ createManagedProcess rec {
|
|||
activity = "Starting";
|
||||
instruction = ''
|
||||
${initialize}
|
||||
|
||||
${postgresql}/bin/pg_ctl -D ${dataDir} -o "-p ${toString port} -k ${socketDir}" start
|
||||
'';
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue