razorrisk-cassini-utilities-cassid 0.8.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +22 -0
- data/LICENSE +5 -0
- data/README.md +2 -0
- data/bin/cassid +279 -0
- data/bin/razorrisk-service-cassid +90 -0
- data/lib/razor_risk/cassini/utilities/cassid/configuration.rb +367 -0
- data/lib/razor_risk/cassini/utilities/cassid/constants.rb +48 -0
- data/lib/razor_risk/cassini/utilities/cassid/main.rb +643 -0
- data/lib/razor_risk/cassini/utilities/cassid/service_controller.rb +149 -0
- data/lib/razor_risk/cassini/utilities/cassid/validations.rb +460 -0
- data/lib/razor_risk/cassini/utilities/cassid/version.rb +54 -0
- data/lib/razor_risk/cassini/utilities/cassid.rb +11 -0
- metadata +210 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a20a127dff057f134d43aff004ec6b89fa7ca76745f7040b9d8e7c7c651d6dc8
|
4
|
+
data.tar.gz: ac515f0f87b992c5e5981074d3c1610028d0714f93d17be818625306cb805b95
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a1e1fee413b545600b7ccbdf2ba33aa3d3108657a0f9d0e6c2001a2ebc0f23817495de73707a5ffcb13d8f063e7f57a80637d0734e46edd53145f27edab8577c
|
7
|
+
data.tar.gz: 75b9b4ab865c853c1694c0546b7929859a5f27bea6514b19f96172a4898c751345a6a0af285a3f4abf8703d15c20e3597c55f138099c57101e51266dea101be1
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# Change Log
|
2
|
+
|
3
|
+
## [0.5.3] (2018-07-05)
|
4
|
+
|
5
|
+
**Implemented enhancements:**
|
6
|
+
|
7
|
+
none
|
8
|
+
|
9
|
+
**Fixed defects:**
|
10
|
+
|
11
|
+
none
|
12
|
+
|
13
|
+
**Dependencies and packaging:**
|
14
|
+
|
15
|
+
- separated into own project/repo/package [WEBAPI-138]
|
16
|
+
|
17
|
+
**Merged pull requests:**
|
18
|
+
|
19
|
+
none
|
20
|
+
|
21
|
+
## END OF CHANGE LOG
|
22
|
+
|
data/LICENSE
ADDED
data/README.md
ADDED
data/bin/cassid
ADDED
@@ -0,0 +1,279 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
# ##########################################################################
|
5
|
+
#
|
6
|
+
# Startup daemon for Cassini
|
7
|
+
#
|
8
|
+
# Copyright (c) 2018 Razor Risk Technologies Pty Limited. All rights reserved.
|
9
|
+
#
|
10
|
+
# ##########################################################################
|
11
|
+
|
12
|
+
# ##########################################################################
|
13
|
+
# requires
|
14
|
+
|
15
|
+
require 'razor_risk/cassini/utilities/cassid'
|
16
|
+
|
17
|
+
require 'razor_risk/cassini/cli'
|
18
|
+
require 'razor_risk/cassini/diagnostics/util_functions'
|
19
|
+
require 'razor_risk/cassini/util/version_util'
|
20
|
+
|
21
|
+
require 'razor_risk/extensions/hash/dig'
|
22
|
+
require 'razor_risk/core/diagnostics/extensions/libclimate'
|
23
|
+
require 'razor_risk/core/diagnostics/logger'
|
24
|
+
|
25
|
+
require 'libclimate'
|
26
|
+
require 'pantheios'
|
27
|
+
require 'recls'
|
28
|
+
|
29
|
+
require 'nokogiri'
|
30
|
+
require 'socket'
|
31
|
+
require 'yaml'
|
32
|
+
|
33
|
+
# ##########################################################################
|
34
|
+
# includes
|
35
|
+
|
36
|
+
include ::RazorRisk::Cassini::Utilities::CassiD
|
37
|
+
|
38
|
+
include ::RazorRisk::Cassini::Diagnostics
|
39
|
+
|
40
|
+
include ::RazorRisk::Cassini::Util::VersionUtil
|
41
|
+
|
42
|
+
include ::RazorRisk::Core::Diagnostics::Logger
|
43
|
+
|
44
|
+
# ##########################################################################
|
45
|
+
# version
|
46
|
+
|
47
|
+
PROGRAM_VERSION = ::RazorRisk::Cassini::Utilities::CassiD::VERSION
|
48
|
+
|
49
|
+
# ##########################################################################
|
50
|
+
# constants
|
51
|
+
|
52
|
+
SERVICE_NAME = 'razorrisk-service-cassid'
|
53
|
+
SERVICE_DISPLAY_NAME = 'Razor Web Services'
|
54
|
+
SERVICE_DESCRIPTION = 'Razor Risk Web Service API'
|
55
|
+
DEPRECIATION_NOTICE = 'NOTICE: this option has been depreciated in favour of service installation'
|
56
|
+
RUBY_PATH = `where ruby`.split("\n")[0].chomp
|
57
|
+
|
58
|
+
|
59
|
+
#############################################################################
|
60
|
+
# compatibility checks
|
61
|
+
|
62
|
+
check_version_compatibility RazorRisk::Core::Diagnostics::Extensions, '0.2'
|
63
|
+
check_version_compatibility ::LibCLImate, '0.8'
|
64
|
+
check_version_compatibility ::Pantheios, '0.20'
|
65
|
+
check_version_compatibility ::Recls, '2.8'
|
66
|
+
|
67
|
+
|
68
|
+
# Listens on the specified port for the message 'exit' and returns when it is
|
69
|
+
# received.
|
70
|
+
#
|
71
|
+
# @param port [Integer] The port to listen on.
|
72
|
+
#
|
73
|
+
# @raise [Errno::EADDRINUSE] if the port is alredy in use.
|
74
|
+
def listen_for_exit port
|
75
|
+
|
76
|
+
TCPServer.open(port) do |server|
|
77
|
+
log :notice, "Listening for exit message on port #{port}"
|
78
|
+
loop do
|
79
|
+
client = server.accept
|
80
|
+
|
81
|
+
line = ''
|
82
|
+
while c = client.getc
|
83
|
+
line += c
|
84
|
+
break if 4 < line.length
|
85
|
+
end
|
86
|
+
client.close
|
87
|
+
|
88
|
+
if /^exit$/i =~ line
|
89
|
+
break
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
# ##########################################################################
|
96
|
+
# command-line processing
|
97
|
+
|
98
|
+
options = {}
|
99
|
+
service_args = []
|
100
|
+
|
101
|
+
climate = LibCLImate::Climate.new do |cl|
|
102
|
+
|
103
|
+
cl.add_option('--detach-child-processes', help: DEPRECIATION_NOTICE) do
|
104
|
+
log :warning, DEPRECIATION_NOTICE
|
105
|
+
end
|
106
|
+
cl.add_alias('--detach-child-processes=true', '-d')
|
107
|
+
cl.add_alias('--detach-child-processes=false', '-D')
|
108
|
+
|
109
|
+
cl.add_option(
|
110
|
+
'--microservice-multiplier',
|
111
|
+
alias: '-m',
|
112
|
+
help: "overrides the 'us_multiplier' configuration setting to the given number. Must be greater than 0"
|
113
|
+
) do |o, a|
|
114
|
+
service_args << o.given_name
|
115
|
+
service_args << o.value
|
116
|
+
end
|
117
|
+
|
118
|
+
cl.add_flag(
|
119
|
+
'--monitor-startup',
|
120
|
+
help: 'monitors child process statuses during initialisation'
|
121
|
+
) do
|
122
|
+
service_args << '--monitor-startup'
|
123
|
+
end
|
124
|
+
|
125
|
+
cl.add_flag(
|
126
|
+
'--pedantic',
|
127
|
+
help: 'conducts checks that the configuration is correct'
|
128
|
+
) do
|
129
|
+
service_args << '--pedantic'
|
130
|
+
end
|
131
|
+
|
132
|
+
cl.add_option(
|
133
|
+
'--max-restarts',
|
134
|
+
help: 'maximum number of times to restart a microservice; this is only available when running as a service'
|
135
|
+
) do |o, a|
|
136
|
+
val = Integer(o.value, nil: true)
|
137
|
+
climate.abort(
|
138
|
+
"max retries must be 0 or a positive integer; use --help for usage"
|
139
|
+
) if val.nil? || val < 0
|
140
|
+
service_args << o.given_name
|
141
|
+
service_args << o.value
|
142
|
+
end
|
143
|
+
|
144
|
+
cl.add_option(
|
145
|
+
'--service-name',
|
146
|
+
help: 'service installation name'
|
147
|
+
) do |o, a|
|
148
|
+
options[:service_name] = (o.value || '').chomp
|
149
|
+
climate.abort 'Service name may not be empty' if options[:service_name].empty?
|
150
|
+
end
|
151
|
+
|
152
|
+
cl.add_option(
|
153
|
+
'--service-display-name',
|
154
|
+
help: 'service installation display name'
|
155
|
+
) do |o, a|
|
156
|
+
options[:service_display_name] = (o.value || '').chomp
|
157
|
+
climate.abort 'Service display name may not be empty' if options[:service_display_name].empty?
|
158
|
+
end
|
159
|
+
|
160
|
+
cl.add_option('--exit-listener-port',
|
161
|
+
alias: '-e',
|
162
|
+
help: "sets the port number to listen on for an exit command, must be in range #{Main::VALID_PORTS}; NOTE: this is for testing only"
|
163
|
+
) do |o, a|
|
164
|
+
|
165
|
+
options[:exit_port] = Integer(o.value, nil: true) and Main::VALID_PORTS.include?(options[:exit_port]) or climate.abort "invalid value port number; use --help for usage"
|
166
|
+
end
|
167
|
+
|
168
|
+
cl.option_log_threshold(
|
169
|
+
options,
|
170
|
+
no_program_name: true,
|
171
|
+
no_benchmark: true,
|
172
|
+
limit: -2
|
173
|
+
)
|
174
|
+
|
175
|
+
cl.usage_values = '[ <config-yaml-file> | register <config-yaml-file> | unregister | start | stop'
|
176
|
+
|
177
|
+
cl.info_lines = [
|
178
|
+
|
179
|
+
'Startup Daemon for Cassini',
|
180
|
+
::RazorRisk::Cassini::CLI.Copyright(2018),
|
181
|
+
:version,
|
182
|
+
'',
|
183
|
+
'Executes a Cassini instance based on a configuration file',
|
184
|
+
'',
|
185
|
+
]
|
186
|
+
end
|
187
|
+
|
188
|
+
r = climate.run ARGV.dup
|
189
|
+
|
190
|
+
begin
|
191
|
+
case r.values[0].downcase
|
192
|
+
when 'start'
|
193
|
+
|
194
|
+
name = options[:service_name] || SERVICE_NAME
|
195
|
+
service = ServiceController.new(name)
|
196
|
+
if service.start
|
197
|
+
$stdout.puts "Started #{name} as a service"
|
198
|
+
else
|
199
|
+
$stdout.puts "Failed to start #{name} as a service"
|
200
|
+
end
|
201
|
+
when 'stop'
|
202
|
+
|
203
|
+
name = options[:service_name] || SERVICE_NAME
|
204
|
+
service = ServiceController.new(name)
|
205
|
+
if service.stop
|
206
|
+
$stdout.puts "Stopped #{name} service"
|
207
|
+
else
|
208
|
+
$stdout.puts "Failed to stop #{name} service"
|
209
|
+
end
|
210
|
+
when 'unregister'
|
211
|
+
|
212
|
+
name = options[:service_name] || SERVICE_NAME
|
213
|
+
service = ServiceController.new(name)
|
214
|
+
if service.unregister
|
215
|
+
$stdout.puts "Removed service #{name}"
|
216
|
+
else
|
217
|
+
$stderr.puts "Failed to removed service #{name}"
|
218
|
+
end
|
219
|
+
|
220
|
+
when 'register'
|
221
|
+
|
222
|
+
config_file = r.values[1] || ''
|
223
|
+
name = options[:service_name] || SERVICE_NAME
|
224
|
+
display_name = options[:service_display_name] || SERVICE_DISPLAY_NAME
|
225
|
+
service = ServiceController.new(name)
|
226
|
+
|
227
|
+
if service.register(
|
228
|
+
display_name,
|
229
|
+
SERVICE_DESCRIPTION,
|
230
|
+
Dir.pwd,
|
231
|
+
File.join('bin', SERVICE_NAME),
|
232
|
+
config_file,
|
233
|
+
RUBY_PATH,
|
234
|
+
*service_args,
|
235
|
+
)
|
236
|
+
$stdout.puts "Registered #{display_name} (#{name}) as a service"
|
237
|
+
else
|
238
|
+
$stdout.puts "Failed to register #{display_name} (#{name}) as a service"
|
239
|
+
end
|
240
|
+
else
|
241
|
+
|
242
|
+
config_path = r.values[0] || ''
|
243
|
+
exit_port = options[:exit_port]
|
244
|
+
|
245
|
+
config_path, options = Main::process_cli(*ARGV.dup)
|
246
|
+
|
247
|
+
at_exit do
|
248
|
+
Main::kill_children
|
249
|
+
end
|
250
|
+
|
251
|
+
trap 'SIGINT' do
|
252
|
+
climate.abort "processing cancelled ..."
|
253
|
+
end
|
254
|
+
|
255
|
+
Main::init_logging(nil, nil, nil)
|
256
|
+
Main::init(config_path, **options)
|
257
|
+
|
258
|
+
$stdout.puts
|
259
|
+
$stdout.puts "Use Ctrl-C to terminate, along with all child processes"
|
260
|
+
|
261
|
+
if exit_port
|
262
|
+
begin
|
263
|
+
listen_for_exit exit_port
|
264
|
+
rescue Errno::EADDRINUSE
|
265
|
+
msg = "Exit port #{exit_port} is already in use"
|
266
|
+
log :critical, msg
|
267
|
+
climate.abort msg
|
268
|
+
end
|
269
|
+
else
|
270
|
+
loop { sleep(1) }
|
271
|
+
end
|
272
|
+
end
|
273
|
+
rescue => x
|
274
|
+
climate.abort x.message
|
275
|
+
end
|
276
|
+
|
277
|
+
# ############################## end of file ############################# #
|
278
|
+
|
279
|
+
|
@@ -0,0 +1,90 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
# ##########################################################################
|
5
|
+
#
|
6
|
+
# Copyright (c) 2019 Razor Risk Technologies Pty Limited. All rights reserved.
|
7
|
+
#
|
8
|
+
# ##########################################################################
|
9
|
+
|
10
|
+
# ##########################################################
|
11
|
+
# requires
|
12
|
+
|
13
|
+
require 'razor_risk/cassini/utilities/cassid'
|
14
|
+
require 'razor_risk/cassini/diagnostics/util_functions'
|
15
|
+
|
16
|
+
require 'razor_risk/core/diagnostics/extensions/libclimate'
|
17
|
+
require 'razor_risk/core/diagnostics/logger'
|
18
|
+
|
19
|
+
require 'libclimate'
|
20
|
+
require 'pantheios'
|
21
|
+
|
22
|
+
require 'win32/daemon'
|
23
|
+
|
24
|
+
# ##########################################################
|
25
|
+
# includes
|
26
|
+
|
27
|
+
include ::RazorRisk::Cassini::Utilities::CassiD
|
28
|
+
include ::RazorRisk::Cassini::Diagnostics
|
29
|
+
|
30
|
+
|
31
|
+
# ##########################################################################
|
32
|
+
# version
|
33
|
+
|
34
|
+
PROGRAM_VERSION = ::RazorRisk::Cassini::Utilities::CassiD::VERSION
|
35
|
+
|
36
|
+
|
37
|
+
# ##########################################################
|
38
|
+
# Service Main
|
39
|
+
|
40
|
+
class CassiDDaemon < Win32::Daemon
|
41
|
+
|
42
|
+
include ::Pantheios
|
43
|
+
include ::RazorRisk::Core::Diagnostics::Logger
|
44
|
+
|
45
|
+
at_exit do
|
46
|
+
|
47
|
+
log :notice, 'Service stopping...'
|
48
|
+
begin
|
49
|
+
Main::kill_children
|
50
|
+
rescue => x
|
51
|
+
log :critical, "Failed to kill child processes (#{x.class}): #{x.message})"
|
52
|
+
exit! 1
|
53
|
+
else
|
54
|
+
exit!
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def service_main
|
59
|
+
|
60
|
+
Main::init_logging(nil, nil, nil)
|
61
|
+
|
62
|
+
log :informational, 'Started CassiD Service'
|
63
|
+
|
64
|
+
config_path, options = Main::process_cli(*ARGV.dup)
|
65
|
+
|
66
|
+
Main::init(config_path, **options)
|
67
|
+
|
68
|
+
while running?
|
69
|
+
loop do
|
70
|
+
unless Main::children_running?
|
71
|
+
Main::restart_children(options[:max_restarts])
|
72
|
+
end
|
73
|
+
sleep 10
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def service_stop
|
79
|
+
|
80
|
+
log :informational, "Stopping CassiD Service"
|
81
|
+
exit
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
CassiDDaemon.mainloop
|
86
|
+
|
87
|
+
|
88
|
+
# ############################## end of file ############################# #
|
89
|
+
|
90
|
+
|