spurious-server 0.5.2 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/spurious-server +2 -14
- data/lib/spurious/server.rb +0 -19
- data/lib/spurious/server/cli.rb +135 -0
- data/lib/spurious/server/version.rb +1 -1
- data/spurious-server.gemspec +2 -2
- metadata +19 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 09edc583e4d202cb5264cd24d4d55d75f760fcef
|
4
|
+
data.tar.gz: e2343933109309a60eb97a5cfc589d509e741361
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e8abc2507d5528b743371b1948dda9a427479318061e1fa4f00a1de7647ecfc71b489936a0b89fe236251314b14eeb88a41522b02802ec040b7e540d986adfff
|
7
|
+
data.tar.gz: 5d6ad8c5d6f430297e4397eb9b85719f840802d75840766756ff32dc29a1536d9b7df43d9bfff0c311bf60f34d879fde03c246e1d1e88bf8c67f16f299815301
|
data/bin/spurious-server
CHANGED
@@ -2,18 +2,6 @@
|
|
2
2
|
|
3
3
|
$: << File.join(File.dirname(__FILE__), '..', 'lib')
|
4
4
|
|
5
|
-
require
|
6
|
-
require 'spurious/server/version'
|
7
|
-
require 'daemons'
|
8
|
-
require 'eventmachine'
|
9
|
-
require 'em-synchrony'
|
10
|
-
require 'spurious/server/options'
|
5
|
+
require "spurious/server/cli"
|
11
6
|
|
12
|
-
|
13
|
-
ENV['DOCKER_HOST'] = options.ssl_docker_host
|
14
|
-
|
15
|
-
if Spurious::Server.docker_daemon_available? ARGV[0]
|
16
|
-
Daemons.run_proc('.spurious-server', :dir => '~/') do
|
17
|
-
EventMachine.synchrony Spurious::Server.handle(options)
|
18
|
-
end
|
19
|
-
end
|
7
|
+
Spurious::Server::CLI.start
|
data/lib/spurious/server.rb
CHANGED
@@ -4,24 +4,6 @@ require "spurious/server/app"
|
|
4
4
|
|
5
5
|
module Spurious
|
6
6
|
module Server
|
7
|
-
|
8
|
-
TIMEOUT = 5
|
9
|
-
SHELL_RED = "\e[31m"
|
10
|
-
SHELL_GREEN = "\e[32m"
|
11
|
-
SHELL_CLEAR = "\e[0m"
|
12
|
-
|
13
|
-
def self.docker_daemon_available?(daemon_action)
|
14
|
-
if daemon_action == 'start'
|
15
|
-
puts "#{SHELL_GREEN} Checking docker daemon is available...#{SHELL_CLEAR}"
|
16
|
-
Excon.defaults[:connect_timeout] = Excon.defaults[:read_timeout] = TIMEOUT
|
17
|
-
!Docker.info.nil?
|
18
|
-
end
|
19
|
-
true
|
20
|
-
rescue Excon::Errors::SocketError, Excon::Errors::Timeout, Docker::Error::TimeoutError => e
|
21
|
-
puts "#{SHELL_RED} Connecting to the docker daemon (#{ENV["DOCKER_HOST"]}) failed... Check that it's running"
|
22
|
-
exit -1
|
23
|
-
end
|
24
|
-
|
25
7
|
def self.handle(options)
|
26
8
|
Proc.new do
|
27
9
|
EventMachine.start_server(
|
@@ -32,6 +14,5 @@ module Spurious
|
|
32
14
|
)
|
33
15
|
end
|
34
16
|
end
|
35
|
-
|
36
17
|
end
|
37
18
|
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
require "thor"
|
2
|
+
require "spurious/server"
|
3
|
+
require "spurious/server/options"
|
4
|
+
require "eventmachine"
|
5
|
+
require "em-synchrony"
|
6
|
+
require "spoon"
|
7
|
+
|
8
|
+
module Spurious
|
9
|
+
module Server
|
10
|
+
class CLI < Thor
|
11
|
+
include Thor::Actions
|
12
|
+
|
13
|
+
PID = File.expand_path "~/.spurious-server.pid"
|
14
|
+
TIMEOUT = 5
|
15
|
+
|
16
|
+
namespace :"spurious-server"
|
17
|
+
|
18
|
+
desc "start", "Starts the spurious-server as a daemon"
|
19
|
+
def start
|
20
|
+
check_and_clear_id
|
21
|
+
if docker_daemon_available?
|
22
|
+
say "Starting server...", :blue
|
23
|
+
pid = can_fork? ? Process.fork(&server_proc) : Spoon.spawn(bin_path, "run-proc")
|
24
|
+
say "Started with pid: ##{pid}", :green
|
25
|
+
File.write(PID, pid)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
desc "status", "Shows the status of the spurious-server daemon"
|
30
|
+
def status
|
31
|
+
message = pid_exists? ? "Server running (pid: ##{pid})" : "Server not running"
|
32
|
+
status = pid_exists? ? :green : :red
|
33
|
+
say message, status
|
34
|
+
end
|
35
|
+
|
36
|
+
desc "stop", "Stops the spurious-server daemon"
|
37
|
+
def stop
|
38
|
+
error "Server isn't running..." unless pid_exists?
|
39
|
+
error "Process isn't runnng..." unless is_process_running?
|
40
|
+
|
41
|
+
say "Stopping server...", :blue
|
42
|
+
kill_process!
|
43
|
+
say "Server successfully stopped", :green
|
44
|
+
end
|
45
|
+
|
46
|
+
desc "run-proc", "Runs the server proc"
|
47
|
+
def run_proc
|
48
|
+
server_proc.call
|
49
|
+
end
|
50
|
+
|
51
|
+
desc "restart", "Restarts the spurious-server daemon"
|
52
|
+
def restart
|
53
|
+
stop
|
54
|
+
start
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def remove_pid!
|
60
|
+
File.delete PID
|
61
|
+
end
|
62
|
+
|
63
|
+
def kill_process!
|
64
|
+
Process.kill("HUP", pid)
|
65
|
+
remove_pid!
|
66
|
+
end
|
67
|
+
|
68
|
+
def docker_daemon_available?
|
69
|
+
say "Checking is docker daemon is available...", :blue
|
70
|
+
Excon.defaults[:connect_timeout] = Excon.defaults[:read_timeout] = TIMEOUT
|
71
|
+
Docker.info
|
72
|
+
true
|
73
|
+
rescue Excon::Errors::SocketError, Excon::Errors::Timeout, Docker::Error::TimeoutError => e
|
74
|
+
error "Connection to the docker daemon (#{ENV["DOCKER_HOST"]}) failed... Check that it's running"
|
75
|
+
false
|
76
|
+
end
|
77
|
+
|
78
|
+
def server_proc
|
79
|
+
options = Spurious::Server::Options.new ENV
|
80
|
+
ENV["DOCKER_HOST"] = options.ssl_docker_host
|
81
|
+
|
82
|
+
Proc.new do
|
83
|
+
EventMachine.synchrony Spurious::Server.handle(options)
|
84
|
+
exit
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def check_and_clear_id
|
89
|
+
if pid_exists? && ! is_process_running?
|
90
|
+
say "Process isn't running but PID file exists.. removing", :red
|
91
|
+
File.delete PID
|
92
|
+
elsif pid_exists?
|
93
|
+
error "Server already running"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def is_process_running?
|
98
|
+
Process.getpgid pid.to_i
|
99
|
+
true
|
100
|
+
rescue Errno::ESRCH
|
101
|
+
false
|
102
|
+
end
|
103
|
+
|
104
|
+
def error(message)
|
105
|
+
say message, :red
|
106
|
+
exit -1
|
107
|
+
end
|
108
|
+
|
109
|
+
def pid_exists?
|
110
|
+
File.exists? PID
|
111
|
+
end
|
112
|
+
|
113
|
+
def pid
|
114
|
+
File.read(PID).to_i
|
115
|
+
end
|
116
|
+
|
117
|
+
def can_fork?
|
118
|
+
RUBY_PLATFORM != "java"
|
119
|
+
end
|
120
|
+
|
121
|
+
def bin_path
|
122
|
+
File.absolute_path(
|
123
|
+
File.join(
|
124
|
+
File.dirname(__FILE__),
|
125
|
+
"..",
|
126
|
+
"..",
|
127
|
+
"..",
|
128
|
+
"bin",
|
129
|
+
"spurious-server"
|
130
|
+
)
|
131
|
+
)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
data/spurious-server.gemspec
CHANGED
@@ -25,8 +25,8 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.add_runtime_dependency "eventmachine"
|
26
26
|
spec.add_runtime_dependency "em-synchrony"
|
27
27
|
spec.add_runtime_dependency "docker-api"
|
28
|
-
spec.add_runtime_dependency "daemons"
|
29
28
|
spec.add_runtime_dependency "peach"
|
30
|
-
|
29
|
+
spec.add_runtime_dependency "thor"
|
30
|
+
spec.add_runtime_dependency "spoon"
|
31
31
|
|
32
32
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spurious-server
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steven Jack
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -95,7 +95,7 @@ dependencies:
|
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
98
|
+
name: peach
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - '>='
|
@@ -109,7 +109,21 @@ dependencies:
|
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
112
|
+
name: thor
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: spoon
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
114
128
|
requirements:
|
115
129
|
- - '>='
|
@@ -140,6 +154,7 @@ files:
|
|
140
154
|
- config/images.yaml
|
141
155
|
- lib/spurious/server.rb
|
142
156
|
- lib/spurious/server/app.rb
|
157
|
+
- lib/spurious/server/cli.rb
|
143
158
|
- lib/spurious/server/config.rb
|
144
159
|
- lib/spurious/server/options.rb
|
145
160
|
- lib/spurious/server/state/base.rb
|