From ca94866879192a2ea962ce12d15573aa83115cd8 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Fri, 30 Aug 2013 14:17:02 -0400 Subject: [PATCH] LP#1204123 osrf_control warn and exit on bad host Any time a start action is issued (start, start_all, restart, restart_all), osrf_control will first verify that the selected hostname (or localhost) hosts the requested service(s). If not, the user is warned and the script exits before any action is taken. Note: we do not make a similar verification for stop and signal actions, since those may be reasonably be used even when a service is not configured to run on the selected host. Thanks to Jason Stephenson for the suggestion. Signed-off-by: Bill Erickson Signed-off-by: Jason Stephenson --- bin/opensrf-perl.pl.in | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/bin/opensrf-perl.pl.in b/bin/opensrf-perl.pl.in index 5c161a21..f9ab8caf 100755 --- a/bin/opensrf-perl.pl.in +++ b/bin/opensrf-perl.pl.in @@ -94,6 +94,20 @@ if ($opt_localhost) { my $C_COMMAND = "opensrf-c -c $opt_config -x opensrf -p $opt_pid_dir -h $hostname"; my $PY_COMMAND = "opensrf.py -f $opt_config -p $opt_pid_dir ". ($opt_localhost ? '-l' : ''); +sub verify_services { + my $service = shift; + my @services = (@perl_services, map {$_->{service}} @nonperl_services); + if (@services) { + return 1 unless $service; + return 1 if grep { $_ eq $service } @services; + msg("$service is not configured to run on $hostname"); + } else { + msg("No services are configured to run on $hostname"); + } + msg("Perhaps you meant to use --localhost?") unless $opt_localhost; + exit; +} + sub do_signal_send { my $service = shift; my $signal = shift; @@ -371,8 +385,8 @@ sub do_start { } } - msg("$service is not configured to run on $hostname"); - return 1; + # should not get here + return 0; } sub do_start_all { @@ -667,11 +681,20 @@ HELP exit; } -# starting services -do_init() and do_start($opt_service) if $opt_start; -do_init() and do_stop($opt_service) and do_start($opt_service) if $opt_restart; -do_init() and do_start_all() if $opt_start_all; -do_init() and do_stop_all() and do_start_all() if $opt_restart_all; +# we do not verify services for stop/signal actions, since those may +# legitimately be used against services not (or no longer) configured +# to run on the selected host. +do_init() and verify_services($opt_service) if + $opt_start or + $opt_start_all or + $opt_restart or + $opt_restart_all; + +# starting services. do_init() handled above +do_start($opt_service) if $opt_start; +do_stop($opt_service) and do_start($opt_service) if $opt_restart; +do_start_all() if $opt_start_all; +do_stop_all() and do_start_all() if $opt_restart_all; # stopping services do_stop($opt_service) if $opt_stop; -- 2.43.2