From 8f2be3f3af326cf15634a21292af4d1ee52c6e8b Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Wed, 4 Mar 2026 20:26:51 +0000 Subject: [PATCH] Enssure we wait for the grafana server to be fully started --- cookbooks/prometheus/metadata.rb | 2 ++ cookbooks/prometheus/recipes/server.rb | 7 +++++++ cookbooks/tools/files/default/local-bin/wait-for-port | 6 ++++++ cookbooks/tools/recipes/default.rb | 11 +++++++++++ 4 files changed, 26 insertions(+) create mode 100755 cookbooks/tools/files/default/local-bin/wait-for-port diff --git a/cookbooks/prometheus/metadata.rb b/cookbooks/prometheus/metadata.rb index e3f4dc4d5..25ff3d821 100644 --- a/cookbooks/prometheus/metadata.rb +++ b/cookbooks/prometheus/metadata.rb @@ -11,3 +11,5 @@ depends "apt" depends "awscli" depends "hardware" depends "networking" +depends "systemd" +depends "tools" diff --git a/cookbooks/prometheus/recipes/server.rb b/cookbooks/prometheus/recipes/server.rb index 81d00b98c..4b75de503 100644 --- a/cookbooks/prometheus/recipes/server.rb +++ b/cookbooks/prometheus/recipes/server.rb @@ -21,6 +21,7 @@ include_recipe "apache" include_recipe "apt::grafana" include_recipe "awscli" include_recipe "networking" +include_recipe "tools" passwords = data_bag_item("prometheus", "passwords") tokens = data_bag_item("prometheus", "tokens") @@ -355,6 +356,12 @@ template "/etc/grafana/grafana.ini" do variables :passwords => passwords end +systemd_service "grafana-server-wait-for-port" do + service "grafana-server" + dropin "wait-for-port" + exec_start_post "/usr/local/bin/wait-for-port 3000" +end + service "grafana-server" do action [:enable, :start] subscribes :restart, "template[/etc/grafana/grafana.ini]" diff --git a/cookbooks/tools/files/default/local-bin/wait-for-port b/cookbooks/tools/files/default/local-bin/wait-for-port new file mode 100755 index 000000000..cd4db798f --- /dev/null +++ b/cookbooks/tools/files/default/local-bin/wait-for-port @@ -0,0 +1,6 @@ +#!/bin/sh + +while [ -z "$(ss -Htl sport = :$1)" ] +do + sleep 1 +done diff --git a/cookbooks/tools/recipes/default.rb b/cookbooks/tools/recipes/default.rb index a51879e67..a0729afea 100644 --- a/cookbooks/tools/recipes/default.rb +++ b/cookbooks/tools/recipes/default.rb @@ -51,6 +51,17 @@ service "rsyslog" do supports :status => true, :restart => true, :reload => true end +# Install some common tools +remote_directory "/usr/local/bin" do + source "local-bin" + owner "root" + group "root" + mode "755" + files_owner "root" + files_group "root" + files_mode "755" +end + # Remove some unused and unwanted packages package %w[mlocate whoopsie] do action :purge -- 2.39.5