invoker 1.5.6 → 1.5.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: b041781f5abb31802fa52316895c2c1ad4142c78
4
- data.tar.gz: 63d084268289f696b8b689f564b007b833f323b6
2
+ SHA256:
3
+ metadata.gz: 55217109e2c3f44ebbbfd25c36f3b4d8d3dedff2c8380cc262cb12653cc1a1b1
4
+ data.tar.gz: 7f9e9a0d4a100d44549400473a81686d09773ee0d9d5ec8f193ccbee999bebe9
5
5
  SHA512:
6
- metadata.gz: 7356d438f44f82bc34d4dfa262bfda0a07b9048024ac905b56b72139a5dac08c7b007cc87e03f58c14c1862ebaf99878f2738316483183768f428aa6c20326b0
7
- data.tar.gz: cb55d77bee7313ff21eff64247c89452f7488fdbb6198f7944ba42e27aea638d6ca2c40867af1878e17e647ecc95cb0bf5c499ca912d0a101ee33b518580a3bb
6
+ metadata.gz: 4221997cbbcf54911d116f2dde24cc30ba91e36013f72b3ed1e392fcb96c0be43186f2837be0735da43932e09ddd1725452784ee2a3e7fd0b12928daebd7f337
7
+ data.tar.gz: f4c3a7697a1ce22121cce85e58770ad0a3fd8f816d731b82115c5b0dcba5cda404822d3a56b1710766171bf776c2cccb44223e8759974f9e231956e2125e2ef6
@@ -21,7 +21,6 @@ require "invoker/power/setup"
21
21
  require "invoker/power/setup/linux_setup"
22
22
  require "invoker/power/setup/osx_setup"
23
23
  require "invoker/power/powerup"
24
- require "invoker/power/pf_migrate"
25
24
  require "invoker/errors"
26
25
  require "invoker/parsers/procfile"
27
26
  require "invoker/parsers/config"
@@ -19,6 +19,7 @@ module Invoker
19
19
  def setup
20
20
  Invoker::Power::Setup.install(get_tld(options))
21
21
  end
22
+ map install: :setup
22
23
 
23
24
  desc "version", "Print Invoker version"
24
25
  def version
@@ -56,7 +57,6 @@ module Invoker
56
57
  Invoker.private_key = options[:private_key]
57
58
  Invoker.load_invoker_config(file, port)
58
59
  warn_about_notification
59
- warn_about_old_configuration
60
60
  pinger = Invoker::CLI::Pinger.new(unix_socket)
61
61
  abort("Invoker is already running".colorize(:red)) if pinger.invoker_running?
62
62
  Invoker.commander.start_manager
@@ -91,6 +91,7 @@ module Invoker
91
91
  signal = options[:signal] || 'INT'
92
92
  unix_socket.send_command('reload', process_name: name, signal: signal)
93
93
  end
94
+ map restart: :reload
94
95
 
95
96
  desc "list", "List all running processes"
96
97
  option :raw,
@@ -131,7 +132,7 @@ module Invoker
131
132
  end
132
133
 
133
134
  def self.valid_tasks
134
- tasks.keys + ["help"]
135
+ tasks.keys + %w(help install restart)
135
136
  end
136
137
 
137
138
  # TODO(kgrz): the default TLD option is duplicated in both this file and
@@ -172,12 +173,6 @@ module Invoker
172
173
  end
173
174
  end
174
175
  end
175
-
176
- def warn_about_old_configuration
177
- Invoker::Power::PfMigrate.new.tap do |pf_migrator|
178
- pf_migrator.migrate
179
- end
180
- end
181
176
  end
182
177
  end
183
178
 
@@ -133,10 +133,10 @@ module Invoker
133
133
  end
134
134
 
135
135
  sleep_duration = section['sleep'].to_i
136
- if sleep_duration > 0
136
+ if sleep_duration >= 0
137
137
  pconfig['sleep_duration'] = sleep_duration
138
138
  else
139
- pconfig['sleep_duration'] = 1
139
+ pconfig['sleep_duration'] = 0
140
140
  end
141
141
 
142
142
  OpenStruct.new(pconfig)
@@ -100,7 +100,7 @@ module Invoker
100
100
  @backend_data = true
101
101
 
102
102
  # check backend data for websockets connection. check for upgrade headers
103
- # - Upgarde: websocket\r\n
103
+ # - Upgrade: websocket\r\n
104
104
  if data =~ /Upgrade: websocket/
105
105
  @upgraded_to = "websocket"
106
106
  end
@@ -11,9 +11,11 @@ module Invoker
11
11
  end
12
12
 
13
13
  def self.uninstall
14
- power_config = Invoker::Power::Config.load_config
15
- selected_installer_klass = installer_klass
16
- selected_installer_klass.new(power_config.tld).uninstall_invoker
14
+ if Invoker::Power::Config.has_config?
15
+ power_config = Invoker::Power::Config.load_config
16
+ selected_installer_klass = installer_klass
17
+ selected_installer_klass.new(power_config.tld).uninstall_invoker
18
+ end
17
19
  end
18
20
 
19
21
  def self.installer_klass
@@ -74,6 +76,7 @@ module Invoker
74
76
  end
75
77
 
76
78
  def remove_resolver_file
79
+ return if resolver_file.nil?
77
80
  begin
78
81
  safe_remove_file(resolver_file)
79
82
  rescue Errno::EACCES
@@ -12,23 +12,19 @@ module Invoker
12
12
  end
13
13
 
14
14
  def self.distro_installer(tld)
15
- case Facter[:operatingsystem].value
16
- when "Ubuntu"
17
- require "invoker/power/setup/distro/ubuntu"
18
- Ubuntu.new(tld)
19
- when "Fedora"
20
- require "invoker/power/setup/distro/redhat"
21
- Redhat.new(tld)
22
- when "Archlinux"
15
+ if distro.start_with? "Arch Linux", "Manjaro Linux"
23
16
  require "invoker/power/setup/distro/arch"
24
17
  Arch.new(tld)
25
- when "Debian"
18
+ elsif distro.start_with? "Debian"
26
19
  require "invoker/power/setup/distro/debian"
27
20
  Debian.new(tld)
28
- when "LinuxMint"
29
- require "invoker/power/setup/distro/mint"
30
- Mint.new(tld)
31
- when "OpenSuSE"
21
+ elsif distro.start_with? "Fedora"
22
+ require "invoker/power/setup/distro/redhat"
23
+ Redhat.new(tld)
24
+ elsif distro.start_with? "Linux Mint", "Ubuntu"
25
+ require "invoker/power/setup/distro/ubuntu"
26
+ Ubuntu.new(tld)
27
+ elsif distro.start_with? "openSUSE"
32
28
  require "invoker/power/setup/distro/opensuse"
33
29
  Opensuse.new(tld)
34
30
  else
@@ -36,6 +32,17 @@ module Invoker
36
32
  end
37
33
  end
38
34
 
35
+ def self.distro
36
+ @distro ||= if File.exist?('/etc/os-release')
37
+ File.read('/etc/os-release').each_line do |line|
38
+ parsed_line = line.chomp.tr('"', '').split('=')
39
+ break parsed_line[1] if parsed_line[0] == 'NAME'
40
+ end
41
+ else
42
+ raise "File /etc/os-release doesn't exist or not Linux"
43
+ end
44
+ end
45
+
39
46
  def initialize(tld)
40
47
  self.tld = tld
41
48
  end
@@ -51,6 +58,22 @@ module Invoker
51
58
  system("systemctl start socat_invoker.service")
52
59
  system("systemctl restart dnsmasq")
53
60
  end
61
+
62
+ def install_packages
63
+ "dnsmasq and socat"
64
+ end
65
+
66
+ def install_other
67
+ " a local resolver for .#{tld} domain and"
68
+ end
69
+
70
+ def get_user_confirmation?
71
+ Invoker::Logger.puts("Invoker is going to install #{install_packages} on this machine."\
72
+ " It is also going to install#{install_other} a socat service"\
73
+ " which will forward all local requests on port 80 and 443 to another port")
74
+ Invoker::Logger.puts("If you still want to proceed with installation, press y.")
75
+ Invoker::CLI::Question.agree("Proceed with installation (y/n) : ")
76
+ end
54
77
  end
55
78
  end
56
79
  end
@@ -4,6 +4,42 @@ module Invoker
4
4
  module Power
5
5
  module Distro
6
6
  class Ubuntu < Debian
7
+ def using_systemd_resolved?
8
+ return @_using_systemd_resolved if defined?(@_using_systemd_resolved)
9
+ @_using_systemd_resolved = system("systemctl is-active --quiet systemd-resolved")
10
+ end
11
+
12
+ def install_required_software
13
+ if using_systemd_resolved?
14
+ # Don't install dnsmasq if Ubuntu version uses systemd-resolved for DNS because they conflict
15
+ system("apt-get --assume-yes install socat")
16
+ else
17
+ super
18
+ end
19
+ end
20
+
21
+ def install_packages
22
+ using_systemd_resolved? ? "socat" : super
23
+ end
24
+
25
+ def install_other
26
+ using_systemd_resolved? ? nil : super
27
+ end
28
+
29
+ def resolver_file
30
+ using_systemd_resolved? ? nil : super
31
+ end
32
+
33
+ def tld
34
+ using_systemd_resolved? ? 'localhost' : @tld
35
+ end
36
+
37
+ def get_user_confirmation?
38
+ if using_systemd_resolved? && tld != 'localhost'
39
+ Invoker::Logger.puts("Ubuntu installations using systemd-resolved (typically Ubuntu 17+) only support the .localhost domain, so your tld setting (or the default) will be ignored.".colorize(:yellow))
40
+ end
41
+ super
42
+ end
7
43
  end
8
44
  end
9
45
  end
@@ -1,5 +1,4 @@
1
1
  require "invoker/power/setup/distro/base"
2
- require "facter"
3
2
  require 'erb'
4
3
  require 'fileutils'
5
4
 
@@ -9,8 +8,8 @@ module Invoker
9
8
  attr_accessor :distro_installer
10
9
 
11
10
  def setup_invoker
12
- if get_user_confirmation?
13
- initialize_distro_installer
11
+ initialize_distro_installer
12
+ if distro_installer.get_user_confirmation?
14
13
  find_open_ports
15
14
  distro_installer.install_required_software
16
15
  install_resolver
@@ -35,6 +34,12 @@ module Invoker
35
34
  Invoker::Power::Config.delete
36
35
  end
37
36
 
37
+ def build_power_config
38
+ config = super
39
+ config[:tld] = distro_installer.tld
40
+ config
41
+ end
42
+
38
43
  def resolver_file
39
44
  distro_installer.resolver_file
40
45
  end
@@ -50,16 +55,11 @@ module Invoker
50
55
  private
51
56
 
52
57
  def initialize_distro_installer
53
- # Create a new facter check for systemctl (in systemd)
54
- Facter.add(:systemctl) do
55
- setcode do
56
- Facter::Util::Resolution.exec("[ -e /usr/bin/systemctl ] && echo 'true' || echo 'false'")
57
- end
58
- end
59
- @distro_installer = Invoker::Power::Distro::Base.distro_installer(tld)
58
+ @distro_installer ||= Invoker::Power::Distro::Base.distro_installer(tld)
60
59
  end
61
60
 
62
61
  def install_resolver
62
+ return if resolver_file.nil?
63
63
  File.open(resolver_file, "w") do |fl|
64
64
  fl.write(resolver_file_content)
65
65
  end
@@ -92,14 +92,6 @@ address=/#{tld}/127.0.0.1
92
92
  FileUtils.cp(socat_unit, Invoker::Power::Distro::Base::SOCAT_SYSTEMD)
93
93
  system("chmod 644 #{Invoker::Power::Distro::Base::SOCAT_SYSTEMD}")
94
94
  end
95
-
96
- def get_user_confirmation?
97
- Invoker::Logger.puts("Invoker is going to install dnsmasq and socat on this machine."\
98
- " It is also going to install a local resolver for .#{tld} domain and a socat service"\
99
- " which will forward all local requests on port 80 and 443 to another port")
100
- Invoker::Logger.puts("If you still want to proceed with installation, press y.")
101
- Invoker::CLI::Question.agree("Proceed with installation (y/n) : ")
102
- end
103
95
  end
104
96
  end
105
97
  end
@@ -168,6 +168,9 @@ module Invoker
168
168
  if worker
169
169
  @open_pipes.delete(worker.pipe_end.fileno)
170
170
  @workers.delete(command_label)
171
+ # Move label color to front of array so it's reused first
172
+ LABEL_COLORS.delete(worker.color)
173
+ LABEL_COLORS.unshift(worker.color)
171
174
  end
172
175
  if trigger_event
173
176
  Invoker.commander.trigger(command_label, :worker_removed)
@@ -43,5 +43,5 @@ module Invoker
43
43
  Version.new(next_splits.join('.'))
44
44
  end
45
45
  end
46
- VERSION = "1.5.6"
46
+ VERSION = "1.5.7"
47
47
  end
@@ -155,7 +155,7 @@ command = ls
155
155
 
156
156
  describe "Procfile" do
157
157
  it "should load Procfiles and create config object" do
158
- File.open("/tmp/Procfile", "w") {|fl|
158
+ File.open("/tmp/Procfile", "w") {|fl|
159
159
  fl.write <<-EOD
160
160
  web: bundle exec rails s -p $PORT
161
161
  EOD
@@ -170,7 +170,7 @@ web: bundle exec rails s -p $PORT
170
170
 
171
171
  describe "Copy of DNS information" do
172
172
  it "should allow copy of DNS information" do
173
- File.open("/tmp/Procfile", "w") {|fl|
173
+ File.open("/tmp/Procfile", "w") {|fl|
174
174
  fl.write <<-EOD
175
175
  web: bundle exec rails s -p $PORT
176
176
  EOD
@@ -251,7 +251,7 @@ index = 1
251
251
  config = Invoker::Parsers::Config.new(file.path, 9000)
252
252
  processes = config.autorunnable_processes
253
253
  expect(processes.map(&:label)).to eq(['panda-auth', 'postgres', 'memcached'])
254
- expect(processes[0].sleep_duration).to eq(1)
254
+ expect(processes[0].sleep_duration).to eq(0)
255
255
  expect(processes[1].sleep_duration).to eq(5)
256
256
  ensure
257
257
  file.unlink()
@@ -342,7 +342,7 @@ some_other_process: some_other_command
342
342
  expect(config.process("some_process").cmd).to eq("some_command")
343
343
  processes = config.autorunnable_processes
344
344
  process_1 = processes[0]
345
- expect(process_1.sleep_duration).to eq(1)
345
+ expect(process_1.sleep_duration).to eq(0)
346
346
  expect(process_1.index).to eq(0)
347
347
  ensure
348
348
  File.delete(invoker_ini)
@@ -16,43 +16,55 @@ def mock_socat_scripts
16
16
  fl.write(socat_content)
17
17
  end
18
18
  FileUtils.mkdir_p("/usr/bin")
19
+ FileUtils.mkdir_p("/etc/systemd/system")
19
20
  end
20
21
 
21
22
  describe Invoker::Power::LinuxSetup, fakefs: true do
22
23
  before do
23
24
  FileUtils.mkdir_p(inv_conf_dir)
24
25
  FileUtils.mkdir_p(Invoker::Power::Distro::Base::RESOLVER_DIR)
26
+ Invoker.config = mock
25
27
  end
26
28
 
27
29
  let(:invoker_setup) { Invoker::Power::LinuxSetup.new('test') }
28
30
  let(:distro_installer) { Invoker::Power::Distro::Ubuntu.new('test') }
29
31
 
30
- describe "should only proceed after user confirmation" do
31
- before { invoker_setup.distro_installer = distro_installer }
32
+ before do
33
+ invoker_setup.distro_installer = distro_installer
34
+ end
32
35
 
33
- it "should create config file with port" do
34
- invoker_setup.expects(:initialize_distro_installer).returns(true)
35
- invoker_setup.expects(:get_user_confirmation?).returns(true)
36
- invoker_setup.expects(:install_resolver).returns(true)
37
- invoker_setup.expects(:install_port_forwarder).returns(true)
38
- invoker_setup.expects(:drop_to_normal_user).returns(true)
36
+ it "should only proceed after user confirmation" do
37
+ distro_installer.expects(:get_user_confirmation?).returns(false)
39
38
 
40
- distro_installer.expects(:install_required_software)
41
- distro_installer.expects(:restart_services)
39
+ invoker_setup.setup_invoker
42
40
 
43
- invoker_setup.setup_invoker
41
+ expect { Invoker::Power::Config.load_config }.to raise_error(Errno::ENOENT)
42
+ end
44
43
 
45
- config = Invoker::Power::Config.load_config
46
- expect(config.http_port).not_to be_nil
47
- expect(config.dns_port).to be_nil
48
- expect(config.https_port).not_to be_nil
49
- end
44
+ it "should create config file with http(s) ports" do
45
+ invoker_setup.expects(:initialize_distro_installer).returns(true)
46
+ invoker_setup.expects(:install_resolver).returns(true)
47
+ invoker_setup.expects(:install_port_forwarder).returns(true)
48
+ invoker_setup.expects(:drop_to_normal_user).returns(true)
49
+
50
+ distro_installer.expects(:get_user_confirmation?).returns(true)
51
+ distro_installer.expects(:install_required_software)
52
+ distro_installer.expects(:restart_services)
53
+
54
+ invoker_setup.setup_invoker
55
+
56
+ config = Invoker::Power::Config.load_config
57
+ expect(config.tld).to eq('test')
58
+ expect(config.http_port).not_to be_nil
59
+ expect(config.dns_port).to be_nil
60
+ expect(config.https_port).not_to be_nil
50
61
  end
51
62
 
52
- describe "configuring dnsmasq and socat" do
63
+ describe "configuring services" do
64
+ let(:config) { Invoker::Power::Config.load_config }
65
+
53
66
  before(:all) do
54
67
  @original_invoker_config = Invoker.config
55
- Invoker.config = mock
56
68
  end
57
69
 
58
70
  after(:all) do
@@ -60,26 +72,21 @@ describe Invoker::Power::LinuxSetup, fakefs: true do
60
72
  end
61
73
 
62
74
  before(:each) do
63
- invoker_setup.distro_installer = distro_installer
64
75
  mock_socat_scripts
65
76
  end
66
77
 
67
- it "should create proper config file" do
78
+ def run_setup
68
79
  invoker_setup.expects(:initialize_distro_installer).returns(true)
69
- invoker_setup.expects(:get_user_confirmation?).returns(true)
70
80
  invoker_setup.expects(:drop_to_normal_user).returns(true)
71
81
 
82
+ distro_installer.expects(:get_user_confirmation?).returns(true)
72
83
  distro_installer.expects(:install_required_software)
73
84
  distro_installer.expects(:restart_services)
74
85
 
75
86
  invoker_setup.setup_invoker
87
+ end
76
88
 
77
- config = Invoker::Power::Config.load_config
78
-
79
- dnsmasq_content = File.read(distro_installer.resolver_file)
80
- expect(dnsmasq_content.strip).to_not be_empty
81
- expect(dnsmasq_content).to match(/test/)
82
-
89
+ def test_socat_config
83
90
  socat_content = File.read(Invoker::Power::Distro::Base::SOCAT_SHELLSCRIPT)
84
91
  expect(socat_content.strip).to_not be_empty
85
92
  expect(socat_content.strip).to match(/#{config.https_port}/)
@@ -88,15 +95,71 @@ describe Invoker::Power::LinuxSetup, fakefs: true do
88
95
  service_file = File.read(Invoker::Power::Distro::Base::SOCAT_SYSTEMD)
89
96
  expect(service_file.strip).to_not be_empty
90
97
  end
98
+
99
+ context 'on ubuntu with systemd-resolved' do
100
+ it "should create socat config & set tld to localhost" do
101
+ distro_installer.expects(:using_systemd_resolved?).at_least_once.returns(true)
102
+ run_setup
103
+ expect(distro_installer.resolver_file).to be_nil
104
+ test_socat_config
105
+ expect(config.tld).to eq('localhost')
106
+ end
107
+ end
108
+
109
+ context 'on non-systemd-resolved distro' do
110
+ it "should create dnsmasq & socat configs" do
111
+ run_setup
112
+ dnsmasq_content = File.read(distro_installer.resolver_file)
113
+ expect(dnsmasq_content.strip).to_not be_empty
114
+ expect(dnsmasq_content).to match(/test/)
115
+
116
+ test_socat_config
117
+ end
118
+ end
91
119
  end
92
120
 
93
121
  describe 'resolver file' do
94
122
  context 'user sets up a custom top level domain' do
95
- it 'should create the correct resolver file' do
96
- linux_setup = Invoker::Power::LinuxSetup.new('local')
97
- suse_installer = Invoker::Power::Distro::Opensuse.new('local')
98
- linux_setup.distro_installer = suse_installer
99
- expect(linux_setup.resolver_file).to eq('/etc/dnsmasq.d/local-tld')
123
+ let(:tld) { 'local' }
124
+ let(:linux_setup) { Invoker::Power::LinuxSetup.new(tld) }
125
+
126
+ context 'on ubuntu with systemd-resolved' do
127
+ it 'should not create a resolver file' do
128
+ ubuntu_installer = Invoker::Power::Distro::Ubuntu.new(tld)
129
+ linux_setup.distro_installer = ubuntu_installer
130
+ ubuntu_installer.expects(:using_systemd_resolved?).at_least_once.returns(true)
131
+ expect(linux_setup.resolver_file).to eq(nil)
132
+ end
133
+ end
134
+
135
+ context 'on non-systemd-resolved distro' do
136
+ it 'should create the correct resolver file' do
137
+ suse_installer = Invoker::Power::Distro::Opensuse.new(tld)
138
+ linux_setup.distro_installer = suse_installer
139
+ expect(linux_setup.resolver_file).to eq("/etc/dnsmasq.d/#{tld}-tld")
140
+ end
141
+ end
142
+ end
143
+ end
144
+ end
145
+
146
+ describe Invoker::Power::Distro::Base, docker: true do
147
+ describe '.distro_installer' do
148
+ it 'correctly recognizes the current distro' do
149
+ case ENV['DISTRO']
150
+ when 'archlinux/base', 'manjarolinux/base'
151
+ expect(described_class.distro_installer('')).to be_a Invoker::Power::Distro::Arch
152
+ when 'debian'
153
+ expect(described_class.distro_installer('')).to be_a Invoker::Power::Distro::Debian
154
+ when 'fedora'
155
+ expect(described_class.distro_installer('')).to be_a Invoker::Power::Distro::Redhat
156
+ when 'linuxmintd/mint20-amd64', 'ubuntu'
157
+ expect(described_class.distro_installer('')).to be_a Invoker::Power::Distro::Ubuntu
158
+ when 'opensuse/leap', 'opensuse/tumbleweed'
159
+ expect(described_class.distro_installer('')).to be_a Invoker::Power::Distro::Opensuse
160
+ when nil
161
+ else
162
+ raise 'Unrecognized Linux distro. Please add the appropriate docker image to the travis build matrix, update the described method, and add a case here.'
100
163
  end
101
164
  end
102
165
  end