riddl 0.99.266 → 0.100.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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ruby/riddl/server.rb +50 -149
  3. data/riddl.gemspec +2 -1
  4. metadata +16 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4c015a19c3a36b6d7db24d26eef331d3316be01d
4
- data.tar.gz: 45b6125383f6533d4e14aa2e1e743a44e41642cb
3
+ metadata.gz: 6c102b4a4f29887b96b6a662b8360be51afe2e50
4
+ data.tar.gz: 5d7849b43316dc94506af325f1c00a35822dbd61
5
5
  SHA512:
6
- metadata.gz: 49ae48bf01ce57452629b8adc6e4038b87d11db6c0b5e4e414a61c8cc79f301ae3e0a0e11661db9aaa8e427bf0f6e257a86214d07a56877eda59588f194acfa9
7
- data.tar.gz: 5b03e60861170c5a15250d27ce8b15206141359a7b581d14980230ebcf6d8d82387c4e722b8923c99b259236334e40d52c8337dd1ffa4882b3de7999ddf62288
6
+ metadata.gz: e68ae727140620b7222d3bb4d4f117e4d73d78bc15cd69e2df93359c0940b2c69bffff26d54a791f0f1b9c8b8f26a0e76fd4f0b3cc0976f7ffe9d366c04c251f
7
+ data.tar.gz: e670b312fe3a8990ded62151f15caa1674b20201eef3d652d73d6d181d59fa014179d6bf456e2be89be454d64c900eba13caf1dd2a7bdd6fe2e384a1d29d8b0d
@@ -11,6 +11,7 @@ require File.expand_path(File.dirname(__FILE__) + '/wrapper')
11
11
  require File.expand_path(File.dirname(__FILE__) + '/utils/description')
12
12
 
13
13
  require 'optparse'
14
+ require 'daemonite'
14
15
  require 'stringio'
15
16
  require 'rack/content_length'
16
17
  require 'rack/chunked'
@@ -39,80 +40,60 @@ module Riddl
39
40
  end
40
41
  end #}}}
41
42
 
42
- OPTS = {
43
- :bind => '0.0.0.0',
44
- :host => 'localhost',
45
- :port => 9292,
46
- :secure => false,
47
- :mode => :debug,
48
- :verbose => false,
49
- :http_only => false,
50
- :basepath => File.expand_path(File.dirname($0)),
51
- :pidfile => File.basename($0,'.rb') + '.pid',
52
- :conffile => File.basename($0,'.rb') + '.conf',
53
- :runtime_options => [],
54
- :cmdl_parsing => true,
55
- :cmdl_operation => 'start'
56
- }
43
+ include Daemonism
57
44
 
58
- def loop! #{{{
59
- ########################################################################################################################
60
- # status and info
61
- ########################################################################################################################
62
- pid = File.read(@riddl_opts[:basepath] + '/' + @riddl_opts[:pidfile]).to_i rescue pid = -1
63
- status = Proc.new do
64
- begin
65
- Process.getpgid pid
66
- true
67
- rescue Errno::ESRCH
68
- false
69
- end
70
- end
71
- if @riddl_opts[:cmdl_operation] == "info" && status.call == false
72
- puts "Server (#{@riddl_opts[:url]}) not running"
73
- exit
74
- end
75
- if @riddl_opts[:cmdl_operation] == "info" && status.call == true
76
- puts "Server (#{@riddl_opts[:url]}) running as #{pid}"
77
- begin
78
- stats = `ps -o "vsz,rss,lstart,time" -p #{pid}`.split("\n")[1].strip.split(/ +/)
79
- puts "Virtual: #{"%0.2f" % (stats[0].to_f/1024)} MiB"
80
- puts "Resident: #{"%0.2f" % (stats[1].to_f/1024)} MiB"
81
- puts "Started: #{stats[2..-2].join(' ')}"
82
- puts "CPU Time: #{stats.last}"
83
- rescue
84
- end
85
- exit
86
- end
87
- if %w{start}.include?(@riddl_opts[:cmdl_operation]) && status.call == true
88
- puts "Server (#{@riddl_opts[:url]}) already started"
89
- exit
90
- end
45
+ attr_reader :riddl_log, :riddl_method, :riddl_pinfo, :riddl_status
91
46
 
92
- ########################################################################################################################
93
- # stop/restart server
94
- ########################################################################################################################
95
- if %w{stop restart}.include?(@riddl_opts[:cmdl_operation])
96
- if status.call == false
97
- puts "Server (#{@riddl_opts[:url]}) maybe not started?"
98
- else
99
- puts "Server (#{@riddl_opts[:url]}) stopped"
100
- puts "Waiting while server goes down ..."
101
- while status.call
102
- Process.kill "SIGTERM", pid
103
- sleep 0.3
104
- end
105
- end
106
- exit unless @riddl_opts[:cmdl_operation] == "restart"
107
- end
47
+ def initialize(riddl,opts={},&blk)# {{{
48
+ @riddl_opts = DAEMONISM_DEFAULT_OPTS.merge({
49
+ :bind => '0.0.0.0',
50
+ :host => 'localhost',
51
+ :port => 9292,
52
+ :secure => false,
53
+ :verbose => false,
54
+ :http_only => false,
55
+ :runtime_opts => [
56
+ ["--port [PORT]", "-p [PORT]", "Specify http port.", ->(p){
57
+ @riddl_opts[:port] = p.to_i
58
+ @riddl_opts[:pidfile] = @riddl_opts[:pidfile].gsub(/\.pid/,'') + '-' + @riddl_opts[:port].to_s + '.pid'
59
+ }],
60
+ ["--http-only", "-s", "Only http, no other protocols.", ->(){ @riddl_opts[:http_only] = true }]
61
+ ],
62
+ :runtime_cmds => [],
63
+ :runtime_proc => Proc.new { |opts|
64
+ @riddl_opts[:cmdl_info] = @riddl_opts[:url] = (@riddl_opts[:secure] ? 'https://' : 'http://') + @riddl_opts[:host] + ':' + @riddl_opts[:port].to_s
65
+ }
66
+ }).merge(opts)
67
+
68
+ @riddl_logger = nil
69
+ @riddl_process_out = true
70
+ @riddl_cross_site_xhr = false
71
+ @accessible_description = false
72
+ @riddl_description_string = ''
73
+ @riddl_paths = []
74
+
75
+ @riddl_at_exit = nil
76
+
77
+ @riddl_interfaces = {}
78
+
79
+ daemonism @riddl_opts, &blk
108
80
 
109
- ########################################################################################################################
110
- # go through user defined startup thingis
111
- ########################################################################################################################
112
- @riddl_opts[:runtime_options].each do |ro|
113
- ro[2].call(status.call) if @riddl_opts[:cmdl_operation] == ro[0]
81
+ @riddl = Riddl::Wrapper.new(riddl,@accessible_description)
82
+ if @riddl.description?
83
+ raise SpecificationError, 'RIDDL description does not conform to specification' unless @riddl.validate!
84
+ @riddl_description_string = @riddl.description.xml
85
+ elsif @riddl.declaration?
86
+ raise SpecificationError, 'RIDDL declaration does not conform to specification' unless @riddl.validate!
87
+ @riddl_description_string = @riddl.declaration.description_xml
88
+ else
89
+ raise SpecificationError, 'Not a RIDDL file'
114
90
  end
115
91
 
92
+ @riddl.load_necessary_handlers!
93
+ @riddl_paths = @riddl.paths
94
+ end# }}}
95
+
96
+ def loop! #{{{
116
97
  app = Rack::Builder.new self
117
98
  unless @riddl_logger.nil?
118
99
  app.use Rack::CommonLogger, @riddl_logger
@@ -124,20 +105,12 @@ module Riddl
124
105
  :Port => @riddl_opts[:port],
125
106
  :environment => @riddl_opts[:verbose] ? 'deployment' : 'none',
126
107
  :server => 'thin',
127
- :pid => File.expand_path(@riddl_opts[:basepath] + '/' + @riddl_opts[:pidfile]),
128
108
  :signals => false
129
109
  )
130
-
131
- puts "Server (#{@riddl_opts[:url]}) started as PID:#{Process.pid}"
132
110
  if @riddl_opts[:custom_protocol] && !@riddl_opts[:http_only]
133
111
  @riddl_opts[:custom_protocol] = @riddl_opts[:custom_protocol].new(@riddl_opts)
134
112
  puts @riddl_opts[:custom_protocol].support if @riddl_opts[:custom_protocol].support
135
113
  end
136
- Process.daemon(@riddl_opts[:basepath]) unless @riddl_opts[:verbose]
137
- Dir.chdir(@riddl_opts[:basepath])
138
- ::Kernel::at_exit do
139
- @riddl_at_exit.call if @riddl_at_exit
140
- end
141
114
  begin
142
115
  EM.run do
143
116
  if @riddl_opts[:secure]
@@ -169,78 +142,6 @@ module Riddl
169
142
  end
170
143
  end #}}}
171
144
 
172
- attr_reader :riddl_log, :riddl_method, :riddl_pinfo, :riddl_status
173
-
174
- def initialize(riddl,opts={},&blk)# {{{
175
- @riddl_opts = {}
176
- @riddl_opts = OPTS.merge(opts)
177
-
178
- if File.exists?(@riddl_opts[:basepath] + '/' + @riddl_opts[:conffile])
179
- @riddl_opts.merge!(Psych::load_file(@riddl_opts[:basepath] + '/' + @riddl_opts[:conffile]))
180
- end
181
-
182
- ########################################################################################################################
183
- # parse arguments
184
- ########################################################################################################################
185
- if @riddl_opts[:cmdl_parsing]
186
- @riddl_opts[:cmdl_operation] = "start"
187
- ARGV.options { |opt|
188
- opt.summary_indent = ' ' * 4
189
- opt.banner = "Usage:\n#{opt.summary_indent}ruby server.rb [options] start|stop|restart|info" + (@riddl_opts[:runtime_options].length > 0 ? '|' : '') + @riddl_opts[:runtime_options].map{|ro| ro[0]}.join('|') + "\n"
190
- opt.on("Options:")
191
- opt.on("--port [PORT]", "-p [PORT]", "Specify http port.") do |p|
192
- @riddl_opts[:port] = p.to_i
193
- @riddl_opts[:pidfile] = @riddl_opts[:pidfile].gsub(/\.pid/,'') + '-' + @riddl_opts[:port].to_s + '.pid'
194
- end
195
- opt.on("--http-only", "-s", "Only http, no other protocols.") { @riddl_opts[:http_only] = true }
196
- opt.on("--verbose", "-v", "Do not daemonize. Write ouput to console.") { @riddl_opts[:verbose] = true }
197
- opt.on("--help", "-h", "This text.") { puts opt; exit }
198
- opt.separator(opt.summary_indent + "start|stop|restart|info".ljust(opt.summary_width+1) + "Do operation start, stop, restart or get information.")
199
- @riddl_opts[:runtime_options].each do |ro|
200
- opt.separator(opt.summary_indent + ro[0].ljust(opt.summary_width+1) + ro[1])
201
- end
202
- opt.parse!
203
- }
204
- unless (%w{start stop restart info} + @riddl_opts[:runtime_options].map{|ro| ro[0] }).include?(ARGV[0])
205
- puts ARGV.options
206
- exit
207
- end
208
- @riddl_opts[:cmdl_operation] = ARGV[0]
209
- end
210
- ########################################################################################################################
211
- @riddl_opts[:url] = (@riddl_opts[:secure] ? 'https://' : 'http://') + @riddl_opts[:host] + ':' + @riddl_opts[:port].to_s
212
-
213
- @riddl_logger = nil
214
- @riddl_process_out = true
215
- @riddl_cross_site_xhr = false
216
- @accessible_description = false
217
- @riddl_description_string = ''
218
- @riddl_paths = []
219
-
220
- @riddl_at_exit = nil
221
-
222
- @riddl_interfaces = {}
223
- instance_exec(@riddl_opts,&blk) if block_given?
224
-
225
- @riddl = Riddl::Wrapper.new(riddl,@accessible_description)
226
- if @riddl.description?
227
- raise SpecificationError, 'RIDDL description does not conform to specification' unless @riddl.validate!
228
- @riddl_description_string = @riddl.description.xml
229
- elsif @riddl.declaration?
230
- raise SpecificationError, 'RIDDL declaration does not conform to specification' unless @riddl.validate!
231
- @riddl_description_string = @riddl.declaration.description_xml
232
- else
233
- raise SpecificationError, 'Not a RIDDL file'
234
- end
235
-
236
- @riddl.load_necessary_handlers!
237
- @riddl_paths = @riddl.paths
238
- end# }}}
239
-
240
- def at_exit(&blk)
241
- @riddl_at_exit = blk
242
- end
243
-
244
145
  def call(env)# {{{
245
146
  dup.__http_call(env)
246
147
  end# }}}
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "riddl"
3
- s.version = "0.99.266"
3
+ s.version = "0.100.0"
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.license = "LGPL-3.0"
6
6
  s.summary = "restful interface description and declaration language: tools and client/server libs"
@@ -23,6 +23,7 @@ Gem::Specification.new do |s|
23
23
 
24
24
  s.required_ruby_version = '>=2.2.0'
25
25
 
26
+ s.add_runtime_dependency 'daemonite', '~>0.2'
26
27
  s.add_runtime_dependency 'typhoeus', '~>1.3'
27
28
  s.add_runtime_dependency 'xml-smart', '>=0.3.6', '~>0'
28
29
  s.add_runtime_dependency 'rdf-smart', '>=0.0.160', '~>0'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: riddl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.99.266
4
+ version: 0.100.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juergen 'eTM' Mangler
@@ -10,8 +10,22 @@ authors:
10
10
  autorequire:
11
11
  bindir: tools
12
12
  cert_chain: []
13
- date: 2018-03-08 00:00:00.000000000 Z
13
+ date: 2018-04-24 00:00:00.000000000 Z
14
14
  dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: daemonite
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - "~>"
20
+ - !ruby/object:Gem::Version
21
+ version: '0.2'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - "~>"
27
+ - !ruby/object:Gem::Version
28
+ version: '0.2'
15
29
  - !ruby/object:Gem::Dependency
16
30
  name: typhoeus
17
31
  requirement: !ruby/object:Gem::Requirement