Skip to content

Commit

Permalink
clusterd: Remove daemon features
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
donald committed Jan 20, 2023
1 parent 0baaebc commit e2c16e1
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 37 deletions.
35 changes: 1 addition & 34 deletions clusterd/clusterd
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand All @@ -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'},
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 1 addition & 3 deletions clusterd/clusterd.service
Original file line number Diff line number Diff line change
@@ -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

Expand Down

0 comments on commit e2c16e1

Please sign in to comment.