Class: Wheneverd::Job::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/wheneverd/job/command.rb

Overview

A oneshot command job rendered as ExecStart= in a systemd service unit.

This job accepts either:

  • A String (inserted into ExecStart= as-is, after stripping surrounding whitespace), or
  • An argv Array (formatted/escaped into a systemd-compatible ExecStart= string).

If you need shell features like pipes, redirects, or environment variable expansion, wrap the command explicitly:

Examples:

command "/bin/bash -lc 'echo hello | sed -e s/hello/hi/'"

argv form (safer argument handling)

command ["/bin/bash", "-lc", "echo hello | sed -e s/hello/hi/"]

Constant Summary collapse

SAFE_UNQUOTED =
%r{\A[A-Za-z0-9_@%+=:,./-]+\z}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command:) ⇒ Command

Returns a new instance of Command.

Parameters:

  • command (String, Array<String>)

    non-empty command to run



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/wheneverd/job/command.rb', line 39

def initialize(command:)
  @argv = nil
  @signature = nil
  @command = nil

  case command
  when String then init_string(command)
  when Array then init_argv(command)
  else
    raise InvalidCommandError,
          "Command must be a String or an Array (got #{command.class})"
  end
end

Instance Attribute Details

#argvArray<String>? (readonly)

Original argv form (when constructed with an Array).

Returns:

  • (Array<String>, nil)


31
32
33
# File 'lib/wheneverd/job/command.rb', line 31

def argv
  @argv
end

#commandString (readonly)

Rendered ExecStart= value.

Returns:

  • (String)


26
27
28
# File 'lib/wheneverd/job/command.rb', line 26

def command
  @command
end

#signatureString (readonly)

Stable signature used for unit naming.

Returns:

  • (String)


36
37
38
# File 'lib/wheneverd/job/command.rb', line 36

def signature
  @signature
end