Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#71] Add support for "run once" custom script #72

Merged
merged 1 commit into from
Apr 15, 2024

Conversation

fluca1978
Copy link
Collaborator

This commit introduces a new configuration parameter PGENV_SCRIPT_FIRSTSTART that can be pointed to an executable that is run once and only once at the very first start of the selected instance.
Therefore, the usage of this script enables for customization of the instance, like for example adding new users and databases.

The changes are made directly into the pgenv_start_instance function, that is the entry point to a start action: the function in turns calls pgenv_initdb that performs the initialization of the instace. If the initialization is done, a new magic variable PGENV_INITDB_DONE is set to 1, so that pgenv_start_instance can then decide to execute the script mentioned above.

Therefore, the trick here is to mark a "first start" time as the one that immediatly follows the initdb phase.

Close #71

Copy link
Owner

@theory theory left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a couple corrections, otherwise works great for me! I will use this, in fact. Here's my script:

#!/bin/sh

createuser -sU postgres
createdb

bin/pgenv Outdated
cat <<EOF
This is the first time PostgreSQL $v is started,
executing the \`PGENV_SCRIPT_FIRSTSTART\` script
$PGENV_SCRIPT_FIRSTSTART"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No opening quotation mark here. Should it be this?

Suggested change
$PGENV_SCRIPT_FIRSTSTART"
"$PGENV_SCRIPT_FIRSTSTART"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FIXED

bin/pgenv Outdated
@@ -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_FIRSTART" "" 'Script to execute at the very first start of the instance'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pgenv_configuration_write_variable "$CONF" "PGENV_SCRIPT_FIRSTART" "" 'Script to execute at the very first start of the instance'
pgenv_configuration_write_variable "$CONF" "PGENV_SCRIPT_FIRSTSTART" "" 'Script to execute at the very first start of the instance'

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shame on me, I was testing without having noted the configuration file produced did have the misspelled word!

This commit introduces a new configuration parameter
`PGENV_SCRIPT_FIRSTSTART` that can be pointed to an executable that is
run once and only once at the very first start of the selected
instance.
Therefore, the usage of this script enables for customization of the
instance, like for example adding new users and databases.

The changes are made directly into the `pgenv_start_instance`
function, that is the entry point to a start action: the function in
turns calls `pgenv_initdb` that performs the initialization of the
instace. If the initialization is done, a new magic variable
`PGENV_INITDB_DONE` is set to `1`, so that `pgenv_start_instance` can
then decide to execute the script mentioned above.

Therefore, the trick here is to mark a "first start" time as the one
that immediatly follows the initdb phase.

Documentation updated.
Version number bumped.

Close theory#71
@fluca1978 fluca1978 force-pushed the custom_installation_script branch from 007cf84 to 8d2c963 Compare April 15, 2024 06:41
@fluca1978 fluca1978 merged commit 1ef512b into theory:master Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for a custom post-installation script to be run once
2 participants