Skip to content

Commit

Permalink
Merge pull request #300 from mariux64/shrink-netlog
Browse files Browse the repository at this point in the history
netlog: Remove daemon features
  • Loading branch information
donald authored Jan 20, 2023
2 parents 8af7127 + 4f97485 commit 8ed0e29
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 46 deletions.
43 changes: 1 addition & 42 deletions netlog/netlog
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
use warnings;
use strict;

use Donald::Tools;
use Donald::Select;
use IO::Socket;
use Getopt::Long;
use Sys::Syslog;
use Donald::Select::Watchfile;

our ($RCS_REVISION)='$Revision: 1.36 $'=~/([\d.]+)/;

Expand Down Expand Up @@ -325,28 +322,17 @@ sub do_syslog {
sub USAGE {
return<<'__EOF__';
usage:
$0 --kill # try to kill a running server
$0 --daemon [options] logfile...
--kill # try to kill previous server first
--foreground # stay in foreground, log to stderr
--syslog # log to syslog instead of stderr
$0 --daemon logfile...
$0 --test logfile.... # debug: just run filters against files
__EOF__
}


GetOptions (
'kill' => \$options{'kill'},
'daemon' => \$options{'daemon'},
'foreground' => \$options{'foreground'},
'syslog' => \$options{'syslog'},
'test' => \$options{'test'},
) or die USAGE;


if ($options{'test'}) {
@ARGV>=1 or die USAGE;
while (<>) {
Expand All @@ -359,30 +345,6 @@ if ($options{'test'}) {

$SIG{PIPE}='IGNORE';

$options{'kill'} and Donald::Tools::kill_previous_server('netlog') and sleep 2;

unless ($options{'foreground'}) {
my $pid=fork;
defined $pid or die "$!\n";
$pid and exit;
}

if ($options{'syslog'} or not $options{'foreground'}) {
openlog('netlog','pid','daemon');
Sys::Syslog::setlogsock('unix'); # with 'native' we get EOLs in the logfile, option "noeol" doesn't work
$SIG{__WARN__} = sub { syslog('warning',@_); };
$SIG{__DIE__} = sub { syslog('crit',@_);syslog('crit','exiting');exit 1;};
open (STDOUT,'>','/dev/null');
open (STDERR,'>','/dev/null');
open (STDIN,'<','/dev/null');
}
warn "server started\n";
Donald::Select::Watchfile->new ($0,5,sub {
system $0,'--kill','--daemon',($options{'foreground'}?'--foreground':()),($options{'syslog'}?'--syslog':()),@ARGV or exit;
warn "restart failed\n";
}
);

{ # dirty hack
chomp(my $hostname=`hostname -s`);
push @ARGV,'/package/syslog/log/current.log' if defined $hostname && $hostname eq 'wtf';
Expand All @@ -391,9 +353,6 @@ if ($options{'test'}) {
syslog_new(@ARGV);
Donald::Select::timeout(5,\&check_idle);
Donald::Select::run();
} elsif ($options{'kill'}) {
@ARGV==0 or die USAGE;
Donald::Tools::kill_previous_server('netlog');
} else {
die USAGE;
}
5 changes: 1 addition & 4 deletions netlog/netlog.service
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
[Unit]
Description=Donalds netlog service
Requires=network.target
After=network.target

[Service]
ExecStart=/usr/sbin/netlog --daemon --foreground --kill --syslog /var/log/messages /var/log/mail.log
ExecStart=/usr/sbin/netlog --daemon /var/log/messages /var/log/mail.log
Restart=always
StandardOutput=syslog


[Install]
WantedBy=multi-user.target
Expand Down

0 comments on commit 8ed0e29

Please sign in to comment.