]> git.proxmox.com Git - pmg-api.git/blame - bin/pmg-daily
close #1917: add pmg-system-report command
[pmg-api.git] / bin / pmg-daily
CommitLineData
d0d5b944
DM
1#!/usr/bin/perl -T
2
3$ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin';
4
5delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
6
7use strict;
8use warnings;
9use Time::Local;
10
11use PVE::SafeSyslog;
12use PVE::INotify;
13use PVE::RESTEnvironment;
14
15use PMG::Utils;
16use PMG::Config;
17use PMG::ClusterConfig;
18use PMG::DBTools;
b2a65168 19use PMG::API2::Subscription;
c7e9e145 20use PMG::API2::APT;
d0d5b944
DM
21
22$SIG{'__WARN__'} = sub {
23 my $err = $@;
24 my $t = $_[0];
25 chomp $t;
26 print STDERR "$t\n";
27 syslog('warning', "%s", $t);
28 $@ = $err;
29};
30
31PVE::RESTEnvironment->setup_default_cli_env();
32
33initlog('pmg-daily', 'mail');
34
b2a65168
DM
35my $nodename = PVE::INotify::nodename();
36
37eval { PMG::API2::Subscription->update({ node => $nodename }); };
38if (my $err = $@) {
39 syslog ('err', "update subscription info failed: $err");
40}
41
d0d5b944
DM
42my $cfg = PMG::Config->new();
43
152ac93e
DM
44if (my $statlifetime = $cfg->get ('admin', 'statlifetime')) {
45 my $count = 0;
d0d5b944
DM
46 eval {
47 my $dbh = PMG::DBTools::open_ruledb();
8fb6f404 48 $count = PMG::DBTools::purge_statistic_database($dbh, $statlifetime);
d0d5b944
DM
49 };
50 if (my $err = $@) {
b902c0b8 51 syslog('err', $err);
d0d5b944 52 } else {
152ac93e 53 syslog('info', "cleanup removed $count entries from statistic database") if $count;
d0d5b944 54 }
d0d5b944
DM
55}
56
c7e9e145
DM
57# check for available updates
58# We assume that users with subscriptions want informations
59# about new packages.
60my $info = PVE::INotify::read_file('subscription');
61my $notify = ($info && $info->{status} eq 'Active') ? 1 : 0;
62eval { PMG::API2::APT->update_database({ node => $nodename, notify => $notify, quiet => 1 }); };
63if (my $err = $@) {
64 syslog ('err', "update apt database failed: $err");
65}
d0d5b944
DM
66
67# rotate razor log file
68rename('/root/.razor/razor-agent.log', '/root/.razor/razor-agent.log.0');
69
85d295d6
DM
70# setup proxy env (assume sa-update use http)
71if (my $http_proxy = $cfg->get('admin', 'http_proxy')) {
72 $ENV{http_proxy} = $http_proxy;
73}
74
7122424b
DC
75# update spamassassin rules
76if (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');
80}
81
d0d5b944
DM
82# run bayes database maintainance
83system('sa-learn --force-expire >/dev/null 2>&1');
84
85exit (0);
86