Class: Baal::Daemon

Inherits:
Object
  • Object
show all
Includes:
Commands, MatchingOptions, OptionalOptions
Defined in:
lib/baal.rb

Overview

Daemon is a builder object that allows you construct and access, at any time, the start-stop-daemon string that will be executed. All building of the start-stop-daemon string will be through this object.

A note should be made that all methods which build the start-stop-daemon script return the Daemon instance for the intention of method chaining where possible so as to read like written English.

Constant Summary collapse

PROGRAM_NAME =
'start-stop-daemon'.freeze

Constants included from OptionalOptions

OptionalOptions::OPTIONAL_OPTS, OptionalOptions::VALID_POLICIES, OptionalOptions::VALID_SCHEDULE_CLASSES

Constants included from MatchingOptions

MatchingOptions::MATCHING_OPTIONS

Constants included from Commands

Commands::COMMANDS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from OptionalOptions

#background, #chdir, #chroot, #chuid, #group, #io_sched, #make_pid_file, #nice_level, #no_close, #oknodo, #proc_sched, #quiet, #remove_pid_file, #retry, #signal, #start_as, #test, #umask, #verbose

Methods included from MatchingOptions

#exec, #name, #pid, #pid_file, #ppid, #user

Methods included from Commands

#help, #start, #status, #stop, #version

Constructor Details

#initializeDaemon

Returns a new instance of Daemon.



40
41
42
# File 'lib/baal.rb', line 40

def initialize
  @commands_and_opts = []
end

Instance Attribute Details

#std_statusObject (readonly)

Returns the value of attribute std_status.



38
39
40
# File 'lib/baal.rb', line 38

def std_status
  @std_status
end

#stderrObject (readonly)

Returns the value of attribute stderr.



38
39
40
# File 'lib/baal.rb', line 38

def stderr
  @stderr
end

#stdoutObject (readonly)

Returns the value of attribute stdout.



38
39
40
# File 'lib/baal.rb', line 38

def stdout
  @stdout
end

Instance Method Details

#clear_all!Object

Clears @commands_and_opts and starts over with only the PROGRAM_NAME



48
49
50
51
# File 'lib/baal.rb', line 48

def clear_all!
  @commands_and_opts.clear
  self
end

#daemonize!nil

Executes the built up start-stop-daemon string and throws an error if there isn’t at least one command and at least one matching option.

Returns:

  • (nil)

    returns nil to force user to interact with the attr methods for the system output vs the array that would be returned if nil was not used



67
68
69
70
71
72
# File 'lib/baal.rb', line 67

def daemonize!
  at_least_one_command?
  at_least_one_matching_option?
  @stdout, @stderr, @std_status = Open3.capture3(PROGRAM_NAME, *@commands_and_opts)
  nil
end

#executionString

Returns the built up, whitespace-formatted start-stop-daemon string to be executed.

Returns:

  • (String)

    the built up, whitespace-formatted start-stop-daemon string to be executed



56
57
58
# File 'lib/baal.rb', line 56

def execution
  ([PROGRAM_NAME] + @commands_and_opts).join(' ').strip
end