brisk 0.2.1 → 0.2.2

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
  SHA1:
3
- metadata.gz: 76fbd2e35a7b55d3bd7601cb83f8536c0614f4a6
4
- data.tar.gz: aeb7b76485f8cd579b477b8f690ab80837020901
3
+ metadata.gz: ffba212e4a0a9322a6367d04872200d2862e1052
4
+ data.tar.gz: a67db63ef02e8581542ff3e56fba940945adcb6d
5
5
  SHA512:
6
- metadata.gz: 769b4414c67e1a44a74911e9de84625b61a7120361119232d87cd7e4e48016ab8361a192bb15751d925ff345e5dca910d8b0b65e8acf47436db1d09c4cfdf08d
7
- data.tar.gz: e5a7a6c482986629f202b79dd294b46682ea89ce0bcb17c38885e9e84a763bf87f87d6940876d708af8209d3269de9f51fd6a13306ef6eee7b721c3a1976ae03
6
+ metadata.gz: 8281b3c315bd1cf328e4df8efe879c7a05ffc5b1c9c75782ab9e962ef1e45525375cb5025efc282f5f0ac592dc50d9d777afa8334bb469b13af8ea59387064af
7
+ data.tar.gz: a3732fdfbc01e746cb27e8f03fd03059279a48f7d2fa000d27e5da0baa011cf5fee0c370f947e87350ca6c4c5cef4c2a1fbd91b931ba2b6ca9b0257380105d09
@@ -4,6 +4,14 @@ require 'brisk/file_system'
4
4
 
5
5
  class Caddy
6
6
 
7
+ @caddy_path = File.expand_path("../../stubs/Caddyfile", __dir__)
8
+ @caddy_daemon_path = "/Library/LaunchDaemons/com.frankleef.caddyBriskServer.plist"
9
+ class << self
10
+ attr_accessor :caddy_path
11
+ attr_accessor :caddy_daemon_path
12
+ end
13
+
14
+
7
15
  def self.install
8
16
  unless is_installed?
9
17
  puts "Installing Caddy for you...".colorize(:green)
@@ -26,7 +34,7 @@ class Caddy
26
34
  end
27
35
 
28
36
  def self.install_caddy_file
29
- FileSystem.copy_file(File.expand_path("../../stubs/Caddyfile", __dir__), Constants.valet_home + '/Caddyfile')
37
+ FileSystem.copy_file(caddy_path, Constants.valet_home + '/Caddyfile')
30
38
  file = FileSystem.read(Constants.valet_home + '/Caddyfile')
31
39
  new_file = file.gsub("BRISK_HOME_PATH", Constants.valet_home)
32
40
  File.write(Constants.valet_home + '/Caddyfile', new_file)
@@ -41,7 +49,7 @@ class Caddy
41
49
  path = FileSystem.get_path("../../stubs/caddy_daemon.plist", __dir__)
42
50
  file = FileSystem.read(path)
43
51
  new_file = file.gsub("BRISK_HOME_PATH", Constants.valet_home)
44
- FileSystem.write("/Library/LaunchDaemons/com.frankleef.caddyBriskServer.plist", new_file)
52
+ FileSystem.write(caddy_daemon_path, new_file)
45
53
  end
46
54
 
47
55
  def self.restart
@@ -2,16 +2,17 @@ require 'brisk/file_system'
2
2
 
3
3
  class Pid
4
4
 
5
- def self.get(port)
6
- `sudo lsof -i tcp:#{port} | grep ruby | awk '{ print $2; }'`
7
- end
8
-
9
5
  def self.write(path, pid)
10
6
  FileSystem.write("#{path}/pid.txt", pid)
11
7
 
12
8
  sleep(1)
13
9
  end
14
10
 
11
+ def self.write_https(path, pid)
12
+ FileSystem.write("#{path}/https_pid.txt", pid)
13
+ sleep(1)
14
+ end
15
+
15
16
  def self.read(path)
16
17
  FileSystem.read("#{path}/tmp/pids/thin.pid")
17
18
  end
@@ -19,13 +19,6 @@ class AppProxy < Rack::Proxy
19
19
  config = request.get_config
20
20
  site_path = Site.get_site_paths(config, site)
21
21
 
22
- port = "3001"
23
- port = "3003" if Site.is_secured?(config, site)
24
-
25
- # Check if site is running
26
- # check if site is equal to written site
27
- # Check if site is secured
28
- # otherwise, kill process
29
22
  # Kill existing servers, so we don't get conflitcs
30
23
  if Server.is_running(valet_home_path)
31
24
 
@@ -41,7 +34,9 @@ class AppProxy < Rack::Proxy
41
34
  return env
42
35
  end
43
36
 
44
- existing_pid = Pid.get(port)
37
+ existing_pid = FileSystem.read("#{valet_home_path}/pid.txt") if FileSystem.file_exists?("#{valet_home_path}/pid.txt")
38
+ existing_pid = FileSystem.read("#{valet_home_path}/https_pid.txt") if Site.is_secured?(config, site)
39
+ puts existing_pid
45
40
  Server.shutdown(existing_pid)
46
41
  end
47
42
 
@@ -50,10 +45,12 @@ class AppProxy < Rack::Proxy
50
45
 
51
46
  Server.start_https(site_path)
52
47
  # Check if proccess is up and running
53
- started = Server.is_started(site_path, port)
48
+ started = Server.is_started(site_path)
54
49
 
55
- # Write the pid to a file so we can delete it later on
50
+ # Write the pid to a file so we can delete it later on
56
51
  if started
52
+ pid = Pid.read(site_path)
53
+ Pid.write_https(valet_home_path, pid)
57
54
  Site.write_site(valet_home_path, site)
58
55
  end
59
56
 
@@ -69,10 +66,12 @@ class AppProxy < Rack::Proxy
69
66
  Server.start(site_path)
70
67
 
71
68
  # Check if proccess is up and running
72
- started = Server.is_started(site_path, port)
69
+ started = Server.is_started(site_path)
73
70
 
74
71
  # Write the pid to a file so we can delete it later on
75
72
  if started
73
+ pid = Pid.read(site_path)
74
+ Pid.write(valet_home_path, pid)
76
75
  Site.write_site(valet_home_path, site)
77
76
  end
78
77
 
@@ -4,18 +4,13 @@ require 'brisk/file_system'
4
4
  class Server
5
5
 
6
6
  def self.is_running(path)
7
- FileSystem.file_exists?("#{path}/pid.txt")
7
+ FileSystem.file_exists?("#{path}/pid.txt") || FileSystem.file_exists?("#{path}/https_pid.txt")
8
8
  end
9
9
 
10
10
  def self.kill(path)
11
- http = Pid.get("3001")
12
- https = Pid.get("3003")
13
- unless http.nil?
14
- shutdown http
15
- end
16
-
17
- unless https.nil?
18
- shutdown https
11
+ if is_running(path)
12
+ pid = FileSystem.read("#{path}/pid.txt")
13
+ shutdown pid
19
14
  end
20
15
  end
21
16
 
@@ -27,18 +22,17 @@ class Server
27
22
  spawn "cd #{path} && /usr/local/bin/thin start -d -R config.ru -a localhost -p 3003 --ssl"
28
23
  end
29
24
 
30
- def self.is_started(path, port)
25
+ def self.is_started(path, counter = 0)
31
26
  sleep(0.5)
32
27
 
33
- pid = Pid.get(port)
34
-
35
- unless pid.nil?
28
+ if Pid.exists?(path)
29
+ pid = Pid.read(path)
36
30
  if Pid.alive?(pid)
37
31
  return true
38
32
  end
39
33
  end
40
34
 
41
- is_started(path, port)
35
+ is_started(path, counter + 1)
42
36
  end
43
37
 
44
38
  def self.shutdown(pid)
@@ -2,6 +2,14 @@ require 'colorize'
2
2
 
3
3
  class Thin
4
4
 
5
+ @thin_daemon = "/Library/LaunchDaemons/com.frankleef.briskServer.plist"
6
+ @thin_secure_daemon = "/Library/LaunchDaemons/com.frankleef.briskSecureServer.plist"
7
+
8
+ class << self
9
+ attr_accessor :thin_daemon
10
+ attr_accessor :thin_secure_daemon
11
+ end
12
+
5
13
  def self.install
6
14
  unless is_installed?
7
15
 
@@ -33,7 +41,7 @@ class Thin
33
41
 
34
42
  new_file = file.gsub("SERVER_PATH", server)
35
43
 
36
- FileSystem.write("/Library/LaunchDaemons/com.frankleef.briskServer.plist", new_file)
44
+ FileSystem.write(thin_daemon, new_file)
37
45
  end
38
46
 
39
47
  def self.install_secure_daemon
@@ -43,7 +51,7 @@ class Thin
43
51
  file = FileSystem.read(path)
44
52
 
45
53
  new_file = file.gsub("SERVER_PATH", server)
46
- FileSystem.write("/Library/LaunchDaemons/com.frankleef.briskSecureServer.plist", new_file)
54
+ FileSystem.write(thin_secure_daemon, new_file)
47
55
  end
48
56
 
49
57
  def self.install_site_daemon
@@ -1,3 +1,3 @@
1
1
  module Brisk
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brisk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frank
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-19 00:00:00.000000000 Z
11
+ date: 2016-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler