]>
git.proxmox.com Git - pmg-api.git/blob - src/bin/pmg-daily
3 $ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin';
5 delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
13 use PVE
::RESTEnvironment
;
17 use PMG
::ClusterConfig
;
19 use PMG
::API2
::Subscription
;
22 $SIG{'__WARN__'} = sub {
27 syslog
('warning', "%s", $t);
31 PVE
::RESTEnvironment-
>setup_default_cli_env();
33 initlog
('pmg-daily', 'mail');
35 my $nodename = PVE
::INotify
::nodename
();
37 eval { PMG
::API2
::Subscription-
>update({ node
=> $nodename }); };
39 syslog
('err', "update subscription info failed: $err");
42 my $cfg = PMG
::Config-
>new();
44 if (my $statlifetime = $cfg->get ('admin', 'statlifetime')) {
47 my $dbh = PMG
::DBTools
::open_ruledb
();
48 $count = PMG
::DBTools
::purge_statistic_database
($dbh, $statlifetime);
53 syslog
('info', "cleanup removed $count entries from statistic database") if $count;
57 # check for available updates
58 # We assume that users with subscriptions want informations
60 my $info = PVE
::INotify
::read_file
('subscription');
61 my $notify = ($info && $info->{status
} eq 'Active') ?
1 : 0;
62 eval { PMG
::API2
::APT-
>update_database({ node
=> $nodename, notify
=> $notify, quiet
=> 1 }); };
64 syslog
('err', "update apt database failed: $err");
67 # rotate razor log file
68 rename('/root/.razor/razor-agent.log', '/root/.razor/razor-agent.log.0');
70 # setup proxy env (assume sa-update use http)
71 if (my $http_proxy = $cfg->get('admin', 'http_proxy')) {
72 $ENV{http_proxy
} = $http_proxy;
75 # update spamassassin rules
76 if (system('sa-update') == 0) {
77 # if the exit code is 0, new updates were downloaded
78 # then restart the pmg-smtp-filter to load the new rules
79 PMG
::Utils
::service_cmd
('pmg-smtp-filter', 'restart');
82 # run bayes database maintainance
83 system('sa-learn --force-expire >/dev/null 2>&1');