Class: Robinhood::Daemon

Inherits:
Object
  • Object
show all
Defined in:
lib/robinhood/daemon.rb

Overview

This class will start robinhood as a daemon

Defined Under Namespace

Classes: Options

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Daemon

Public: Instantiates a new Robinhood::Daemon object

args - Hash with the different options that can be supplied to the Daemonize object

:config_file - File that will contain the robinhood tasks, by default it will be robinhood.rb
:pids_path - Dir to store de Pidfile for the daemon, by default it will be 'tmp/pids'
:log_path - Dir to store the logs for the daemon, by default it will be 'log'

Returns a new Robinhood::Daemonize



18
19
20
21
22
23
# File 'lib/robinhood/daemon.rb', line 18

def initialize(options={})
  @options = default_options.merge(options)
  @file = File.expand_path(@options[:config_file])
  @pids_path = File.expand_path(@options[:pids_path])
  @log_path = File.expand_path(@options[:log_path])
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



8
9
10
# File 'lib/robinhood/daemon.rb', line 8

def file
  @file
end

#log_pathObject (readonly)

Returns the value of attribute log_path.



8
9
10
# File 'lib/robinhood/daemon.rb', line 8

def log_path
  @log_path
end

#pids_pathObject (readonly)

Returns the value of attribute pids_path.



8
9
10
# File 'lib/robinhood/daemon.rb', line 8

def pids_path
  @pids_path
end

Instance Method Details

#restartObject



45
46
47
48
# File 'lib/robinhood/daemon.rb', line 45

def restart
  stop
  start
end

#startObject Also known as: run

Public: Start the daemon

Returns nothing



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/robinhood/daemon.rb', line 28

def start
  definition = File.read(file)

  FileUtils.mkdir_p(log_path)
  FileUtils.mkdir_p(pids_path)

  Daemons.run_proc(filename, daemon_options.merge(ARGV: [@options[:command]])) do
    instance_eval(definition, @file)
    Robinhood.run
  end
end

#stopObject



41
42
43
# File 'lib/robinhood/daemon.rb', line 41

def stop
  Daemons.run_proc(filename, daemon_options.merge(ARGV: ['stop']))
end