summaryrefslogtreecommitdiff
path: root/scripts/system/vyatta_update_logrotate.pl
blob: 27405263a6be01f35ec49a4a31244fb3377f3e6d (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
47
48
49
50
51
52
53
54
55
#!/usr/bin/perl

use strict;

my $file = "messages";
my $log_file = "/var/log/messages";
if ($#ARGV == 3) {
  $file = shift;
  $log_file = "/var/log/user/$file";
}
my $files = shift;
my $size = shift;
my $set = shift;
my $log_conf = "/etc/logrotate.d/$file";

if (!defined($files) || !defined($size) || !defined($set)) {
  exit 1;
}

if (!($files =~ m/^\d+$/) || !($size =~ m/^\d+$/)) {
  exit 2;
}

# just remove it and make a new one below
# (the detection mechanism in XORP doesn't work anyway)
unlink $log_conf;

open(OUT, ">>$log_conf") or exit 3;
if ($set == 1) {
  print OUT <<EOF;
$log_file {
  missingok
  notifempty
  rotate $files
  size=${size}k
  postrotate
  kill -HUP `cat /var/run/syslogd.pid`
  endscript
}
EOF
}
close OUT;

sleep 1;
# XXX somehow starting syslogd with 'start-stop-daemon --start...' here fails
# with SEGV (?). just start syslogd directly.
#if (system("/opt/vyatta/sbin/sysklogd.init restart")) {
system("/opt/vyatta/sbin/sysklogd.init stop");
sleep 1;
if (system(". /etc/default/syslogd ; /sbin/syslogd \$SYSLOGD")) {
  exit 4;
}

exit 0;