]> git.proxmox.com Git - pmg-api.git/commitdiff
move postgres_admin_command into PMG::Utils
authorStoiko Ivanov <s.ivanov@proxmox.com>
Thu, 8 Aug 2019 13:36:09 +0000 (15:36 +0200)
committerFabian Grünbichler <f.gruenbichler@proxmox.com>
Fri, 9 Aug 2019 06:45:05 +0000 (08:45 +0200)
Take postgres_admin_command from PMG::DBTools and put it in PMG::Utils.
This avoids a cyclic dependency (PMG::DBTools calls
PMG::Config::rewrite_postfix_whitelist when reloading the RuleDB, and
PMG::Config needs access to the Postgres major version for rendering
the postgresql.conf)

Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
src/PMG/Backup.pm
src/PMG/DBTools.pm
src/PMG/Utils.pm

index 9114d2bcacce07ccf574c8f8511af9f098f04362..11eff5f79e5e42178508b2a8794e3b721b028798 100644 (file)
@@ -10,6 +10,7 @@ use PVE::Tools;
 
 use PMG::pmgcfg;
 use PMG::AtomicFile;
+use PMG::Utils qw(postgres_admin_cmd);
 
 my $sa_custom_config_fn = "/etc/mail/spamassassin/custom.cf";
 
@@ -286,7 +287,7 @@ sub pmg_restore {
            }
 
            print STDERR "run analyze to speed up database queries\n";
-           PMG::DBTools::postgres_admin_cmd('psql', { input => 'analyze;' }, $dbname);
+           postgres_admin_cmd('psql', { input => 'analyze;' }, $dbname);
 
            print "Analyzing/Upgrading existing Databases...";
            my $ruledb = PMG::RuleDB->new($dbh);
index a01f07c3970dbade8761011e45c96c551d529497..c675e2f055e39b28299fa8cb1f91421bd60de919 100644 (file)
@@ -15,6 +15,7 @@ use PMG::Utils;
 use PMG::RuleDB;
 use PMG::MailQueue;
 use PMG::Config;
+use PMG::Utils qw(postgres_admin_cmd);
 
 our $default_db_name = "Proxmox_ruledb";
 
@@ -76,23 +77,6 @@ sub open_ruledb {
     }
 }
 
-sub postgres_admin_cmd {
-    my ($cmd, $options, @params) = @_;
-
-    $cmd = ref($cmd) ? $cmd : [ $cmd ];
-
-    my $save_uid = POSIX::getuid();
-    my $pg_uid = getpwnam('postgres') || die "getpwnam postgres failed\n";
-
-    PVE::Tools::setresuid(-1, $pg_uid, -1) ||
-       die "setresuid postgres ($pg_uid) failed - $!\n";
-
-    PVE::Tools::run_command([@$cmd, '-U', 'postgres', @params], %$options);
-
-    PVE::Tools::setresuid(-1, $save_uid, -1) ||
-       die "setresuid back failed - $!\n";
-}
-
 sub delete_ruledb {
     my ($dbname) = @_;
 
index aa6aac770ad77d29b9bba0a3fe54f62cab1bbed9..7606a89b774b20b687753a25a4b8d62889dd376d 100644 (file)
@@ -37,6 +37,12 @@ use PMG::AtomicFile;
 use PMG::MailQueue;
 use PMG::SMTPPrinter;
 
+use base 'Exporter';
+
+our @EXPORT_OK = qw(
+postgres_admin_cmd
+);
+
 my $valid_pmg_realms = ['pam', 'pmg', 'quarantine'];
 
 PVE::JSONSchema::register_standard_option('realm', {
@@ -1378,4 +1384,21 @@ sub cond_add_default_locale {
     system("dpkg-reconfigure locales -f noninteractive");
 }
 
+sub postgres_admin_cmd {
+    my ($cmd, $options, @params) = @_;
+
+    $cmd = ref($cmd) ? $cmd : [ $cmd ];
+
+    my $save_uid = POSIX::getuid();
+    my $pg_uid = getpwnam('postgres') || die "getpwnam postgres failed\n";
+
+    PVE::Tools::setresuid(-1, $pg_uid, -1) ||
+       die "setresuid postgres ($pg_uid) failed - $!\n";
+
+    PVE::Tools::run_command([@$cmd, '-U', 'postgres', @params], %$options);
+
+    PVE::Tools::setresuid(-1, $save_uid, -1) ||
+       die "setresuid back failed - $!\n";
+}
+
 1;