Class: Wheneverd::Service
- Inherits:
-
Object
- Object
- Wheneverd::Service
- Defined in:
- lib/wheneverd/service.rb
Overview
A long-running systemd user service managed alongside scheduled timers.
Constant Summary collapse
- SAFE_SETTING_NAME =
/\A[A-Za-z][A-Za-z0-9]*\z/.freeze
Instance Attribute Summary collapse
- #command ⇒ Wheneverd::Job::Command readonly
- #name ⇒ String readonly
- #restart ⇒ String readonly
- #restart_sec ⇒ String readonly
- #service_lines ⇒ Array<String> readonly
Instance Method Summary collapse
-
#initialize(name:, command:, restart: "always", restart_sec: "5s", service: {}) ⇒ Service
constructor
A new instance of Service.
-
#signature ⇒ String
Stable signature used for unit naming.
Constructor Details
#initialize(name:, command:, restart: "always", restart_sec: "5s", service: {}) ⇒ Service
Returns a new instance of Service.
28 29 30 31 32 33 34 |
# File 'lib/wheneverd/service.rb', line 28 def initialize(name:, command:, restart: "always", restart_sec: "5s", service: {}) @name = normalize_name(name) @command = Wheneverd::Job::Command.new(command: command) @restart = normalize_required_value(restart, "restart") @restart_sec = normalize_required_value(restart_sec, "restart_sec") @service_lines = normalize_service_lines(service) end |
Instance Attribute Details
#command ⇒ Wheneverd::Job::Command (readonly)
12 13 14 |
# File 'lib/wheneverd/service.rb', line 12 def command @command end |
#name ⇒ String (readonly)
9 10 11 |
# File 'lib/wheneverd/service.rb', line 9 def name @name end |
#restart ⇒ String (readonly)
15 16 17 |
# File 'lib/wheneverd/service.rb', line 15 def restart @restart end |
#restart_sec ⇒ String (readonly)
18 19 20 |
# File 'lib/wheneverd/service.rb', line 18 def restart_sec @restart_sec end |
#service_lines ⇒ Array<String> (readonly)
21 22 23 |
# File 'lib/wheneverd/service.rb', line 21 def service_lines @service_lines end |
Instance Method Details
#signature ⇒ String
Stable signature used for unit naming.
39 40 41 42 43 44 45 46 47 |
# File 'lib/wheneverd/service.rb', line 39 def signature [ "service:#{name}", command.signature, "restart:#{restart}", "restart_sec:#{restart_sec}", *service_lines ].join("\n") end |