]> git.openstreetmap.org Git - chef.git/commitdiff
Avoid restarting a non-existent service
authorTom Hughes <tom@compton.nu>
Wed, 17 Nov 2021 09:09:02 +0000 (09:09 +0000)
committerTom Hughes <tom@compton.nu>
Wed, 17 Nov 2021 09:58:55 +0000 (09:58 +0000)
cookbooks/prometheus/resources/exporter.rb

index df5304b3c3aeeebf5a92332237dda68605a97a38..ae0596885b07220efd3d9a1d09ace9c3e34be211 100644 (file)
@@ -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