From d9607a667bf751eb217930c5a691ebf0f0fe6d83 Mon Sep 17 00:00:00 2001 From: Vadim Ogievetsky Date: Wed, 7 Sep 2022 07:00:11 -0700 Subject: [PATCH] Add CTA and fix typo (#13009) (#13039) * Add CTA and fix typo * resolve hostname better --- .gitignore | 2 +- examples/bin/greet | 32 +++++++++++++++++++ examples/bin/supervise | 21 ++++++++++-- .../conf/supervise/single-server/large.conf | 1 + .../conf/supervise/single-server/medium.conf | 1 + .../single-server/micro-quickstart.conf | 1 + .../single-server/nano-quickstart.conf | 1 + .../conf/supervise/single-server/small.conf | 1 + .../conf/supervise/single-server/xlarge.conf | 1 + 9 files changed, 57 insertions(+), 4 deletions(-) create mode 100755 examples/bin/greet diff --git a/.gitignore b/.gitignore index 89eabfcbdd0..f906e242679 100644 --- a/.gitignore +++ b/.gitignore @@ -25,5 +25,5 @@ README .pmdruleset.xml .java-version integration-tests/gen-scripts/ -bin/ +/bin/ *.hprof diff --git a/examples/bin/greet b/examples/bin/greet new file mode 100755 index 00000000000..94e0a263509 --- /dev/null +++ b/examples/bin/greet @@ -0,0 +1,32 @@ +#!/usr/bin/env perl + +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +use strict; +use warnings; +use Sys::Hostname qw/hostname/; + +my $h = hostname; +system("host \Q$h\E >/dev/null 2>&1"); +my $h_valid = !$?; + +print "Starting Apache Druid.\n"; +print "Open http://localhost:8888/" . + ($h_valid ? " or http://$h:8888/" : "") . + " in your browser to access the web console.\n"; +print "Or, if you have enabled TLS, use https on port 9088.\n" diff --git a/examples/bin/supervise b/examples/bin/supervise index aaccce6d180..81b7e57b049 100755 --- a/examples/bin/supervise +++ b/examples/bin/supervise @@ -55,12 +55,13 @@ sub read_config_file my @commands; my @verify; + my @notify; my $kill_timeout; while (my $line = <$config_fh>) { chomp $line; next if $line =~ /^(\s*\#.*|\s*)$/; - if ($line =~ /^(:verify|:kill-timeout|(?:\!p[0-9]+\s+)?[^:]\S+)\s+(.+)$/) { + if ($line =~ /^(:verify|:notify|:kill-timeout|(?:\!p[0-9]+\s+)?[^:]\S+)\s+(.+)$/) { my $name = $1; my $order = 50; my $command = $2; @@ -72,6 +73,8 @@ sub read_config_file if ($name eq ':verify') { push @verify, $command; + } elsif ($name eq ':notify') { + push @notify, $command; } elsif ($name eq ':kill-timeout') { $kill_timeout = int($command); } else { @@ -92,7 +95,7 @@ sub read_config_file } close $config_fh; - return { commands => \@commands, verify => \@verify, 'kill-timeout' => $kill_timeout }; + return { commands => \@commands, verify => \@verify, notify => \@notify, 'kill-timeout' => $kill_timeout }; } sub stringify_exit_status @@ -136,6 +139,8 @@ sub pretty return "\x1b[1m$text\x1b[0m"; } elsif ($color eq 'red') { return "\x1b[31m\x1b[1m$text\x1b[0m"; + } elsif ($color eq 'green') { + return "\x1b[32m\x1b[1m$text\x1b[0m"; } else { return $text; } @@ -236,8 +241,18 @@ $SIG{TERM} = sub { if (!$killed) { $killed = 15; $killkill = time + $opt{'kill-t # Build up control fifo command over multiple sysreads, potentially my $fifobuffer = ''; +# Run notification commands and print their output +for my $notify_cmd (@{$config->{notify}}) { + my $notify_output = qx[$notify_cmd 2>&1]; + if (!$?) { + for my $notify_line (split /\n/, $notify_output) { + logit pretty($notify_line, 'green'); + } + } +} + if (defined $opt{svlogd}) { - logit "Staring services with log directory [svdir]."; + logit "Starting services with log directory [$svdir]."; } else { logit "Starting services with log directory [$logdir]."; } diff --git a/examples/conf/supervise/single-server/large.conf b/examples/conf/supervise/single-server/large.conf index 2f7baf6fa5b..9dde5eaa335 100644 --- a/examples/conf/supervise/single-server/large.conf +++ b/examples/conf/supervise/single-server/large.conf @@ -1,5 +1,6 @@ :verify bin/verify-java :verify bin/verify-default-ports +:notify bin/greet :kill-timeout 10 !p10 zk bin/run-zk conf diff --git a/examples/conf/supervise/single-server/medium.conf b/examples/conf/supervise/single-server/medium.conf index 84d15caba9b..78d43ac5269 100644 --- a/examples/conf/supervise/single-server/medium.conf +++ b/examples/conf/supervise/single-server/medium.conf @@ -1,5 +1,6 @@ :verify bin/verify-java :verify bin/verify-default-ports +:notify bin/greet :kill-timeout 10 !p10 zk bin/run-zk conf diff --git a/examples/conf/supervise/single-server/micro-quickstart.conf b/examples/conf/supervise/single-server/micro-quickstart.conf index de1c0f8d68f..78d43a3fd81 100644 --- a/examples/conf/supervise/single-server/micro-quickstart.conf +++ b/examples/conf/supervise/single-server/micro-quickstart.conf @@ -1,5 +1,6 @@ :verify bin/verify-java :verify bin/verify-default-ports +:notify bin/greet :kill-timeout 10 !p10 zk bin/run-zk conf diff --git a/examples/conf/supervise/single-server/nano-quickstart.conf b/examples/conf/supervise/single-server/nano-quickstart.conf index 8baf7698021..918b3683404 100644 --- a/examples/conf/supervise/single-server/nano-quickstart.conf +++ b/examples/conf/supervise/single-server/nano-quickstart.conf @@ -1,5 +1,6 @@ :verify bin/verify-java :verify bin/verify-default-ports +:notify bin/greet :kill-timeout 10 !p10 zk bin/run-zk conf diff --git a/examples/conf/supervise/single-server/small.conf b/examples/conf/supervise/single-server/small.conf index ef4cad54da4..ef88416949b 100644 --- a/examples/conf/supervise/single-server/small.conf +++ b/examples/conf/supervise/single-server/small.conf @@ -1,5 +1,6 @@ :verify bin/verify-java :verify bin/verify-default-ports +:notify bin/greet :kill-timeout 10 !p10 zk bin/run-zk conf diff --git a/examples/conf/supervise/single-server/xlarge.conf b/examples/conf/supervise/single-server/xlarge.conf index dbec43f4e77..e0d6c638b70 100644 --- a/examples/conf/supervise/single-server/xlarge.conf +++ b/examples/conf/supervise/single-server/xlarge.conf @@ -1,5 +1,6 @@ :verify bin/verify-java :verify bin/verify-default-ports +:notify bin/greet :kill-timeout 10 !p10 zk bin/run-zk conf