diff --git a/data/helpers.d/postgresql b/data/helpers.d/postgresql index 992474dd5..0e8d91936 100644 --- a/data/helpers.d/postgresql +++ b/data/helpers.d/postgresql @@ -292,34 +292,5 @@ ynh_psql_test_if_first_run() { # Make sure postgresql is indeed installed dpkg --list | grep -q "ii postgresql-$PSQL_VERSION" || ynh_die --message="postgresql-$PSQL_VERSION is not installed !?" - # Check for some weird issue where postgresql could be installed but etc folder would not exist ... - [ -e "/etc/postgresql/$PSQL_VERSION" ] || ynh_die --message="It looks like postgresql was not properly configured ? /etc/postgresql/$PSQL_VERSION is missing ... Could be due to a locale issue, c.f.https://serverfault.com/questions/426989/postgresql-etc-postgresql-doesnt-exist" - - # Make sure postgresql is started and enabled - # (N.B. : to check the active state, we check the cluster state because - # postgresql could be flagged as active even though the cluster is in - # failed state because of how the service is configured..) - systemctl is-active postgresql@$PSQL_VERSION-main -q || ynh_systemd_action --service_name=postgresql --action=restart - systemctl is-enabled postgresql -q || systemctl enable postgresql --quiet - - # If this is the very first time, we define the root password - # and configure a few things - if [ ! -f "$PSQL_ROOT_PWD_FILE" ]; then - local pg_hba=/etc/postgresql/$PSQL_VERSION/main/pg_hba.conf - - local psql_root_password="$(ynh_string_random)" - echo "$psql_root_password" >$PSQL_ROOT_PWD_FILE - sudo --login --user=postgres psql -c"ALTER user postgres WITH PASSWORD '$psql_root_password'" postgres - - # force all user to connect to local databases using hashed passwords - # https://www.postgresql.org/docs/current/static/auth-pg-hba-conf.html#EXAMPLE-PG-HBA.CONF - # Note: we can't use peer since YunoHost create users with nologin - # See: https://github.com/YunoHost/yunohost/blob/unstable/data/helpers.d/user - ynh_replace_string --match_string="local\(\s*\)all\(\s*\)all\(\s*\)peer" --replace_string="local\1all\2all\3md5" --target_file="$pg_hba" - - # Integrate postgresql service in yunohost - yunohost service add postgresql --log "/var/log/postgresql/" - - ynh_systemd_action --service_name=postgresql --action=reload - fi + yunohost tools regen-conf postgresql } diff --git a/data/hooks/conf_regen/12-metronome b/data/hooks/conf_regen/12-metronome index 5dfa7b5dc..c3c5ff828 100755 --- a/data/hooks/conf_regen/12-metronome +++ b/data/hooks/conf_regen/12-metronome @@ -2,6 +2,12 @@ set -e +if ! dpkg --list | grep -q 'ii *metronome ' +then + echo 'metronome is not installed, skipping' + exit 0 +fi + do_pre_regen() { pending_dir=$1 diff --git a/data/hooks/conf_regen/34-mysql b/data/hooks/conf_regen/34-mysql index 8b4d59288..c9115017d 100755 --- a/data/hooks/conf_regen/34-mysql +++ b/data/hooks/conf_regen/34-mysql @@ -3,6 +3,12 @@ set -e . /usr/share/yunohost/helpers +if ! dpkg --list | grep -q 'ii *mariadb-server ' +then + echo 'mysql/mariadb is not installed, skipping' + exit 0 +fi + do_pre_regen() { pending_dir=$1 diff --git a/data/hooks/conf_regen/35-postgresql b/data/hooks/conf_regen/35-postgresql new file mode 100755 index 000000000..0da0767cc --- /dev/null +++ b/data/hooks/conf_regen/35-postgresql @@ -0,0 +1,66 @@ +#!/bin/bash + +set -e +. /usr/share/yunohost/helpers + +if ! dpkg --list | grep -q "ii *postgresql-$PSQL_VERSION " +then + echo 'postgresql is not installed, skipping' + exit 0 +fi + +if [ ! -e "/etc/postgresql/$PSQL_VERSION" ] +then + ynh_die --message="It looks like postgresql was not properly configured ? /etc/postgresql/$PSQL_VERSION is missing ... Could be due to a locale issue, c.f.https://serverfault.com/questions/426989/postgresql-etc-postgresql-doesnt-exist" +fi + + +do_pre_regen() { + return 0 +} + +do_post_regen() { + regen_conf_files=$1 + + # Make sure postgresql is started and enabled + # (N.B. : to check the active state, we check the cluster state because + # postgresql could be flagged as active even though the cluster is in + # failed state because of how the service is configured..) + systemctl is-active postgresql@$PSQL_VERSION-main -q || ynh_systemd_action --service_name=postgresql --action=restart + systemctl is-enabled postgresql -q || systemctl enable postgresql --quiet + + # If this is the very first time, we define the root password + # and configure a few things + if [ ! -f "$PSQL_ROOT_PWD_FILE" ] || [ -z "$(cat $PSQL_ROOT_PWD_FILE)" ]; then + ynh_string_random >$PSQL_ROOT_PWD_FILE + fi + + sudo --login --user=postgres psql -c"ALTER user postgres WITH PASSWORD '$(cat $PSQL_ROOT_PWD_FILE)'" postgres + + # force all user to connect to local databases using hashed passwords + # https://www.postgresql.org/docs/current/static/auth-pg-hba-conf.html#EXAMPLE-PG-HBA.CONF + # Note: we can't use peer since YunoHost create users with nologin + # See: https://github.com/YunoHost/yunohost/blob/unstable/data/helpers.d/user + local pg_hba=/etc/postgresql/$PSQL_VERSION/main/pg_hba.conf + ynh_replace_string --match_string="local\(\s*\)all\(\s*\)all\(\s*\)peer" --replace_string="local\1all\2all\3md5" --target_file="$pg_hba" + + ynh_systemd_action --service_name=postgresql --action=reload +} + +FORCE=${2:-0} +DRY_RUN=${3:-0} + +case "$1" in + pre) + do_pre_regen $4 + ;; + post) + do_post_regen $4 + ;; + *) + echo "hook called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac + +exit 0 diff --git a/data/hooks/conf_regen/35-redis b/data/hooks/conf_regen/36-redis similarity index 100% rename from data/hooks/conf_regen/35-redis rename to data/hooks/conf_regen/36-redis