Skip to content

netlog: Remove daemon features #300

Merged
merged 1 commit into from
Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn’t the --daemon not very systemd idiomatic(?), that means, it prefers programs that do not daemonize?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Year right. There are two operating modes: What would be better?

netlog test files...
netlog run files...

?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe "watch" instead of run, because it watches the named files. Or "service", because it runs forever waiting for external events (data appended top these files). "service" seems to be better when applied to clusterd, which also has "--daemon" at the moment. clusterd loops forever waiting for external events over the network. idk.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like watch, but don’t have a strong opinion.

Restart=always
StandardOutput=syslog


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