ngrok-wrapper 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 270d9efa417c5821721519760816d3febbf085d183680ad0268a244eaec4a753
4
- data.tar.gz: dd477aa0effed04807720dd6e22a3f607b79f88b343318c7d1674c18e573b056
3
+ metadata.gz: 73d4023376c99fae6a7c7c0e5461e1fb2fe91d83531bc77e35252e42e87a9795
4
+ data.tar.gz: 61eecae9040ebbe584b02cacea0c0a41a84d928dd6ebe7964c20f4b391e155e4
5
5
  SHA512:
6
- metadata.gz: e8d752ee9ee727a5e54705e1c7d361b6babd13415a68173325df4cf4a2c7158fa37cc60920b8023e9b57b45c1ce1450325bcc17949885045ff1f1d3b9bebcb7a
7
- data.tar.gz: 7f3e3c5404e138e6f4a01ed06c77d13f746bc977057b91494a26f98f80fa59fa2c55b992cf6bf015142e6bc38ff4fc1fcd73e5537e77018801a8b945e9b33623
6
+ metadata.gz: e20e1589b5b0e375acbbd59b0c6e7b472906a1f54534e6695492926fdad36b1aeec2a25fef568fb7527d9416c7a4cae78296473733ccb4166b8c6bbaec95ead4
7
+ data.tar.gz: 237102d6642b6f58f5be5e9b35dfe9782863f93662df84c6a9864728df9103c67e4bf12badc87fa481e80b7156b636caab7ecd7058dfb44467e4420968dc191d
data/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # Changelog
2
2
 
3
+ ## [v0.2.0](https://github.com/texpert/ngrok-wrapper/tree/v0.2.0) (2022-02-19)
4
+
5
+ ### Making Ngrok process survive server stop on Linux
6
+
7
+ It was working OK on Mac OS on the 0.1.0 release, but not on Linux.
8
+
9
+ It came out that `Process.setsid` should be applied to the spawned process to establish this process as a new session
10
+ and process group leader. This is completely detaching it from the parent process, so it won't be killed when the
11
+ parent will go down.
12
+
13
+ [Full Changelog](https://github.com/texpert/ngrok-wrapper/compare/v0.1.0...v0.2.0)
14
+
15
+ **Merged pull requests:**
16
+
17
+ - Add config.hosts example for Rails \>= 6.0.0 [\#18](https://github.com/texpert/ngrok-wrapper/pull/18) ([texpert](https://github.com/texpert))
18
+ - Ngrok.start should try to return first @ngrok\_url\_https or then @ngrok\_url [\#17](https://github.com/texpert/ngrok-wrapper/pull/17) ([texpert](https://github.com/texpert))
19
+ - Use fork, Process.setsid and spawn instead of just spawn, to change the owner of ngrok process [\#16](https://github.com/texpert/ngrok-wrapper/pull/16) ([texpert](https://github.com/texpert))
20
+
3
21
  ## [v0.1.0](https://github.com/texpert/ngrok-wrapper/tree/v0.1.0) (2022-01-09)
4
22
 
5
23
  [Full Changelog](https://github.com/texpert/ngrok-wrapper/compare/3e032fa019c91ee7338a7ad3a3335e6c5597b394...v0.1.0)
data/README.md CHANGED
@@ -140,6 +140,7 @@ end
140
140
 
141
141
  ```ruby
142
142
  config.force_ssl = true if NGROK_ENABLED
143
+ config.hosts << '.ngrok.io' if NGROK_ENABLED # for Rails >= 6.0.0
143
144
 
144
145
  config.action_mailer.default_url_options = {
145
146
  host: NGROK_ENABLED ? NGROK_URL.delete_prefix('https://') : 'myapp.local',
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Ngrok
4
4
  class Wrapper
5
- VERSION = '0.1.0'
5
+ VERSION = '0.2.0'
6
6
  end
7
7
  end
data/lib/ngrok/wrapper.rb CHANGED
@@ -38,7 +38,7 @@ module Ngrok
38
38
  File.write(@persistence_file, { pid: @pid, ngrok_url: @ngrok_url, ngrok_url_https: @ngrok_url_https }.to_json)
39
39
  end
40
40
 
41
- @ngrok_url
41
+ @ngrok_url_https || @ngrok_url
42
42
  end
43
43
 
44
44
  def stop
@@ -104,7 +104,7 @@ module Ngrok
104
104
  def ngrok_process_status_lines(refetch: false)
105
105
  return @ngrok_process_status_lines if defined?(@ngrok_process_status_lines) && !refetch
106
106
 
107
- @ngrok_process_status_lines = (`ps ax | grep "ngrok http"`).split("\n")
107
+ @ngrok_process_status_lines = (`ps ax | grep "ngrok http"`).split("\n").map(&:strip)
108
108
  end
109
109
 
110
110
  def try_params_from_running_ngrok
@@ -134,7 +134,13 @@ module Ngrok
134
134
  # Prepare the log file into which ngrok output will be redirected in `ngrok_exec_params`
135
135
  @params[:log] = @params[:log] ? File.open(@params[:log], 'w+') : Tempfile.new('ngrok')
136
136
  if persistent_ngrok
137
- Process.spawn("exec nohup ngrok http #{ngrok_exec_params} &")
137
+ fork do
138
+ Process.setsid
139
+ system("exec nohup ngrok http #{ngrok_exec_params} &")
140
+ end
141
+
142
+ sleep 0.5
143
+
138
144
  @pid = ngrok_process_status_lines(refetch: true)
139
145
  .find { |line| line.include?('ngrok http -log') && line.end_with?(addr.to_s) }.split[0]
140
146
  else
@@ -260,12 +260,13 @@ RSpec.describe 'Ngrok::Wrapper' do
260
260
  it 'set Ngrok::Wrapper pid and status attributes' do
261
261
  expect(Ngrok::Wrapper).not_to receive(:spawn_new_ngrok)
262
262
 
263
- Ngrok::Wrapper.start(persistence: true)
263
+ result = Ngrok::Wrapper.start(persistence: true)
264
264
 
265
265
  expect(Ngrok::Wrapper.pid).to eql('795')
266
266
  expect(Ngrok::Wrapper.status).to eql(:running)
267
267
  expect(Ngrok::Wrapper.ngrok_url).to eql('http://b1cd-109-185-141-9.ngrok.io')
268
268
  expect(Ngrok::Wrapper.ngrok_url_https).to eql('https://b1cd-109-185-141-9.ngrok.io')
269
+ expect(result).to eql('https://b1cd-109-185-141-9.ngrok.io')
269
270
  end
270
271
  end
271
272
 
@@ -306,13 +307,14 @@ RSpec.describe 'Ngrok::Wrapper' do
306
307
 
307
308
  it 'sets Ngrok::Wrapper pid and status attributes' do
308
309
  allow(Ngrok::Wrapper).to receive(:spawn_new_ngrok).with(persistent_ngrok: true).and_call_original
310
+ allow(Ngrok::Wrapper).to receive(:fork).and_call_original
309
311
  allow(Ngrok::Wrapper)
310
312
  .to receive(:ngrok_process_status_lines).with(refetch: true).and_return(new_ngrok_ps_lines)
311
313
  allow(Ngrok::Wrapper).to receive(:fetch_urls)
312
314
 
313
315
  expect(Ngrok::Wrapper).to receive(:spawn_new_ngrok).with(persistent_ngrok: true)
314
- expect(Ngrok::Wrapper)
315
- .to receive(:ngrok_process_status_lines).with(refetch: true)
316
+ expect(Ngrok::Wrapper).to receive(:fork)
317
+ expect(Ngrok::Wrapper).to receive(:ngrok_process_status_lines).with(refetch: true)
316
318
  allow(Ngrok::Wrapper).to receive(:fetch_urls)
317
319
 
318
320
  Ngrok::Wrapper.start(persistence: true)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ngrok-wrapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton Bogdanovich
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-01-09 00:00:00.000000000 Z
12
+ date: 2022-02-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: github_changelog_generator