From cb3952291a8e1d28affe866621804db96ecf202d Mon Sep 17 00:00:00 2001 From: Daniel Nichter Date: Wed, 10 Apr 2013 17:29:33 -0600 Subject: [PATCH] Make --stop check for files. --- bin/pt-agent | 68 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 39 insertions(+), 29 deletions(-) diff --git a/bin/pt-agent b/bin/pt-agent index 3a78a0fd..9301c494 100755 --- a/bin/pt-agent +++ b/bin/pt-agent @@ -6474,39 +6474,49 @@ sub stop_agent { } } - _info("Removing all services from crontab..."); - eval { - schedule_services( - services => [], - lib_dir => $lib_dir, - quiet => 1, - ); - }; - if ( $EVAL_ERROR ) { - _warn("Error removing services from crontab: $EVAL_ERROR"); + if ( -f "$lib_dir/crontab" ) { + _info("Removing all services from crontab..."); + eval { + schedule_services( + services => [], + lib_dir => $lib_dir, + quiet => 1, + ); + }; + if ( $EVAL_ERROR ) { + _warn("Error removing services from crontab: $EVAL_ERROR"); + } + } + else { + _info("$lib_dir/crontab does not exist, no services to remove from crontab"); } - my $env_vars = env_vars(); + if ( -d "$lib_dir/services" ) { + my $env_vars = env_vars(); - _info("Disabling all services (clean up)..."); - SERVICE: - foreach my $file ( glob "$lib_dir/services/disable-*" ) { - my $service = basename($file); - my $disable_log = "$lib_dir/logs/$service.stop"; - my $cmd = ($env_vars ? "$env_vars " : '') - . "${bin_dir}pt-agent --run-service $service" - . " $disable_log 2>&1"; - PTDEBUG && _d($cmd); - system($cmd); - my $cmd_exit_status = $CHILD_ERROR >> 8; - if ( $cmd_exit_status != 0 ) { - my $err = slurp($disable_log); - _warn("Error running $service: " . ($err || '')); - next SERVICE; + _info("Disabling all services (clean up)..."); + SERVICE: + foreach my $file ( glob "$lib_dir/services/disable-*" ) { + my $service = basename($file); + my $disable_log = "$lib_dir/logs/$service.stop"; + my $cmd = ($env_vars ? "$env_vars " : '') + . "${bin_dir}pt-agent --run-service $service" + . " $disable_log 2>&1"; + PTDEBUG && _d($cmd); + system($cmd); + my $cmd_exit_status = $CHILD_ERROR >> 8; + if ( $cmd_exit_status != 0 ) { + my $err = slurp($disable_log); + _warn("Error running $service: " . ($err || '')); + next SERVICE; + } + unlink $disable_log + or _warn("Cannot remove $disable_log: $OS_ERROR"); } - unlink $disable_log - or _warn("Cannot remove $disable_log: $OS_ERROR"); + } + else { + _info("$lib_dir/services does not exist, no services to disable") } return;