[Service] Environment=PGDATA=/srv/postgresql/postgresql Environment=PG_CONF=/etc/postgresql/postgresql.conf Environment=PG_HBA=/etc/postgresql/pg_hba.conf Environment=PG_IDENT=/etc/postgresql/pg_ident.conf Environment=LC_ALL=fr_FR.UTF-8 ExecStartPre= ExecStartPre=+/usr/local/lib/sbin/postgresql_init {# 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 -%} )' {# recheck db #} ExecStartPre=/usr/libexec/postgresql-check-db-dir %N 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 {# if lock do reindex #} 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'