norikra 0.0.12-java → 0.0.13-java
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.
- data/bin/norikra +5 -8
- data/lib/norikra/cli.rb +151 -56
- data/lib/norikra/server.rb +10 -0
- data/lib/norikra/version.rb +1 -1
- metadata +2 -4
- data/bin/norikra-server +0 -8
data/bin/norikra
CHANGED
@@ -1,11 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
require 'pathname'
|
4
|
+
libs = ['lib', 'esper'].map{|p| Pathname.new(__FILE__).dirname.join('..', p).expand_path}
|
5
|
+
$LOAD_PATH.unshift(*libs.map(&:to_s))
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
ARGV.shift
|
9
|
-
end
|
10
|
-
args = jruby_options + [binpath] + ARGV
|
11
|
-
exec('jruby', *args)
|
7
|
+
require 'norikra/cli'
|
8
|
+
Norikra::CLI.start
|
data/lib/norikra/cli.rb
CHANGED
@@ -3,64 +3,127 @@ require 'norikra/error'
|
|
3
3
|
require 'thor'
|
4
4
|
|
5
5
|
module Norikra
|
6
|
+
DEFAULT_PID_PATH = '/var/run/norikra/norikra.pid'
|
7
|
+
|
8
|
+
module CLIUtil
|
9
|
+
def self.register_common_start_options(klass)
|
10
|
+
klass.module_exec {
|
11
|
+
### Server options
|
12
|
+
option :host, :type => :string, :default => nil, :aliases => "-H", :desc => 'host address that server listen [0.0.0.0]'
|
13
|
+
option :port, :type => :numeric, :default => nil, :aliases => "-P", :desc => 'port that server uses [26571]'
|
14
|
+
|
15
|
+
option :stats, :type => :string, :default => nil, :aliases => "-s", \
|
16
|
+
:desc => 'status file path to load/dump targets, queries and server configurations [none]'
|
17
|
+
option :'suppress-dump-stat', :type => :boolean, :default => false, \
|
18
|
+
:desc => 'specify not to update stat file with updated targets/queries/configurations on runtime [false]'
|
19
|
+
|
20
|
+
### Daemonize options
|
21
|
+
option :daemonize, :type => :boolean, :default => false, :aliases => "-d", \
|
22
|
+
:desc => 'daemonize Norikra server [false (foreground)]'
|
23
|
+
option :pidfile, :type => :string, :default => DEFAULT_PID_PATH, :aliases => "-p", \
|
24
|
+
:desc => "pidfile path when daemonized [#{DEFAULT_PID_PATH}]"
|
25
|
+
option :outfile, :type => :string, :default => nil, \
|
26
|
+
:desc => "stdout redirect file when daemonized [${logdir}/norikra.out]"
|
27
|
+
|
28
|
+
### Performance options
|
29
|
+
# performance predefined configuration sets
|
30
|
+
option :micro, :type => :boolean, :default => false, \
|
31
|
+
:desc => 'development or testing (inbound:0, outbound:0, route:0, timer:0, rpc:2)'
|
32
|
+
option :small, :type => :boolean, :default => false, \
|
33
|
+
:desc => 'virtual or small scale servers (inbound:1, outbount:1, route:1, timer:1, rpc:2)'
|
34
|
+
option :middle, :type => :boolean, :default => false, \
|
35
|
+
:desc => 'rackmount servers (inbound:4, outbound:2, route:2, timer:2, rpc:4)'
|
36
|
+
option :large, :type => :boolean, :default => false, \
|
37
|
+
:desc => 'high performance servers (inbound: 6, outbound: 6, route:4, timer:4, rpc: 8)'
|
38
|
+
# Esper
|
39
|
+
option :'inbound-threads', :type => :numeric, :default => nil, :desc => 'number of threads for inbound data'
|
40
|
+
option :'outbound-threads', :type => :numeric, :default => nil, :desc => 'number of threads for outbound data'
|
41
|
+
option :'route-threads', :type => :numeric, :default => nil, :desc => 'number of threads for events routing for query execution'
|
42
|
+
option :'timer-threads', :type => :numeric, :default => nil, :desc => 'number of threads for internal timers for query execution'
|
43
|
+
option :'inbound-thread-capacity', :type => :numeric, :default => nil
|
44
|
+
option :'outbound-thread-capacity', :type => :numeric, :default => nil
|
45
|
+
option :'route-thread-capacity', :type => :numeric, :default => nil
|
46
|
+
option :'timer-thread-capacity', :type => :numeric, :default => nil
|
47
|
+
# Jetty
|
48
|
+
option :'rpc-threads', :type => :numeric, :default => nil, :desc => 'number of threads for rpc handlers'
|
49
|
+
|
50
|
+
### Logging options
|
51
|
+
option :logdir, :type => :string, :default => nil, :aliases => "-l", \
|
52
|
+
:desc => "directory path of logfiles when daemonized [nil (console for foreground)]"
|
53
|
+
option :'log-filesize', :type => :string, :default => nil, :desc => 'log rotation size [10MB]'
|
54
|
+
option :'log-backups' , :type => :numeric, :default => nil, :desc => 'log rotation backups [10]'
|
55
|
+
|
56
|
+
### Loglevel options
|
57
|
+
option :'more-quiet', :type => :boolean, :default => false, :desc => 'set loglevel as ERROR'
|
58
|
+
option :quiet, :type => :boolean, :default => false, :aliases => "-q", :desc => 'set loglevel as WARN'
|
59
|
+
option :verbose, :type => :boolean, :default => false, :aliases => "-v", :desc => 'set loglevel as DEBUG'
|
60
|
+
option :'more-verbose', :type => :boolean, :default => false, :desc => 'set loglevel as TRACE'
|
61
|
+
}
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
6
65
|
class CLI < Thor
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
option :
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
66
|
+
### 'start' and 'serverprocess' have almost same option set (for parse/help)
|
67
|
+
### DIFF: jvm options (-X)
|
68
|
+
Norikra::CLIUtil.register_common_start_options(self)
|
69
|
+
option :help, :type => :boolean, :default => false, :aliases => "-h", :desc => "show this message"
|
70
|
+
desc "start [-Xxxx] [other options]", "Start Norikra server process"
|
71
|
+
def start(*optargs)
|
72
|
+
if options[:help]
|
73
|
+
invoke :help, ["start"]
|
74
|
+
return
|
75
|
+
end
|
76
|
+
|
77
|
+
ARGV.shift # shift head "start"
|
78
|
+
|
79
|
+
argv = ["serverproc"]
|
80
|
+
jruby_options = ['-J-server', '-J-XX:-UseGCOverheadLimit']
|
81
|
+
|
82
|
+
ARGV.each do |arg|
|
83
|
+
if arg =~ /^-X(.+)$/
|
84
|
+
jruby_options.push('-J-X' + $1)
|
85
|
+
else
|
86
|
+
argv.push(arg)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
# norikra/lib/norikra
|
91
|
+
binpath = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'bin', 'norikra'))
|
92
|
+
args = jruby_options + [binpath] + argv
|
93
|
+
|
94
|
+
if options[:daemonize]
|
95
|
+
unless options[:logdir]
|
96
|
+
puts "'logdir' must be specified for '--daemonize'."
|
97
|
+
exit(1)
|
98
|
+
end
|
99
|
+
|
100
|
+
## need to close/reopen STDIN/STDOUT/STDERR in child process
|
101
|
+
outfile = options[:outfile] || File.join(options[:logdir], '/norikra.out')
|
102
|
+
File.open(outfile, 'w'){|file| file.write 'write test on parent process'}
|
103
|
+
|
104
|
+
pidfile = File.open(options[:pidfile], 'w')
|
105
|
+
pid = spawn('jruby', *args, :pgroup => 0)
|
106
|
+
pidfile.write(pid.to_s)
|
107
|
+
pidfile.close
|
108
|
+
waiting_child = true
|
109
|
+
while waiting_child && sleep(1)
|
110
|
+
out = File.open(outfile){|f| f.read}
|
111
|
+
waiting_child = false if out =~ /working on #{pid}/
|
112
|
+
end
|
113
|
+
Process.detach(pid)
|
114
|
+
else
|
115
|
+
exec('jruby', *args)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
Norikra::CLIUtil.register_common_start_options(self)
|
120
|
+
desc "serverproc", "execute server process actually (don't execute this subcommand directly)", :hide => true
|
121
|
+
def serverproc
|
59
122
|
conf = {}
|
60
123
|
|
61
|
-
|
62
|
-
|
63
|
-
|
124
|
+
if options[:daemonize]
|
125
|
+
conf[:daemonize] = {:outfile => options[:outfile]}
|
126
|
+
end
|
64
127
|
|
65
128
|
### stat file
|
66
129
|
conf[:stats] = {
|
@@ -68,7 +131,7 @@ module Norikra
|
|
68
131
|
}
|
69
132
|
|
70
133
|
### threads
|
71
|
-
predefined_selecteds = [:micro, :small, :middle, :
|
134
|
+
predefined_selecteds = [:micro, :small, :middle, :large].select{|sym| options[sym]}
|
72
135
|
if predefined_selecteds.size > 1
|
73
136
|
raise Norikra::ConfigurationError, "one of micro/small/middle/large should be specified"
|
74
137
|
end
|
@@ -100,5 +163,37 @@ module Norikra
|
|
100
163
|
server.run
|
101
164
|
server.shutdown
|
102
165
|
end
|
166
|
+
|
167
|
+
option :pidfile, :type => :string, :default => DEFAULT_PID_PATH, :aliases => "-p", \
|
168
|
+
:desc => "pidfile path when daemonized [#{DEFAULT_PID_PATH}]"
|
169
|
+
option :timeout, :type => :numeric, :default => 5, :desc => "timeout seconds to wait process exit [5]"
|
170
|
+
desc "stop [options]", "stop daemonized Norikra server"
|
171
|
+
def stop
|
172
|
+
unless test(?r,options[:pidfile])
|
173
|
+
puts "Cannot find pidfile at #{options[:pidfile]}"
|
174
|
+
exit(1)
|
175
|
+
end
|
176
|
+
pid = File.open(options[:pidfile]){|f| f.read}.to_i
|
177
|
+
timeout = Time.now + options[:timeout]
|
178
|
+
waiting = true
|
179
|
+
Process.kill(:TERM, pid)
|
180
|
+
begin
|
181
|
+
while waiting && Time.now < timeout
|
182
|
+
sleep(0.5)
|
183
|
+
status = Process.waitpid(pid, Process::WNOHANG)
|
184
|
+
if status
|
185
|
+
waiting = false
|
186
|
+
end
|
187
|
+
end
|
188
|
+
rescue Errno::ECHILD
|
189
|
+
waiting = false
|
190
|
+
end
|
191
|
+
if waiting
|
192
|
+
puts "Faild to stop Norikra server #{pid}"
|
193
|
+
exit(1)
|
194
|
+
else
|
195
|
+
File.unlink(options[:pidfile])
|
196
|
+
end
|
197
|
+
end
|
103
198
|
end
|
104
199
|
end
|
data/lib/norikra/server.rb
CHANGED
@@ -63,6 +63,16 @@ module Norikra
|
|
63
63
|
end
|
64
64
|
|
65
65
|
def initialize(host, port, conf={})
|
66
|
+
if conf[:daemonize]
|
67
|
+
outfile_path = conf[:daemonize][:outfile] || File.join(conf[:log][:dir], 'norikra.out')
|
68
|
+
Dir.chdir("/")
|
69
|
+
STDIN.reopen("/dev/null")
|
70
|
+
outfile = File.open(outfile_path, 'w')
|
71
|
+
STDOUT.reopen(outfile)
|
72
|
+
STDERR.reopen(outfile)
|
73
|
+
puts "working on #{$PID}"
|
74
|
+
end
|
75
|
+
|
66
76
|
@stats_path = conf[:stats][:path]
|
67
77
|
@stats_suppress_dump = conf[:stats][:suppress]
|
68
78
|
@stats = if @stats_path && test(?r, @stats_path)
|
data/lib/norikra/version.rb
CHANGED
metadata
CHANGED
@@ -2,14 +2,14 @@
|
|
2
2
|
name: norikra
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.13
|
6
6
|
platform: java
|
7
7
|
authors:
|
8
8
|
- TAGOMORI Satoshi
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-09-
|
12
|
+
date: 2013-09-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: mizuno
|
@@ -177,7 +177,6 @@ email:
|
|
177
177
|
- tagomoris@gmail.com
|
178
178
|
executables:
|
179
179
|
- norikra
|
180
|
-
- norikra-server
|
181
180
|
extensions: []
|
182
181
|
extra_rdoc_files: []
|
183
182
|
files:
|
@@ -189,7 +188,6 @@ files:
|
|
189
188
|
- README.md
|
190
189
|
- Rakefile
|
191
190
|
- bin/norikra
|
192
|
-
- bin/norikra-server
|
193
191
|
- esper/changelog.txt
|
194
192
|
- esper/esper-4.9.0.jar
|
195
193
|
- esper/esper-license.txt
|