From 4f97485b6da442cf101b520093a853da9819ceeb Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Fri, 20 Jan 2023 10:13:03 +0100 Subject: [PATCH] netlog: Remove daemon features We now run the netlog daemon as a systemd service. The features to demonize, redirect logging, restart and kill previous daemons are all not needed. Additionally, the restart is buggy, because Donald::Tools::kill_previous_server doesn't kill the parent - assuming this is an rc.d script. However, in `--foregound` mode, the previous daemon is in fact the parent. - Remove unused features and leave job control and logging to systemd. - Log into journal instead of into syslog. - Remove "Description=" from the unit, because its easier to identify things, when the name used in messages is the same as the unit name and the unit file name. --- netlog/netlog | 43 +------------------------------------------ netlog/netlog.service | 5 +---- 2 files changed, 2 insertions(+), 46 deletions(-) diff --git a/netlog/netlog b/netlog/netlog index e2b812b..5e3b787 100755 --- a/netlog/netlog +++ b/netlog/netlog @@ -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.]+)/; @@ -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 (<>) { @@ -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'; @@ -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; } diff --git a/netlog/netlog.service b/netlog/netlog.service index 97abbb3..56b7061 100644 --- a/netlog/netlog.service +++ b/netlog/netlog.service @@ -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