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

Stoiko Ivanov s.ivanov at proxmox.com
Thu Aug 8 09:14:02 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

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

diff --git a/src/PMG/Config.pm b/src/PMG/Config.pm
index 996d485..c78ad0e 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 qw(get_pg_server_version);
 
 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} = 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 = get_pg_server_version();
+    my $pgconfdir = "/etc/postgresql/$pg_maj_version/main";
 
     my $changes = 0;
 
diff --git a/src/PMG/Utils.pm b/src/PMG/Utils.pm
index a773f9d..b47445f 100644
--- a/src/PMG/Utils.pm
+++ b/src/PMG/Utils.pm
@@ -40,8 +40,8 @@ use PMG::SMTPPrinter;
 use base 'Exporter';
 
 our @EXPORT_OK = qw(
-postgres_admin_cmd,
-get_pg_server_version,
+postgres_admin_cmd
+get_pg_server_version
 );
 
 my $valid_pmg_realms = ['pam', 'pmg', 'quarantine'];
diff --git a/src/templates/postgresql.conf.in b/src/templates/postgresql.conf.in
index c13fe20..294d89c 100644
--- a/src/templates/postgresql.conf.in
+++ b/src/templates/postgresql.conf.in
@@ -38,15 +38,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)
 
 
@@ -428,7 +428,7 @@ dynamic_shared_memory_type = posix	# the default is the first option
 #log_duration = off
 #log_error_verbosity = default		# terse, default, or verbose messages
 #log_hostname = off
-log_line_prefix = '%m [%p] %q%u@%d '			# special values:
+log_line_prefix = '%m [% "[%" %]p] %q%u@%d '			# special values:
 					#   %a = application name
 					#   %u = user name
 					#   %d = database name
@@ -460,7 +460,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 +476,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