mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Tweak regenconf scripts for mysql, metronome, add one for postgresql
This commit is contained in:
parent
93f1ab2b34
commit
00bd7f16a5
5 changed files with 79 additions and 30 deletions
|
@ -292,34 +292,5 @@ ynh_psql_test_if_first_run() {
|
||||||
# Make sure postgresql is indeed installed
|
# Make sure postgresql is indeed installed
|
||||||
dpkg --list | grep -q "ii postgresql-$PSQL_VERSION" || ynh_die --message="postgresql-$PSQL_VERSION is not 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 ...
|
yunohost tools regen-conf postgresql
|
||||||
[ -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
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,12 @@
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
if ! dpkg --list | grep -q 'ii *metronome '
|
||||||
|
then
|
||||||
|
echo 'metronome is not installed, skipping'
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
do_pre_regen() {
|
do_pre_regen() {
|
||||||
pending_dir=$1
|
pending_dir=$1
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,12 @@
|
||||||
set -e
|
set -e
|
||||||
. /usr/share/yunohost/helpers
|
. /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() {
|
do_pre_regen() {
|
||||||
pending_dir=$1
|
pending_dir=$1
|
||||||
|
|
||||||
|
|
66
data/hooks/conf_regen/35-postgresql
Executable file
66
data/hooks/conf_regen/35-postgresql
Executable file
|
@ -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
|
Loading…
Add table
Reference in a new issue