]>
Commit | Line | Data |
---|---|---|
d0d5b944 DM |
1 | #!/usr/bin/perl -T |
2 | ||
3 | $ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin'; | |
4 | ||
5 | delete @ENV{qw(IFS CDPATH ENV BASH_ENV)}; | |
6 | ||
7 | use strict; | |
8 | use warnings; | |
9 | use Time::Local; | |
10 | ||
11 | use PVE::SafeSyslog; | |
12 | use PVE::INotify; | |
13 | use PVE::RESTEnvironment; | |
14 | ||
15 | use PMG::Utils; | |
16 | use PMG::Config; | |
17 | use PMG::ClusterConfig; | |
18 | use PMG::DBTools; | |
b2a65168 | 19 | use PMG::API2::Subscription; |
c7e9e145 | 20 | use 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 | ||
31 | PVE::RESTEnvironment->setup_default_cli_env(); | |
32 | ||
33 | initlog('pmg-daily', 'mail'); | |
34 | ||
b2a65168 DM |
35 | my $nodename = PVE::INotify::nodename(); |
36 | ||
37 | eval { PMG::API2::Subscription->update({ node => $nodename }); }; | |
38 | if (my $err = $@) { | |
39 | syslog ('err', "update subscription info failed: $err"); | |
40 | } | |
41 | ||
d0d5b944 DM |
42 | my $cfg = PMG::Config->new(); |
43 | ||
152ac93e DM |
44 | if (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. | |
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 }); }; | |
63 | if (my $err = $@) { | |
64 | syslog ('err', "update apt database failed: $err"); | |
65 | } | |
d0d5b944 DM |
66 | |
67 | # rotate razor log file | |
68 | rename('/root/.razor/razor-agent.log', '/root/.razor/razor-agent.log.0'); | |
69 | ||
85d295d6 DM |
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; | |
73 | } | |
74 | ||
7122424b DC |
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'); | |
80 | } | |
81 | ||
d0d5b944 DM |
82 | # run bayes database maintainance |
83 | system('sa-learn --force-expire >/dev/null 2>&1'); | |
84 | ||
85 | exit (0); | |
86 |