Module: Nodectl

Defined in:
lib/nodectl.rb,
lib/nodectl/version.rb

Defined Under Namespace

Modules: Generators, Stream, Webapp Classes: Action, Binding, CLI, Context, Database, Instance, Log, Manager, MultiIO, Options, Process, PromisedFile, Recipe, Repository, Server, Service, Watchdog

Constant Summary collapse

NotFound =
Class.new(Sinatra::NotFound)
VERSION =
"0.2.4"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.optionsObject (readonly)

Returns the value of attribute options.



61
62
63
# File 'lib/nodectl.rb', line 61

def options
  @options
end

Class Method Details

.assets_pathString

Base path of assets folder

Returns:

  • (String)


131
132
133
# File 'lib/nodectl.rb', line 131

def assets_path
  File.absolute_path(File.join(__FILE__, "../../assets"))
end

.boot(options = {}) ⇒ Object

Node initialization: here default global options could be overriden

Parameters:

  • options (Hash) (defaults to: {})

    overrides for default options



66
67
68
69
70
71
72
73
# File 'lib/nodectl.rb', line 66

def boot(options = {})
  @options = Options.new(options)

  # Routing targets
  Dir["#{@options[:recipe_dir]}/**/*.rb"].each do |path|
    require path
  end
end

.databaseNodectl::Database

Key-value store for node

Returns:



78
79
80
# File 'lib/nodectl.rb', line 78

def database
  @database ||= Nodectl::Database.new(options[:database])
end

.loggerLogger

Get logger instance

Returns:

  • (Logger)

    logger instance



108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/nodectl.rb', line 108

def logger
  unless defined? @logger
    file = File.open(options[:logger_dir].join("nodectl.log"), "a")
    file.sync = true
    io = MultiIO.new(STDOUT, file)

    @logger ||= Logger.new(io)
    @logger.level = Logger.const_get(options[:log_level])
  end

  @logger
end

.manifestArray

Get node manifest: list of hashes with service definitions. It looks like:

[

{
  "name" => "hub",
  "repo" => "git://example.com:service.git",
  "path" => "hub"
},
...

]

Returns:

  • (Array)

    node manifest



98
99
100
101
102
103
# File 'lib/nodectl.rb', line 98

def manifest
  @manifest ||= YAML.load_file(@options[:manifest]) || []
rescue SystemCallError => e
  $stderr.puts "Manifest loading error: #{e.message}"
  abort
end

.serverObject



82
83
84
# File 'lib/nodectl.rb', line 82

def server
  @server ||= Nodectl::Server.new(options)
end

.shut_up!Object

Redirect all standard streams to null device



122
123
124
125
126
# File 'lib/nodectl.rb', line 122

def shut_up!
  $stdout.reopen(File.open(File::NULL, "w"))
  $stderr.reopen(File.open(File::NULL, "w"))
  $stdin.reopen(File.open(File::NULL, "r"))
end