Reuse the existing PostgreSQL resources for Patroni bootstrap
The initial implementation of Patroni in !3984 (merged) rewrites the post-initialization of PostgreSQL in a shell script and runs it as the post-bootstrap task. This "post-initialization" includes database object creation, such as database roles, extensions, and functions. The operations for creating or updating these database objects is already part of postgresql::enable
recipe which are skipped when Patroni is enabled.
These operations need to run against a running database instance which with Patroni can not happen until after bootstrapping. The problem is that Patroni's post-bootstrap script will run with the default PostgreSQL user, e.g. gitlab-psql
, while the database operations require access to gitlab.rb
settings, for example password hashes, which require root privilege. The workaround was to generate a shell script and fill it with the required information during reconfigure
and run it as post-bootstrap.
This workaround creates a redundancy and requires maintaining the post-initialization of PostgreSQL in two separate places with two different methods. Ideally we should be able to use the existing resources in postgresql::enable
recipe.
The gist of the solution is to factor out these resource from postgresql::enable
into a separate recipe and include it in patroni::enable
with a retry limit. So when Patroni service starts it bootstraps PostgreSQL and the recipe waits until it is running. The it initiates the post-initialization using the same resources. This can be implemented with setting retry number and timeout on resources.
For the disscussion on this issue see !3984 (comment 353201388)