[pmg-devel] [PATCH pmg-api v2 3/3] adapt postgresql.conf template to variable version

Stoiko Ivanov s.ivanov at proxmox.com
Thu Aug 8 15:36:11 CEST 2019


pass the postgres major version in template_vars->{postgres}->{version} and
use that in the template. Additionally use the version for the config file
location.

The start and end tags are changed to '<*' and '*>' since the original
postgresql.conf contains an occurence of the default start tag '[%' which
would need to get escaped

Signed-off-by: Stoiko Ivanov <s.ivanov at proxmox.com>
---
 src/PMG/Config.pm                |  5 ++++-
 src/templates/postgresql.conf.in | 13 +++++++------
 2 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/src/PMG/Config.pm b/src/PMG/Config.pm
index 996d485..a62d9e4 100755
--- a/src/PMG/Config.pm
+++ b/src/PMG/Config.pm
@@ -661,6 +661,7 @@ use PVE::INotify;
 use PVE::JSONSchema;
 
 use PMG::Cluster;
+use PMG::Utils;
 
 PMG::Config::Admin->register();
 PMG::Config::Mail->register();
@@ -1263,6 +1264,7 @@ sub get_template_vars {
 	};
 	warn "parse http_proxy failed - $@" if $@;
     }
+    $vars->{postgres}->{version} = PMG::Utils::get_pg_server_version();
 
     return $vars;
 }
@@ -1399,7 +1401,8 @@ sub rewrite_config_freshclam {
 sub rewrite_config_postgres {
     my ($self) = @_;
 
-    my $pgconfdir = "/etc/postgresql/11/main";
+    my $pg_maj_version = PMG::Utils::get_pg_server_version();
+    my $pgconfdir = "/etc/postgresql/$pg_maj_version/main";
 
     my $changes = 0;
 
diff --git a/src/templates/postgresql.conf.in b/src/templates/postgresql.conf.in
index c13fe20..1dc6791 100644
--- a/src/templates/postgresql.conf.in
+++ b/src/templates/postgresql.conf.in
@@ -1,3 +1,4 @@
+[% TAGS <* *> -%]
 # -----------------------------
 # PostgreSQL configuration file
 # -----------------------------
@@ -38,15 +39,15 @@
 # The default values of these variables are driven from the -D command-line
 # option or PGDATA environment variable, represented here as ConfigDir.
 
-data_directory = '/var/lib/postgresql/11/main'		# use data in another directory
+data_directory = '/var/lib/postgresql/<* postgres.version *>/main'		# use data in another directory
 					# (change requires restart)
-hba_file = '/etc/postgresql/11/main/pg_hba.conf'	# host-based authentication file
+hba_file = '/etc/postgresql/<* postgres.version *>/main/pg_hba.conf'	# host-based authentication file
 					# (change requires restart)
-ident_file = '/etc/postgresql/11/main/pg_ident.conf'	# ident configuration file
+ident_file = '/etc/postgresql/<* postgres.version *>/main/pg_ident.conf'	# ident configuration file
 					# (change requires restart)
 
 # If external_pid_file is not explicitly set, no extra PID file is written.
-external_pid_file = '/var/run/postgresql/11-main.pid'			# write an extra PID file
+external_pid_file = '/var/run/postgresql/<* postgres.version *>-main.pid'			# write an extra PID file
 					# (change requires restart)
 
 
@@ -460,7 +461,7 @@ log_timezone = 'localtime'
 
 # - Process Title -
 
-cluster_name = '11/main'			# added to process titles if nonempty
+cluster_name = '<* postgres.version *>/main'			# added to process titles if nonempty
 					# (change requires restart)
 #update_process_title = on
 
@@ -476,7 +477,7 @@ cluster_name = '11/main'			# added to process titles if nonempty
 #track_io_timing = off
 #track_functions = none			# none, pl, all
 #track_activity_query_size = 1024	# (change requires restart)
-stats_temp_directory = '/var/run/postgresql/11-main.pg_stat_tmp'
+stats_temp_directory = '/var/run/postgresql/<* postgres.version *>-main.pg_stat_tmp'
 
 
 # - Statistics Monitoring -
-- 
2.20.1




More information about the pmg-devel mailing list