Module: Invoker

Defined in:
lib/invoker.rb,
lib/invoker/cli.rb,
lib/invoker/ipc.rb,
lib/invoker/daemon.rb,
lib/invoker/errors.rb,
lib/invoker/logger.rb,
lib/invoker/reactor.rb,
lib/invoker/version.rb,
lib/invoker/cli/tail.rb,
lib/invoker/commander.rb,
lib/invoker/dns_cache.rb,
lib/invoker/power/dns.rb,
lib/invoker/cli/pinger.rb,
lib/invoker/ipc/server.rb,
lib/invoker/ipc/message.rb,
lib/invoker/power/setup.rb,
lib/invoker/cli/question.rb,
lib/invoker/power/config.rb,
lib/invoker/event/manager.rb,
lib/invoker/power/powerup.rb,
lib/invoker/command_worker.rb,
lib/invoker/parsers/config.rb,
lib/invoker/power/balancer.rb,
lib/invoker/reactor/reader.rb,
lib/invoker/ipc/add_command.rb,
lib/invoker/ipc/unix_client.rb,
lib/invoker/process_manager.rb,
lib/invoker/process_printer.rb,
lib/invoker/cli/tail_watcher.rb,
lib/invoker/ipc/base_command.rb,
lib/invoker/ipc/list_command.rb,
lib/invoker/ipc/ping_command.rb,
lib/invoker/ipc/tail_command.rb,
lib/invoker/parsers/procfile.rb,
lib/invoker/power/pf_migrate.rb,
lib/invoker/power/http_parser.rb,
lib/invoker/power/port_finder.rb,
lib/invoker/ipc/client_handler.rb,
lib/invoker/ipc/reload_command.rb,
lib/invoker/ipc/remove_command.rb,
lib/invoker/power/url_rewriter.rb,
lib/invoker/power/http_response.rb,
lib/invoker/ipc/add_http_command.rb,
lib/invoker/ipc/dns_check_command.rb,
lib/invoker/power/setup/osx_setup.rb,
lib/invoker/power/setup/distro/arch.rb,
lib/invoker/power/setup/distro/base.rb,
lib/invoker/power/setup/distro/mint.rb,
lib/invoker/power/setup/linux_setup.rb,
lib/invoker/ipc/message/list_response.rb,
lib/invoker/ipc/message/tail_response.rb,
lib/invoker/power/setup/distro/debian.rb,
lib/invoker/power/setup/distro/redhat.rb,
lib/invoker/power/setup/distro/ubuntu.rb,
lib/invoker/power/setup/distro/opensuse.rb

Defined Under Namespace

Modules: Errors, Event, IPC, Parsers, Power Classes: CLI, CommandWorker, Commander, DNSCache, Daemon, Logger, ProcessManager, ProcessPrinter, Reactor, Version

Constant Summary collapse

VERSION =
"1.5.6"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.certificateObject

Returns the value of attribute certificate.



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

def certificate
  @certificate
end

.commanderObject

Returns the value of attribute commander.



37
38
39
# File 'lib/invoker.rb', line 37

def commander
  @commander
end

.configObject

Returns the value of attribute config.



37
38
39
# File 'lib/invoker.rb', line 37

def config
  @config
end

.daemonizeObject Also known as: daemonize?

Returns the value of attribute daemonize.



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

def daemonize
  @daemonize
end

.dns_cacheObject

Returns the value of attribute dns_cache.



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

def dns_cache
  @dns_cache
end

.nocolorsObject Also known as: nocolors?

Returns the value of attribute nocolors.



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

def nocolors
  @nocolors
end

.private_keyObject

Returns the value of attribute private_key.



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

def private_key
  @private_key
end

.tail_watchersObject

Returns the value of attribute tail_watchers.



37
38
39
# File 'lib/invoker.rb', line 37

def tail_watchers
  @tail_watchers
end

Class Method Details

.can_run_balancer?(throw_warning = true) ⇒ Boolean

Returns:

  • (Boolean)


72
73
74
75
76
77
78
79
# File 'lib/invoker.rb', line 72

def can_run_balancer?(throw_warning = true)
  return true if File.exist?(Invoker::Power::Config.config_file)

  if throw_warning
    Invoker::Logger.puts("Invoker has detected setup has not been run. Domain feature will not work without running setup command.".colorize(:red))
  end
  false
end

.check_and_notify_with_terminal_notifier(message) ⇒ Object



114
115
116
117
118
119
# File 'lib/invoker.rb', line 114

def check_and_notify_with_terminal_notifier(message)
  command_path = `which terminal-notifier`
  if command_path && !command_path.empty?
    system("terminal-notifier -message '#{message}' -title Invoker")
  end
end

.close_socket(socket) ⇒ Object



62
63
64
65
66
# File 'lib/invoker.rb', line 62

def close_socket(socket)
  socket.close
rescue StandardError => error
  Invoker::Logger.puts "Error removing socket #{error}"
end

.daemonObject



68
69
70
# File 'lib/invoker.rb', line 68

def daemon
  @daemon ||= Invoker::Daemon.new
end

.darwin?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/invoker.rb', line 43

def darwin?
  ruby_platform.downcase.include?("darwin")
end

.default_tldObject



148
149
150
# File 'lib/invoker.rb', line 148

def default_tld
  'test'
end

.homeString

On some platforms ‘Dir.home` or `ENV` does not return home directory of user. this is especially true, after effective and real user id of process has been changed.

Returns:

  • (String)

    home directory of the user



140
141
142
143
144
145
146
# File 'lib/invoker.rb', line 140

def home
  if File.writable?(Dir.home)
    Dir.home
  else
    Etc.getpwuid(Process.uid).dir
  end
end

.linux?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/invoker.rb', line 47

def linux?
  ruby_platform.downcase.include?("linux")
end

.load_invoker_config(file, port) ⇒ Object



55
56
57
58
59
60
# File 'lib/invoker.rb', line 55

def load_invoker_config(file, port)
  @config = Invoker::Parsers::Config.new(file, port)
  @dns_cache = Invoker::DNSCache.new(@invoker_config)
  @tail_watchers = Invoker::CLI::TailWatcher.new
  @commander = Invoker::Commander.new
end

.migrate_old_config(old_config, config_location) ⇒ Object



128
129
130
131
132
133
# File 'lib/invoker.rb', line 128

def migrate_old_config(old_config, config_location)
  new_config = File.join(config_location, 'config')
  File.open(new_config, 'w') do |file|
    file.write(old_config)
  end
end

.notify_user(message) ⇒ Object



106
107
108
109
110
111
112
# File 'lib/invoker.rb', line 106

def notify_user(message)
  if Invoker.darwin?
    run_without_bundler { check_and_notify_with_terminal_notifier(message) }
  elsif Invoker.linux?
    notify_with_libnotify(message)
  end
end

.notify_with_libnotify(message) ⇒ Object



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

def notify_with_libnotify(message)
  begin
    require "libnotify"
    Libnotify.show(body: message, summary: "Invoker", timeout: 2.5)
  rescue LoadError; end
end

.ruby_platformObject



51
52
53
# File 'lib/invoker.rb', line 51

def ruby_platform
  RUBY_PLATFORM
end

.run_without_bundlerObject



96
97
98
99
100
101
102
103
104
# File 'lib/invoker.rb', line 96

def run_without_bundler
  if defined?(Bundler)
    Bundler.with_clean_env do
      yield
    end
  else
    yield
  end
end

.setup_config_locationObject



81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/invoker.rb', line 81

def setup_config_location
  config_dir = Invoker::Power::Config.config_dir
  return config_dir if Dir.exist?(config_dir)

  if File.exist?(config_dir)
    old_config = File.read(config_dir)
    FileUtils.rm_f(config_dir)
  end

  FileUtils.mkdir(config_dir)

  migrate_old_config(old_config, config_dir) if old_config
  config_dir
end