From 6957220642629a13704d4a58054f72211da33d16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Phillipp=20R=C3=B6ll?= Date: Mon, 12 Aug 2024 14:47:47 +0200 Subject: [PATCH] Add support for .timer units to --deb-systemd Before the change, when using an option --deb-systemd myunit.timer, the actual file created would be /lib/systemd/system/myunit.timer.service Because of that, systemd would then not find the timer. With this change, the correct extension is extracted from the file, defaulting to .service. Typically, there would be two files for installing a timer: --deb-systemd myunit.service (where .service could be omitted) and --deb-systemd myunit.timer So that the .timer references a .service file. --- lib/fpm/package/deb.rb | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/lib/fpm/package/deb.rb b/lib/fpm/package/deb.rb index 4d97dfb0cc..9f2a135fb4 100644 --- a/lib/fpm/package/deb.rb +++ b/lib/fpm/package/deb.rb @@ -517,14 +517,23 @@ def output(output_path) attributes[:deb_systemd] = [] attributes.fetch(:deb_systemd_list, []).each do |systemd| - name = File.basename(systemd, ".service") - dest_systemd = staging_path("lib/systemd/system/#{name}.service") + name = File.basename(systemd) + extname = File.extname(name) + + name_with_extension = if extname.empty? + "#{name}.service" + elsif [".service", ".timer"].include?(extname) + name + else + raise ArgumentError, "Invalid systemd unit file extension: #{extname}. Expected .service or .timer, or no extension." + end + + dest_systemd = staging_path("lib/systemd/system/#{name_with_extension}") mkdir_p(File.dirname(dest_systemd)) FileUtils.cp(systemd, dest_systemd) File.chmod(0644, dest_systemd) - # add systemd service name to attribute - attributes[:deb_systemd] << name + attributes[:deb_systemd] << name_with_extension end if script?(:before_upgrade) or script?(:after_upgrade) or attributes[:deb_systemd].any? @@ -627,8 +636,11 @@ def output(output_path) end attributes.fetch(:deb_systemd_list, []).each do |systemd| - name = File.basename(systemd, ".service") - dest_systemd = staging_path("lib/systemd/system/#{name}.service") + name = File.basename(systemd) + extname = File.extname(systemd) + name_with_extension = extname.empty? ? "#{name}.service" : name + + dest_systemd = staging_path("lib/systemd/system/#{name_with_extension}") mkdir_p(File.dirname(dest_systemd)) FileUtils.cp(systemd, dest_systemd) File.chmod(0644, dest_systemd)