From: Tom Hughes Date: Wed, 17 Nov 2021 09:09:02 +0000 (+0000) Subject: Avoid restarting a non-existent service X-Git-Url: https://git.openstreetmap.org/chef.git/commitdiff_plain/cd3653225c75a743806ae73b473eda8a2a93724e Avoid restarting a non-existent service --- diff --git a/cookbooks/prometheus/resources/exporter.rb b/cookbooks/prometheus/resources/exporter.rb index df5304b3c..ae0596885 100644 --- a/cookbooks/prometheus/resources/exporter.rb +++ b/cookbooks/prometheus/resources/exporter.rb @@ -85,6 +85,7 @@ end action :restart do service service_name do action :restart + only_if { service_exists? } end end @@ -97,6 +98,10 @@ action_class do end end + def service_exists? + File.exist?("/etc/systemd/system/#{service_name}.service") + end + def executable_path "/opt/prometheus/exporters/#{new_resource.exporter}/#{new_resource.exporter}_exporter" end