From 0baaebc52ba64e7388a79b4e0b71d5614d4ebf69 Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Fri, 20 Jan 2023 11:49:33 +0100 Subject: [PATCH 1/3] clusterd: Use syslog() for NETLOG messages We are going to remove the --syslog option to log everything into syslog. However, netlog messages received from netlog services should still go into syslog. So use syslog() for that explicitly. --- clusterd/clusterd | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/clusterd/clusterd b/clusterd/clusterd index 5625d04..a0f46ac 100755 --- a/clusterd/clusterd +++ b/clusterd/clusterd @@ -654,6 +654,7 @@ sub delete_host { #----------------------------------------------------------------------- package My::NetlogReceiver; +use Sys::Syslog; our $listen_socket; our $TCP_MAX=1024; @@ -668,7 +669,7 @@ sub day { sub bigben { my $day=day(); $day le $DAY_LAST_MSG and return; - warn "NETLOG ==================================================== morning has broken ====\n"; + syslog('warning', "NETLOG ==================================================== morning has broken ====\n"); $DAY_LAST_MSG=$day; } @@ -702,8 +703,7 @@ sub receive { last if length($$bufref)<2+$l; my $msg=substr($$bufref,2,$l); $$bufref=substr($$bufref,2+$l); - $|=1; - warn "NETLOG $msg\n" unless $msg=~/NETLOG/; + syslog('warning', "NETLOG $msg\n") unless $msg=~/NETLOG/; } My::Select::reader_requeue(); } @@ -2124,9 +2124,10 @@ if (defined $options{'push'}) { $pid and exit 0; } + openlog('clusterd','pid','daemon'); + Sys::Syslog::setlogsock('unix'); # with 'native' we get EOLs in the logfile, option "noeol" doesn't work + if ($options{'syslog'} or not $options{'foreground'}) { - openlog('clusterd','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'); From e2c16e14200d61160dacd15c0d69f1a570e64b62 Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Fri, 20 Jan 2023 12:10:05 +0100 Subject: [PATCH 2/3] clusterd: Remove daemon features We now run clusterd as a systemd service. The features to daemonize, 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. --- clusterd/clusterd | 35 +---------------------------------- clusterd/clusterd.service | 4 +--- 2 files changed, 2 insertions(+), 37 deletions(-) diff --git a/clusterd/clusterd b/clusterd/clusterd index a0f46ac..2d2a736 100755 --- a/clusterd/clusterd +++ b/clusterd/clusterd @@ -1702,16 +1702,7 @@ our $PROG_MTIME; sub check_progfile_status { defined $PROG_FILE or $PROG_FILE=$0; my @f=lstat $PROG_FILE or return; - if (defined $PROG_MTIME) { - if ($f[9] != $PROG_MTIME) { - warn "progfile $PROG_FILE has changed - upgrade restart from version ".version_info()."\n"; - exec $PROG_FILE,'--daemon',($options{'foreground'}?'--foreground':()),($options{'syslog'}?'--syslog':()); - } - } - else { - $PROG_MTIME=$f[9]; - } - My::Select::timeout(60,\&check_progfile_status); + $PROG_MTIME=$f[9]; } sub version_info { # '20090617-155314' @@ -2047,12 +2038,7 @@ usage: $0 [options] --lsof=pattern - --kill # try to kill a running server - --daemon # start a daemon - --kill # try to kill previous server first - --foreground # stay in foreground, log to stderr - --syslog # log to syslog instead of stderr push files.... # push files over tcp @@ -2061,12 +2047,9 @@ __EOF__ use Getopt::Long; GetOptions ( - 'kill' => \$options{'kill'}, 'daemon' => \$options{'daemon'}, 'push=s' => \$options{'push'}, 'exec=s' => \$options{'exec'}, - 'foreground' => \$options{'foreground'}, - 'syslog' => \$options{'syslog'}, 'push-amd-tar' => \$options{'push_amd_tar'}, 'send-restart' => \$options{'send-restart'}, 'flush-gidcache' => \$options{'flush-gidcache'}, @@ -2111,30 +2094,14 @@ if (defined $options{'push'}) { $donald_s=new My::Select::INET(Proto=>'udp') or die "$!\n"; udp_broadcast_message($donald_s,'reexport'); } elsif (defined $options{'daemon'}) { - $options{'kill'} and Donald::Tools::kill_previous_server('clusterd') and sleep 2; - $SIG{PIPE}='IGNORE'; $donald_s=new My::Select::INET(Proto=>'udp',Broadcast=>1,LocalPort=>$UDP_PORT) or die "$!\n"; $donald_s->receive_data(\&udp_message,$donald_s); - unless ($options{'foreground'}) { - my $pid=fork; - defined $pid or die "$!\n"; - $pid and exit 0; - } - openlog('clusterd','pid','daemon'); Sys::Syslog::setlogsock('unix'); # with 'native' we get EOLs in the logfile, option "noeol" doesn't work - if ($options{'syslog'} or not $options{'foreground'}) { - $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'); - } - check_progfile_status(); warn "server started - ".version_info()."\n"; init_area(); diff --git a/clusterd/clusterd.service b/clusterd/clusterd.service index 79f0beb..c5566ef 100644 --- a/clusterd/clusterd.service +++ b/clusterd/clusterd.service @@ -1,11 +1,9 @@ [Unit] -Description=ClusterDonald Requires=network.target After=network.target [Service] -ExecStart=/usr/sbin/clusterd --daemon --foreground --kill --syslog -StandardOutput=syslog +ExecStart=/usr/sbin/clusterd --daemon Restart=always RestartSec=10s From 985ffdcffaa555503e2e52d5a33eeed8d3426ccf Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Fri, 20 Jan 2023 12:19:49 +0100 Subject: [PATCH 3/3] clusterd: Remove obsolete code --- clusterd/clusterd | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/clusterd/clusterd b/clusterd/clusterd index 2d2a736..b38a9e5 100755 --- a/clusterd/clusterd +++ b/clusterd/clusterd @@ -769,7 +769,6 @@ chomp($my_unixrev); our $CLUSTER_PW; our $CLUSTER_PW_FILE='/etc/clusterd.password'; -our $OLD_CLUSTER_PW_FILE='/root/clusterd.password'; our $CLUSTER_PW_TIMESTAMP=0; $ENV{'PATH'} = '/usr/local/bin:/sbin:/usr/sbin:/bin'.($ENV{PATH}?':'.$ENV{PATH}:''); # for ps , tar (gnu!) @@ -1612,24 +1611,6 @@ sub send_tcp_cp { sub sync_cluster_pw { my $st=Donald::FileInfo->lstat($CLUSTER_PW_FILE); - # upgrade : move cluster password file from /root to /etc - - if (!$st && -e $OLD_CLUSTER_PW_FILE) { - warn "upgrading cluster password file location $OLD_CLUSTER_PW_FILE -> $CLUSTER_PW_FILE\n"; - my $in=new IO::File $OLD_CLUSTER_PW_FILE,'<'; - unless (defined $in) {warn "$OLD_CLUSTER_PW_FILE: $!\n";return undef;} - my $out=new IO::File $CLUSTER_PW_FILE,O_WRONLY|O_CREAT,0600; - unless (defined $out) {warn "$CLUSTER_PW_FILE: $!\n";return undef;} - my $data; - $in->read($data,1024); - $out->write($data); - $in->close; - $out->close; - $st=Donald::FileInfo->lstat($CLUSTER_PW_FILE); - defined $st or die "$CLUSTER_PW_FILE: $!\n"; - unlink $OLD_CLUSTER_PW_FILE; - } - if ($st) { if (!defined $CLUSTER_PW or $CLUSTER_PW_TIMESTAMP != $st->mtime) { my $fh=new IO::File $CLUSTER_PW_FILE,'<';