From e2c16e14200d61160dacd15c0d69f1a570e64b62 Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Fri, 20 Jan 2023 12:10:05 +0100 Subject: [PATCH] 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