Skip to content

Commit

Permalink
clusterd: Implement standard command service
Browse files Browse the repository at this point in the history
Implement new udp service 'exec.2' which accepts a list of predefined
commands to run.

Implement new command `clusterd exec CMD...`

The new usage is supposed to make `clusterd --exec` and the 'exec' UDP
service obsolete. Having all commands which might be issued after file
updates available in the same %CMD infrastructure will make the
following changes easier and the file shorter, once the obsolete command
`clusterd --exec` and the UDP services udp_rx_flush_gidcache,
udp_rx_make_automaps, udp_rx_reexport and udp_rx_exec are removed.
  • Loading branch information
donald committed Jan 27, 2025
1 parent b5e0685 commit 9574aba
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions clusterd/clusterd
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,7 @@ our %UDP_HANDLER = (
'reexport' => \&udp_rx_reexport,
'log' => \&udp_rx_log,
'exec' => \&udp_rx_exec,
'exec.2' => \&udp_rx_exec2,
'push' => \&udp_rx_push,
);

Expand Down Expand Up @@ -871,8 +872,11 @@ sub push_file {

}

our %CMD=(
'mkmotd'=>'/usr/sbin/mkmotd.pl',
our %CMD = (
'mkmotd' => '/usr/sbin/mkmotd.pl',
'flush-gidcache' => 'date -d tomorrow +%s > /proc/net/rpc/auth.unix.gid/flush',
'reexport' => '/usr/bin/mxmount --reexport-only',
'make-automaps' => '/sbin/make-automaps',
);

sub send_exec {
Expand Down Expand Up @@ -911,6 +915,25 @@ sub udp_rx_exec {
wait;
}

sub udp_rx_exec2 {
my @cmd = @_;
my $pid = fork;
unless (defined $pid) {
warn "$!\n";
return;
}
if ($pid == 0) {
open STDIN,'<','/dev/null';
alarm(60);
chdir '/';
for my $cmd (@cmd) {
exists $CMD{$cmd} and warn "executing $CMD{$cmd}\n";
exists $CMD{$cmd} and system '/bin/sh', '-c', $CMD{$cmd};
}
exit;
}
}

#-------------------------------------------------------------

sub normalize_seg { # [pos,len],[pos,len],...
Expand Down Expand Up @@ -1930,6 +1953,16 @@ sub cmd_push {
}
}

sub cmd_exec {
my @cmd = @_;
for my $cmd (@cmd) {
exists $CMD{$cmd} or die "$cmd: only these commands are allowed: " . join(', ', keys %CMD) . "\n";
}
sync_cluster_pw() or die "$CLUSTER_PW_FILE: $!\n";
$donald_s=new My::Select::INET(Proto=>'udp') or die "$!\n";
udp_broadcast_message($donald_s, 'exec.2', @cmd);
}

#------------------------------------------------------------

our $TRUSTCHECK_PORT=236;
Expand Down Expand Up @@ -1975,6 +2008,8 @@ usage: $0 [options]
--daemon # start a daemon
push files.... # push files over tcp
exec CMD... # execute CMD on all nodes
CMD : mkmotd | flush-gidcache | reexport | make-automaps
__EOF__

Expand Down Expand Up @@ -2062,6 +2097,9 @@ if (defined $options{'push'}) {
if ($cmd eq 'push') {
@args>0 or die USAGE;
cmd_push(@args);
} elsif ($cmd eq 'exec') {
@args > 0 or die USAGE;
cmd_exec(@args);
} else {
die USAGE;
}
Expand Down

0 comments on commit 9574aba

Please sign in to comment.