|
| 1 | +# lint:ignore:140chars |
| 2 | +# @param service_ensure Ensure service is installed |
| 3 | +# @param service_enable Enable the PostgreSQL service |
| 4 | +# @param service_manage Defines whether or not Puppet should manage the service. |
| 5 | +# @param service_name Overrides the default PostgreSQL service name. |
| 6 | +# @param service_provider Overrides the default PostgreSQL service provider. |
| 7 | +# @param service_status Overrides the default status check command for your PostgreSQL service. |
| 8 | +# @param user Overrides the default PostgreSQL super user and owner of PostgreSQL related files in the file system. |
| 9 | +# @param port Specifies the port for the PostgreSQL server to listen on. Note: The same port number is used for all IP addresses the server listens on. Also, for Red Hat systems and early Debian systems, changing the port causes the server to come to a full stop before being able to make the change. |
| 10 | +# Default value: 5432. Meaning the Postgres server listens on TCP port 5432. |
| 11 | +# @param default_database Specifies the name of the default database to connect with. On most systems this is 'postgres'. |
| 12 | +# @param psql_path Specifies the path to the psql command. |
| 13 | +# @param default_connect_settings Specifies a hash of environment variables used when connecting to a remote server. Becomes the default for other defined types, such as postgresql::server::role. |
| 14 | +# lint:endignore:140chars |
| 15 | +define postgresql::server::instance_service ( |
| 16 | + $service_ensure = $postgresql::server::service_ensure, |
| 17 | + $service_enable = $postgresql::server::service_enable, |
| 18 | + $service_manage = $postgresql::server::service_manage, |
| 19 | + $service_name = $postgresql::server::service_name, |
| 20 | + $service_provider = $postgresql::server::service_provider, |
| 21 | + $service_status = $postgresql::server::service_status, |
| 22 | + $user = $postgresql::server::user, |
| 23 | + $port = $postgresql::server::port, |
| 24 | + $default_database = $postgresql::server::default_database, |
| 25 | + $psql_path = $postgresql::server::psql_path, |
| 26 | + $connect_settings = $postgresql::server::default_connect_settings, |
| 27 | +) { |
| 28 | + anchor { 'postgresql::server::service::begin': } |
| 29 | + |
| 30 | + if $service_manage { |
| 31 | + service { 'postgresqld': |
| 32 | + ensure => $service_ensure, |
| 33 | + enable => $service_enable, |
| 34 | + name => $service_name, |
| 35 | + provider => $service_provider, |
| 36 | + hasstatus => true, |
| 37 | + status => $service_status, |
| 38 | + } |
| 39 | + |
| 40 | + if $service_ensure in ['running', true] { |
| 41 | + # This blocks the class before continuing if chained correctly, making |
| 42 | + # sure the service really is 'up' before continuing. |
| 43 | + # |
| 44 | + # Without it, we may continue doing more work before the database is |
| 45 | + # prepared leading to a nasty race condition. |
| 46 | + postgresql_conn_validator { 'validate_service_is_running': |
| 47 | + run_as => $user, |
| 48 | + db_name => $default_database, |
| 49 | + port => $port, |
| 50 | + connect_settings => $connect_settings, |
| 51 | + sleep => 1, |
| 52 | + tries => 60, |
| 53 | + psql_path => $psql_path, |
| 54 | + require => Service['postgresqld'], |
| 55 | + before => Anchor['postgresql::server::service::end'], |
| 56 | + } |
| 57 | + Postgresql::Server::Database <| title == $default_database |> -> Postgresql_conn_validator['validate_service_is_running'] |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | + anchor { 'postgresql::server::service::end': } |
| 62 | +} |
0 commit comments