diff --git a/README.md b/README.md index d6c9c06..24ceeee 100644 --- a/README.md +++ b/README.md @@ -117,7 +117,17 @@ The script gets the version of PostgreSQL being installed as first argument. command ends the `initdb` phase, that happens only the `PGDATA` has not been initialized (i.e., on *very first `use`*). The return value of the script does not affect the `pgenv` workflow. The script gets the current `PGDATA` - path as first argument. + path as first argument. Please note that this script runs with the cluster + turned off. + +- `PGENV_SCRIPT_FIRSTSTART` is an executable script run at the very first of + a freshly installed cluster. Typically, this happens immediatly after the + `initdb` phase, after the cluster has been succesfully started. Please + note that this script is run only once in the whole cluster's life, that + means it will not run at every cluster start action, but only on the very first + start of the cluster. Therefore, this script can be used to initialize + the cluster with custmo data (e.g., creating users, databases, populating + tables and so on). - `PGENV_SCRIPT_POSTSTART` is an executable script executed each time an instances is started, that is `start` is executed. The return value of the diff --git a/bin/pgenv b/bin/pgenv index 272cc76..a8b2616 100755 --- a/bin/pgenv +++ b/bin/pgenv @@ -2,7 +2,7 @@ # # VERSION # -PGENV_VERSION="1.3.5" +PGENV_VERSION="1.3.6" # https://stackoverflow.com/a/19622569/79202 trap 'exit' ERR @@ -781,7 +781,8 @@ pgenv_configuration_write() { pgenv_configuration_write_variable "$CONF" "PGENV_RESTART_OPTIONS" "" 'Restart configuration flags' pgenv_configuration_write_variable "$CONF" "PGENV_SCRIPT_POSTINSTALL" "" 'Script to execute when the build process finishes' - pgenv_configuration_write_variable "$CONF" "PGENV_SCRIPT_POSTINITDB" "" 'Script to execute when initdb finishes' + pgenv_configuration_write_variable "$CONF" "PGENV_SCRIPT_POSTINITDB" "" 'Script to execute when initdb finishes (and the server has not started yet)' + pgenv_configuration_write_variable "$CONF" "PGENV_SCRIPT_FIRSTSTART" "" 'Script to execute at the very first start of the instance' pgenv_configuration_write_variable "$CONF" "PGENV_SCRIPT_PRESTOP" "" 'Script to execute before the cluster stops' pgenv_configuration_write_variable "$CONF" "PGENV_SCRIPT_POSTSTOP" "" 'Script to execute when the cluster has been stopped' pgenv_configuration_write_variable "$CONF" "PGENV_SCRIPT_POSTSTART" "" 'Script to execute when the cluster has been started' @@ -927,6 +928,7 @@ pgenv_start_instance(){ fi # Init the database if needed. + # the special variable PGENV_INITDB_DONE will be valued accordingly pgenv_initdb pgenv_debug "pg_ctl starting instance with flags [${PGENV_START_OPTIONS[@]}] log [$PGENV_LOG]" @@ -935,6 +937,22 @@ pgenv_start_instance(){ echo "PostgreSQL $v started" echo "Logging to $PGENV_LOG" + # if this is the first start, i.e., the start run + # just after the initialization, execute + # the appropriate custom script + if [ $PGENV_INITDB_DONE -eq 1 ]; then + if [ ! -z "$PGENV_SCRIPT_FIRSTSTART" -a -x "$PGENV_SCRIPT_FIRSTSTART" ]; then + cat <