diff --git a/README.md b/README.md index b7219d0..bf45ea3 100644 --- a/README.md +++ b/README.md @@ -292,6 +292,9 @@ This setting can be used to override the default postgresql service provider. If ####`service_status` This setting can be used to override the default status check command for your PostgreSQL service. If not specified, the module will use whatever service name is the default for your OS distro. +####`default_database` +This setting is used to specify the name of the default database to connect with. On most systems this will be "postgres". + ####`inidb_path` Path to the `initdb` command. @@ -375,6 +378,9 @@ This setting can be used to override the default postgresql service provider. If ####`service_status` This setting can be used to override the default status check command for your PostgreSQL service. If not specified, the module will use whatever service name is the default for your OS distro. +####`default_database` +This setting is used to specify the name of the default database to connect with. On most systems this will be "postgres". + ####`listen_addresses` This value defaults to `localhost`, meaning the postgres server will only accept connections from localhost. If you'd like to be able to connect to postgres from remote machines, you can override this setting. A value of `*` will tell postgres to accept connections from any remote machine. Alternately, you can specify a comma-separated list of hostnames or IP addresses. (For more info, have a look at the `postgresql.conf` file from your system's postgres package). diff --git a/manifests/globals.pp b/manifests/globals.pp index e678b93..5bd1b09 100644 --- a/manifests/globals.pp +++ b/manifests/globals.pp @@ -14,6 +14,7 @@ class postgresql::globals ( $service_name = undef, $service_provider = undef, $service_status = undef, + $default_database = undef, $initdb_path = undef, $createdb_path = undef, diff --git a/manifests/params.pp b/manifests/params.pp index 315e80b..b619528 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -146,4 +146,5 @@ class postgresql::params inherits postgresql::globals { $pg_hba_conf_path = pick($pg_hba_conf_path, "${confdir}/pg_hba.conf") $pg_hba_conf_defaults = pick($pg_hba_conf_defaults, true) $postgresql_conf_path = pick($postgresql_conf_path, "${confdir}/postgresql.conf") + $default_database = pick($default_database, 'postgres') } diff --git a/manifests/server.pp b/manifests/server.pp index 864bb1f..eb71b3d 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -14,6 +14,7 @@ class postgresql::server ( $service_name = $postgresql::params::service_name, $service_provider = $postgresql::params::service_provider, $service_status = $postgresql::params::service_status, + $default_database = $postgresql::params::default_database, $listen_addresses = $postgresql::params::listen_addresses, $ip_mask_deny_postgres_user = $postgresql::params::ip_mask_deny_postgres_user, diff --git a/manifests/server/service.pp b/manifests/server/service.pp index 96adba4..1369bbc 100644 --- a/manifests/server/service.pp +++ b/manifests/server/service.pp @@ -5,6 +5,7 @@ class postgresql::server::service { $service_provider = $postgresql::server::service_provider $service_status = $postgresql::server::service_status $user = $postgresql::server::user + $default_database = $postgresql::server::default_database $service_ensure = $ensure ? { present => true, @@ -29,6 +30,7 @@ class postgresql::server::service { # prepared leading to a nasty race condition. postgresql::validate_db_connection { 'validate_service_is_running': run_as => $user, + database_name => $default_database, sleep => 1, tries => 60, create_db_first => false, diff --git a/manifests/validate_db_connection.pp b/manifests/validate_db_connection.pp index 09d6d17..f70af1e 100644 --- a/manifests/validate_db_connection.pp +++ b/manifests/validate_db_connection.pp @@ -5,7 +5,7 @@ # See README.md for more details. define postgresql::validate_db_connection( $database_host = undef, - $database_name = 'postgres', + $database_name = undef, $database_password = undef, $database_username = undef, $database_port = undef, @@ -15,25 +15,26 @@ define postgresql::validate_db_connection( $create_db_first = true ) { require postgresql::client + include postgresql::params $psql_path = $postgresql::params::psql_path $cmd_init = "${psql_path} --tuples-only --quiet " $cmd_host = $database_host ? { default => "-h ${database_host} ", - undef => "" + undef => "", } $cmd_user = $database_username ? { default => "-U ${database_username} ", - undef => "" + undef => "", } $cmd_port = $database_port ? { default => "-p ${database_port} ", - undef => "" + undef => "", } $cmd_dbname = $database_name ? { default => "--dbname ${database_name} ", - undef => "" + undef => "--dbname ${postgresql::params::default_database} ", } $env = $database_password ? { default => "PGPASSWORD=${database_password}",