2022-03-08 19:42:28 +01:00
|
|
|
[Service]
|
2022-07-18 17:06:12 +02:00
|
|
|
Environment=PGDATA=/srv/postgresql/postgresql
|
2022-03-08 19:42:28 +01:00
|
|
|
Environment=PG_CONF=/etc/postgresql/postgresql.conf
|
|
|
|
Environment=PG_HBA=/etc/postgresql/pg_hba.conf
|
|
|
|
Environment=PG_IDENT=/etc/postgresql/pg_ident.conf
|
2022-07-18 17:06:12 +02:00
|
|
|
Environment=LC_ALL=fr_FR.UTF-8
|
|
|
|
ExecStartPre=
|
2022-08-18 10:19:43 +02:00
|
|
|
ExecStartPre=+/usr/local/lib/sbin/postgresql_init
|
2023-06-23 08:12:05 +02:00
|
|
|
{# if upgrade needed, do it #}
|
|
|
|
ExecStartPre=/bin/bash -c '{% if True -%}{% endif -%}
|
|
|
|
/usr/libexec/postgresql-check-db-dir %N || ({% if True -%}{% endif -%}
|
|
|
|
echo "UPGRADE" &&{% if True -%}{% endif -%}
|
|
|
|
{# directory creation must have 700 rights #}
|
|
|
|
umask 0077 &&{% if True -%}{% endif -%}
|
|
|
|
{# pg_upgrade do not like ssl activation #}
|
|
|
|
/bin/grep -v "ssl " ${PG_CONF} > /tmp/postgresql.conf &&{% if True -%}{% endif -%}
|
|
|
|
mv -f /tmp/postgresql.conf ${PGDATA}/postgresql.conf &&{% if True -%}{% endif -%}
|
|
|
|
{# pg_upgrade modify pg_hba.conf so copy it #}
|
|
|
|
/bin/rm ${PGDATA}/pg_hba.conf &&{% if True -%}{% endif -%}
|
|
|
|
/bin/cp -af ${PG_HBA} ${PGDATA} &&{% if True -%}{% endif -%}
|
|
|
|
{# do upgrade #}
|
|
|
|
/usr/bin/postgresql-setup --upgrade &&{% if True -%}{% endif -%}
|
|
|
|
{# re do link #}
|
|
|
|
ln -sf ${PG_HBA} ${PGDATA}/ &&{% if True -%}{% endif -%}
|
|
|
|
ln -sf ${PG_CONF} ${PGDATA}/ &&{% if True -%}{% endif -%}
|
|
|
|
{# remove old cluster #}
|
|
|
|
/srv/postgresql/postgresql/delete_old_cluster.sh &&{% if True -%}{% endif -%}
|
|
|
|
rm -f /srv/postgresql/postgresql/delete_old_cluster.sh &&{% if True -%}{% endif -%}
|
|
|
|
{# force index (see later) #}
|
|
|
|
touch /srv/postgresql/risotto_upgrade.lock{% if True -%}{% endif -%}
|
2022-07-18 17:06:12 +02:00
|
|
|
)'
|
2023-06-23 08:12:05 +02:00
|
|
|
{# recheck db #}
|
2022-07-18 17:06:12 +02:00
|
|
|
ExecStartPre=/usr/libexec/postgresql-check-db-dir %N
|
2022-03-08 19:42:28 +01:00
|
|
|
ExecStart=
|
|
|
|
ExecStart=/usr/bin/postmaster -D ${PGDATA} -c config_file=${PG_CONF} -c hba_file=${PG_HBA} -c ident_file=${PG_IDENT}
|
|
|
|
ExecStartPost=-/usr/bin/psql -f /etc/postgresql/postgresql.sql
|
2023-06-23 08:12:05 +02:00
|
|
|
{# if lock do reindex #}
|
2022-07-18 17:06:12 +02:00
|
|
|
ExecStartPost=/bin/bash -c 'if [ -f /srv/postgresql/risotto_upgrade.lock ];then echo REINDEX; /usr/bin/reindexdb && rm -f /srv/postgresql/risotto_upgrade.lock; fi'
|