summaryrefslogtreecommitdiff
path: root/scripts/vyatta-update-conntrack-log.pl
blob: 09ee0a52721008184d4b745daa3cb8424219b40d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/perl

use strict;
use lib "/opt/vyatta/share/perl5";
use Vyatta::Conntrack::Config;

my $pfile = '/var/run/vyatta/connlogd.lock';
my $lfile = '/var/run/vyatta/connlogd.log';

my $config = new Vyatta::Conntrack::Config;
my $oconfig = new Vyatta::Conntrack::Config;
$config->setup();
$oconfig->setupOrig();

if (!($config->isDifferentFrom($oconfig))) {
  if ($config->isEmpty()) {
    print STDERR "Empty Configuration\n";
    exit 1;
  }
  # config not changed. do nothing.
  exit 0;
}

if ($config->isEmpty()) {
  # delete the daemon process
  Vyatta::Conntrack::Config::kill_daemon();
  # delete the .lock and .log file getting generated
  `rm -f $pfile`;
  `rm -f $lfile`; 
   exit 0;
}

my $cmd = $config->get_command();
if ($cmd) {
  # First stop the daemon and restart with config 
  Vyatta::Conntrack::Config::kill_daemon();
  `rm -f $pfile`;
  `rm -f $lfile`; 
   system("$cmd");
   if ($? >> 8) {
     print STDERR "Failed to start conntrack logging daemon";
     exit 1;
   }
}

exit 0;