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>
use PMG::pmgcfg;
use PMG::AtomicFile;
+use PMG::Utils qw(postgres_admin_cmd);
my $sa_custom_config_fn = "/etc/mail/spamassassin/custom.cf";
}
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);
use PMG::RuleDB;
use PMG::MailQueue;
use PMG::Config;
+use PMG::Utils qw(postgres_admin_cmd);
our $default_db_name = "Proxmox_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) = @_;
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', {
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;