]> git.proxmox.com Git - pmg-api.git/blame - bin/pmg-hourly
pmg-hourly: cleanup statistic database
[pmg-api.git] / bin / pmg-hourly
CommitLineData
6a672919
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;
9
10use PVE::SafeSyslog;
11use PVE::INotify;
12use PVE::RESTEnvironment;
13
14use PMG::Utils;
15use PMG::Config;
16use PMG::ClusterConfig;
17use PMG::LDAPSet;
3d511edd
DM
18use PMG::DBTools;
19use PMG::Statistic;
6a672919
DM
20
21$SIG{'__WARN__'} = sub {
22 my $err = $@;
23 my $t = $_[0];
24 chomp $t;
25 print STDERR "$t\n";
26 syslog('warning', "%s", $t);
27 $@ = $err;
28};
29
30PVE::RESTEnvironment->setup_default_cli_env();
31
461cb046 32initlog('pmg-hourly', 'mail');
6a672919
DM
33
34my $cfg = PMG::Config->new();
35
36my $demo = $cfg->get('admin', 'demo');
37
3d511edd 38my $cinfo = PMG::ClusterConfig->new();
6a672919
DM
39
40if ($demo) {
41 # fixme: generate fake statistics
42
43 return;
44}
3d511edd
DM
45
46if (my $statlifetime = $cfg->get ('admin', 'statlifetime')) {
47 my $count = 0;
48 eval {
49 my $dbh = PMG::DBTools::open_ruledb();
50 $count = PMG::Statistic::cleanup_stats($dbh, $statlifetime);
51 };
52 if (my $err = $@) {
53 syslog('err', $err);
54 } else {
55 syslog('info', "cleanup removed $count entries from statistic database") if $count;
56 }
57}
58
6a672919
DM
59PMG::Utils::service_cmd('pmgpolicy', 'restart');
60
61my $ldap_cfg = PVE::INotify::read_file("pmg-ldap.conf");
62PMG::LDAPSet::ldap_resync($ldap_cfg);
63
64# sync bayes journal to database
65system('sa-learn --sync >/dev/null 2>&1');
66
67# make sure clamav-daemon is running
68PMG::Utils::service_cmd('clamav-daemon', 'start');
69
70exit(0);
71