procon_bypass_man 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +19 -6
- data/.github/workflows/gitleacks.yml +1 -1
- data/.rubocop.yml +4 -0
- data/.ruby-version +1 -1
- data/CHANGELOG.md +15 -0
- data/Gemfile +6 -3
- data/Gemfile.lock +5 -3
- data/README.md +28 -41
- data/Steepfile +0 -1
- data/bin/generate_default_app +10 -0
- data/docs/getting_started.md +102 -28
- data/docs/setup_raspi_by_mitamae.md +43 -2
- data/lib/procon_bypass_man/background/job_performer.rb +1 -2
- data/lib/procon_bypass_man/background/job_queue.rb +50 -0
- data/lib/procon_bypass_man/background/jobs/base_job.rb +1 -1
- data/lib/procon_bypass_man/background/jobs/concerns/has_external_api_setting.rb +2 -2
- data/lib/procon_bypass_man/background/jobs/concerns/job_performable.rb +16 -0
- data/lib/procon_bypass_man/background/jobs/post_completed_remote_macro_job.rb +1 -1
- data/lib/procon_bypass_man/background/jobs/report_boot_job.rb +1 -1
- data/lib/procon_bypass_man/background/jobs/report_completed_upgrade_pbm_job.rb +1 -1
- data/lib/procon_bypass_man/background/jobs/report_error_job.rb +1 -1
- data/lib/procon_bypass_man/background/jobs/report_error_reload_config_job.rb +1 -1
- data/lib/procon_bypass_man/background/jobs/report_load_config_job.rb +1 -1
- data/lib/procon_bypass_man/background/jobs/report_procon_performance_measurements_job.rb +43 -0
- data/lib/procon_bypass_man/background/jobs/report_reload_config_job.rb +1 -1
- data/lib/procon_bypass_man/background/jobs/report_start_reboot_job.rb +1 -1
- data/lib/procon_bypass_man/background/jobs/sync_device_stats_job.rb +1 -1
- data/lib/procon_bypass_man/background.rb +3 -4
- data/lib/procon_bypass_man/bypass/bypass_command.rb +16 -20
- data/lib/procon_bypass_man/bypass/bypass_value.rb +6 -0
- data/lib/procon_bypass_man/bypass/procon_to_switch.rb +99 -0
- data/lib/procon_bypass_man/bypass/switch_to_procon.rb +66 -0
- data/lib/procon_bypass_man/bypass.rb +5 -109
- data/lib/procon_bypass_man/commands/print_boot_message_command.rb +0 -2
- data/lib/procon_bypass_man/configuration.rb +18 -39
- data/lib/procon_bypass_man/device_connection/procon_setting_overrider.rb +12 -3
- data/lib/procon_bypass_man/procon/analog_stick_manipulator.rb +2 -0
- data/lib/procon_bypass_man/procon/layer_changer.rb +2 -0
- data/lib/procon_bypass_man/procon/macro.rb +3 -1
- data/lib/procon_bypass_man/procon/macro_builder.rb +2 -0
- data/lib/procon_bypass_man/procon/macro_registry.rb +2 -0
- data/lib/procon_bypass_man/procon/performance_measurement/last_bypass_at.rb +17 -0
- data/lib/procon_bypass_man/procon/performance_measurement/measurement_collection.rb +9 -0
- data/lib/procon_bypass_man/procon/performance_measurement/measurements_summarizer.rb +101 -0
- data/lib/procon_bypass_man/procon/performance_measurement/procon_performance_span_transfer_job.rb +8 -0
- data/lib/procon_bypass_man/procon/performance_measurement/queue_over_process.rb +38 -0
- data/lib/procon_bypass_man/procon/performance_measurement/span_queue.rb +42 -0
- data/lib/procon_bypass_man/procon/performance_measurement/span_transfer_buffer.rb +39 -0
- data/lib/procon_bypass_man/procon/performance_measurement.rb +110 -0
- data/lib/procon_bypass_man/procon/suppress_rumble.rb +2 -0
- data/lib/procon_bypass_man/procon/user_operation.rb +2 -0
- data/lib/procon_bypass_man/procon/value_objects/analog_stick.rb +2 -0
- data/lib/procon_bypass_man/procon/value_objects/binary/inbound_procon_binary.rb +2 -0
- data/lib/procon_bypass_man/procon/value_objects/binary/processing_procon_binary.rb +2 -0
- data/lib/procon_bypass_man/procon/value_objects/rumble_binary.rb +2 -0
- data/lib/procon_bypass_man/procon.rb +26 -7
- data/lib/procon_bypass_man/procon_display/bypass_hook.rb +12 -0
- data/lib/procon_bypass_man/procon_display.rb +1 -0
- data/lib/procon_bypass_man/remote_macro/queue_over_process.rb +26 -44
- data/lib/procon_bypass_man/remote_macro/remote_macro_object.rb +22 -24
- data/lib/procon_bypass_man/remote_macro/remote_macro_receiver.rb +1 -1
- data/lib/procon_bypass_man/remote_macro/remote_macro_sender.rb +1 -1
- data/lib/procon_bypass_man/remote_macro/task.rb +1 -5
- data/lib/procon_bypass_man/remote_macro/task_queue.rb +6 -10
- data/lib/procon_bypass_man/remote_macro.rb +2 -0
- data/lib/procon_bypass_man/remote_pbm_action/commands/update_remote_pbm_action_status_command.rb +1 -1
- data/lib/procon_bypass_man/remote_pbm_action.rb +2 -0
- data/lib/procon_bypass_man/runner.rb +4 -10
- data/lib/procon_bypass_man/scheduler.rb +15 -6
- data/lib/procon_bypass_man/support/callbacks.rb +79 -34
- data/lib/procon_bypass_man/support/can_over_process.rb +60 -0
- data/lib/procon_bypass_man/support/gc.rb +8 -0
- data/lib/procon_bypass_man/support/http_client.rb +12 -6
- data/lib/procon_bypass_man/support/load_agv.rb +20 -0
- data/lib/procon_bypass_man/support/procon_performance_http_client.rb +7 -0
- data/lib/procon_bypass_man/support/renice_command.rb +17 -0
- data/lib/procon_bypass_man/support/retryable.rb +16 -0
- data/lib/procon_bypass_man/support/signal_handler.rb +1 -1
- data/lib/procon_bypass_man/version.rb +1 -1
- data/lib/procon_bypass_man/websocket/client.rb +2 -2
- data/lib/procon_bypass_man/worker.rb +32 -0
- data/lib/procon_bypass_man.rb +53 -10
- data/procon_bypass_man.gemspec +4 -2
- data/project_template/README.md +0 -5
- data/project_template/app.rb +17 -11
- data/project_template/app.rb.erb +59 -0
- data/project_template/lib/app_generator.rb +31 -0
- data/project_template/web.rb +1 -1
- data/sig/main.rbs +10 -52
- data/tmp/.keep +0 -0
- metadata +43 -10
- data/lib/procon_bypass_man/background/job_runner.rb +0 -45
- data/lib/procon_bypass_man/background/jobs/concerns/has_internal_api_setting.rb +0 -5
- data/lib/procon_bypass_man/background/jobs/concerns/job_runnable.rb +0 -16
- data/lib/procon_bypass_man/background/jobs/report_pressed_buttons_job.rb +0 -15
- data/lib/procon_bypass_man/bypass/usb_hid_logger.rb +0 -47
- data/lib/procon_bypass_man/io_monitor.rb +0 -108
- data/lib/procon_bypass_man/support/server_pool.rb +0 -46
@@ -0,0 +1,20 @@
|
|
1
|
+
module ProconBypassMan
|
2
|
+
class LoadAgv
|
3
|
+
PATH = '/proc/loadavg'
|
4
|
+
|
5
|
+
# @return [[Integer, Integer, Integer]]
|
6
|
+
def get
|
7
|
+
loadavg = get_proc_loadavg
|
8
|
+
loadavg =~ /^([0-9.]+)\s([0-9.]+)\s([0-9.]+)/
|
9
|
+
return [$1.to_f, $2.to_f, $3.to_f].join("-")
|
10
|
+
rescue Errno::ENOENT
|
11
|
+
""
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def get_proc_loadavg
|
17
|
+
File.read('/proc/loadavg')
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module ProconBypassMan
|
2
|
+
class ReniceCommand
|
3
|
+
def self.change_priority(to: , pid: )
|
4
|
+
cmd =
|
5
|
+
case to
|
6
|
+
when :high
|
7
|
+
"renice -n -20 -p #{pid}"
|
8
|
+
when :low
|
9
|
+
"renice -n 20 -p #{pid}"
|
10
|
+
else
|
11
|
+
raise "unknown priority"
|
12
|
+
end
|
13
|
+
ProconBypassMan.logger.debug { "[SHELL] #{cmd}" }
|
14
|
+
`#{cmd}`
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module ProconBypassMan
|
2
|
+
class Retryable
|
3
|
+
def self.retryable(tries: , retried: 0, on_no_retry: [])
|
4
|
+
return yield(retried)
|
5
|
+
rescue *on_no_retry
|
6
|
+
raise
|
7
|
+
rescue
|
8
|
+
if tries <= retried
|
9
|
+
raise
|
10
|
+
else
|
11
|
+
retried = retried + 1
|
12
|
+
retry
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -99,11 +99,11 @@ module ProconBypassMan
|
|
99
99
|
def self.validate_and_run_remote_macro(data: )
|
100
100
|
pbm_job_hash = data.dig("message")
|
101
101
|
begin
|
102
|
-
remote_macro_object = ProconBypassMan::RemoteMacroObject.new(name: pbm_job_hash["name"],
|
102
|
+
remote_macro_object = ProconBypassMan::RemoteMacro::RemoteMacroObject.new(name: pbm_job_hash["name"],
|
103
103
|
uuid: pbm_job_hash["uuid"],
|
104
104
|
steps: pbm_job_hash["steps"])
|
105
105
|
remote_macro_object.validate!
|
106
|
-
rescue ProconBypassMan::RemoteMacroObject::ValidationError => e
|
106
|
+
rescue ProconBypassMan::RemoteMacro::RemoteMacroObject::ValidationError => e
|
107
107
|
ProconBypassMan::SendErrorCommand.execute(error: e)
|
108
108
|
return
|
109
109
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module ProconBypassMan
|
2
|
+
class Worker
|
3
|
+
attr_accessor :pid
|
4
|
+
|
5
|
+
def self.run
|
6
|
+
new.run
|
7
|
+
end
|
8
|
+
|
9
|
+
# @param [Boolean]
|
10
|
+
def run
|
11
|
+
return self if @thread
|
12
|
+
@thread = Thread.new do
|
13
|
+
while(item = ProconBypassMan::Background::JobQueue.pop)
|
14
|
+
begin
|
15
|
+
# プロセスを越えるので、文字列でenqueueしてくれる前提. evalしてクラスにする
|
16
|
+
ProconBypassMan::Background::JobPerformer.new(klass: eval(item[:job_class]), args: item[:args]).perform
|
17
|
+
rescue => e
|
18
|
+
ProconBypassMan.logger.error(e)
|
19
|
+
sleep(0.2) # busy loopしないように
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
return self
|
25
|
+
end
|
26
|
+
|
27
|
+
# 重要な非同期ジョブは存在しないのでqueueが捌けるのを待たずにkill
|
28
|
+
def shutdown
|
29
|
+
@thread&.kill
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/procon_bypass_man.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "logger"
|
2
4
|
require 'yaml'
|
3
5
|
require "json"
|
@@ -10,10 +12,9 @@ require "ext/em_pure_ruby"
|
|
10
12
|
require "ext/module"
|
11
13
|
require "resolv-replace"
|
12
14
|
require "pbmenv"
|
15
|
+
require "blue_green_process"
|
13
16
|
|
14
17
|
require_relative "procon_bypass_man/version"
|
15
|
-
require_relative "procon_bypass_man/remote_pbm_action"
|
16
|
-
require_relative "procon_bypass_man/remote_macro"
|
17
18
|
|
18
19
|
require_relative "procon_bypass_man/device_connection"
|
19
20
|
require_relative "procon_bypass_man/support/usb_device_controller"
|
@@ -26,16 +27,21 @@ require_relative "procon_bypass_man/support/yaml_writer"
|
|
26
27
|
require_relative "procon_bypass_man/support/safe_timeout"
|
27
28
|
require_relative "procon_bypass_man/support/compress_array"
|
28
29
|
require_relative "procon_bypass_man/support/uptime"
|
30
|
+
require_relative "procon_bypass_man/support/load_agv"
|
29
31
|
require_relative "procon_bypass_man/support/on_memory_cache"
|
30
32
|
require_relative "procon_bypass_man/support/http_client"
|
31
33
|
require_relative "procon_bypass_man/support/report_http_client"
|
32
34
|
require_relative "procon_bypass_man/support/remote_macro_http_client"
|
33
35
|
require_relative "procon_bypass_man/support/update_remote_pbm_action_status_http_client"
|
34
36
|
require_relative "procon_bypass_man/support/send_device_stats_http_client"
|
35
|
-
require_relative "procon_bypass_man/support/
|
37
|
+
require_relative "procon_bypass_man/support/procon_performance_http_client"
|
36
38
|
require_relative "procon_bypass_man/support/analog_stick_hypotenuse_tilting_power_scaler"
|
37
39
|
require_relative "procon_bypass_man/support/never_exit_accidentally"
|
38
40
|
require_relative "procon_bypass_man/support/cycle_sleep"
|
41
|
+
require_relative "procon_bypass_man/support/can_over_process"
|
42
|
+
require_relative "procon_bypass_man/support/gc"
|
43
|
+
require_relative "procon_bypass_man/support/retryable"
|
44
|
+
require_relative "procon_bypass_man/support/renice_command"
|
39
45
|
require_relative "procon_bypass_man/procon_display"
|
40
46
|
require_relative "procon_bypass_man/background"
|
41
47
|
require_relative "procon_bypass_man/commands"
|
@@ -53,10 +59,14 @@ require_relative "procon_bypass_man/procon/analog_stick_manipulator"
|
|
53
59
|
require_relative "procon_bypass_man/remote_pbm_action/value_objects/remote_pbm_action_object"
|
54
60
|
require_relative "procon_bypass_man/scheduler"
|
55
61
|
require_relative "procon_bypass_man/plugins"
|
62
|
+
require_relative "procon_bypass_man/worker"
|
56
63
|
require_relative "procon_bypass_man/websocket/client"
|
57
64
|
require_relative "procon_bypass_man/websocket/watchdog"
|
58
65
|
require_relative "procon_bypass_man/websocket/forever"
|
59
66
|
|
67
|
+
require_relative "procon_bypass_man/remote_pbm_action"
|
68
|
+
require_relative "procon_bypass_man/remote_macro"
|
69
|
+
|
60
70
|
STDOUT.sync = true
|
61
71
|
Thread.abort_on_exception = true
|
62
72
|
|
@@ -67,11 +77,18 @@ module ProconBypassMan
|
|
67
77
|
class CouldNotLoadConfigError < StandardError; end
|
68
78
|
class NotFoundProconError < StandardError; end
|
69
79
|
|
80
|
+
class InterruptForRestart < StandardError; end
|
81
|
+
|
82
|
+
class << self
|
83
|
+
attr_accessor :worker
|
84
|
+
end
|
85
|
+
|
70
86
|
# @return [void]
|
71
87
|
def self.run(setting_path: nil)
|
72
88
|
ProconBypassMan::PrintMessageCommand.execute(text: "PBMを起動しています")
|
73
89
|
initialize_pbm
|
74
90
|
|
91
|
+
# 設定ファイルの読み込み
|
75
92
|
begin
|
76
93
|
ProconBypassMan::ButtonsSettingConfiguration::Loader.load(setting_path: setting_path)
|
77
94
|
rescue ProconBypassMan::CouldNotLoadConfigError
|
@@ -84,6 +101,7 @@ module ProconBypassMan
|
|
84
101
|
return
|
85
102
|
end
|
86
103
|
|
104
|
+
# デバイスの接続フェーズ
|
87
105
|
begin
|
88
106
|
gadget, procon = ProconBypassMan::DeviceConnection::Command.execute!
|
89
107
|
rescue ProconBypassMan::DeviceConnection::NotFoundProconError
|
@@ -95,7 +113,7 @@ module ProconBypassMan
|
|
95
113
|
end
|
96
114
|
return
|
97
115
|
rescue ProconBypassMan::DeviceConnection::TimeoutError
|
98
|
-
ProconBypassMan::SendErrorCommand.execute(error: "
|
116
|
+
ProconBypassMan::SendErrorCommand.execute(error: "接続に失敗しました。プロコンとRaspberry Piのケーブルを差し直して、再実行してください。\n改善しない場合は、app.logの中身を添えて不具合報告をお願いします。")
|
99
117
|
ProconBypassMan::DeviceStatus.change_to_connected_but_sleeping!
|
100
118
|
%w(TERM INT).each do |sig|
|
101
119
|
Kernel.trap(sig) { exit 0 }
|
@@ -131,33 +149,58 @@ module ProconBypassMan
|
|
131
149
|
ProconBypassMan::Procon::ModeRegistry.reset!
|
132
150
|
ProconBypassMan::Procon.reset!
|
133
151
|
ProconBypassMan::ButtonsSettingConfiguration.instance.reset!
|
134
|
-
ProconBypassMan::IOMonitor.reset!
|
135
152
|
end
|
136
153
|
|
137
154
|
# @return [void]
|
138
155
|
def self.initialize_pbm
|
139
|
-
ProconBypassMan::
|
140
|
-
ProconBypassMan::Background::
|
156
|
+
ProconBypassMan::ReniceCommand.change_priority(to: :low, pid: $$)
|
157
|
+
ProconBypassMan::Background::JobQueue.start!
|
141
158
|
ProconBypassMan::Websocket::Client.start!
|
142
|
-
ProconBypassMan::
|
159
|
+
# TODO ProconBypassMan::DrbObjects.start_all! みたいな感じで書きたい
|
160
|
+
ProconBypassMan::RemoteMacro::QueueOverProcess.start!
|
161
|
+
ProconBypassMan::Procon::PerformanceMeasurement::QueueOverProcess.start!
|
162
|
+
ProconBypassMan::Scheduler.start!
|
143
163
|
|
144
164
|
ProconBypassMan::WriteDeviceIdCommand.execute
|
145
165
|
ProconBypassMan::WriteSessionIdCommand.execute
|
146
|
-
`renice -n -20 -p #{$$}`
|
147
166
|
File.write(pid_path, $$)
|
148
167
|
ProconBypassMan::DeviceStatus.change_to_running!
|
149
168
|
end
|
150
169
|
|
170
|
+
# @return [void]
|
151
171
|
def self.ready_pbm
|
152
172
|
ProconBypassMan::PrintBootMessageCommand.execute
|
153
173
|
ProconBypassMan::ReportLoadConfigJob.perform_async(ProconBypassMan.config.raw_setting)
|
174
|
+
|
175
|
+
self.worker = ProconBypassMan::Worker.run
|
176
|
+
end
|
177
|
+
|
178
|
+
# @return [void]
|
179
|
+
def self.after_fork_on_bypass_process
|
180
|
+
ProconBypassMan::ReniceCommand.change_priority(to: :high, pid: $$)
|
181
|
+
::GC.start
|
182
|
+
DRb.start_service if defined?(DRb)
|
183
|
+
# GC対策することによって一時的に削除した機能
|
184
|
+
# ProconBypassMan::ProconDisplay::Server.start!
|
185
|
+
|
186
|
+
DRb.start_service if defined?(DRb)
|
187
|
+
BlueGreenProcess.configure do |config|
|
188
|
+
config.after_fork = -> {
|
189
|
+
DRb.start_service if defined?(DRb)
|
190
|
+
ProconBypassMan::RemoteMacroReceiver.start!
|
191
|
+
BlueGreenProcess.config.logger = ProconBypassMan.logger
|
192
|
+
}
|
193
|
+
config.shared_variables = [:buttons, :current_layer_key]
|
194
|
+
end
|
154
195
|
end
|
155
196
|
|
156
197
|
# @return [void]
|
157
198
|
def self.terminate_pbm
|
158
199
|
FileUtils.rm_rf(ProconBypassMan.pid_path)
|
159
200
|
FileUtils.rm_rf(ProconBypassMan.digest_path)
|
160
|
-
ProconBypassMan::QueueOverProcess.shutdown
|
201
|
+
ProconBypassMan::RemoteMacro::QueueOverProcess.shutdown
|
202
|
+
ProconBypassMan::Procon::PerformanceMeasurement::QueueOverProcess.shutdown
|
203
|
+
self.worker&.shutdown
|
161
204
|
end
|
162
205
|
|
163
206
|
# @return [void]
|
data/procon_bypass_man.gemspec
CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
|
|
12
12
|
spec.description = spec.summary
|
13
13
|
spec.homepage = "https://github.com/splaplapla/procon_bypass_man"
|
14
14
|
spec.license = "MIT"
|
15
|
-
spec.required_ruby_version = Gem::Requirement.new(">=
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
|
16
16
|
|
17
17
|
spec.metadata["homepage_uri"] = spec.homepage
|
18
18
|
spec.metadata["source_code_uri"] = spec.homepage
|
@@ -28,9 +28,11 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.require_paths = ["lib"]
|
29
29
|
|
30
30
|
# Uncomment to register a new dependency of your gem
|
31
|
-
spec.add_dependency "pbmenv", ">= 0.1.9" # Pbmenv.install
|
31
|
+
spec.add_dependency "pbmenv", ">= 0.1.9" # enable_pbm_cloud連携機能でPbmenv.installを使っている.
|
32
32
|
spec.add_dependency "action_cable_client"
|
33
33
|
spec.add_dependency "sorted_set"
|
34
|
+
spec.add_dependency "blue_green_process"
|
35
|
+
# spec.add_dependency "blue_green_process"
|
34
36
|
|
35
37
|
# For more information and examples about making a new gem, checkout our
|
36
38
|
# guide at: https://bundler.io/guides/creating_gem.html
|
data/project_template/README.md
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
# Project Template
|
2
2
|
* これらは https://github.com/splaplapla/pbmenv がinstallするときに配備するファイルです
|
3
|
-
* pbm_webはオプショナルです
|
4
3
|
|
5
4
|
## systemdを使ってサービスに登録する方法
|
6
5
|
systemctl enableした後は、次回のOS起動時にserviceも自動起動します
|
@@ -8,13 +7,9 @@ systemctl enableした後は、次回のOS起動時にserviceも自動起動し
|
|
8
7
|
* pbm
|
9
8
|
* sudo systemctl link /usr/share/pbm/current/systemd_units/pbm.service
|
10
9
|
* sudo systemctl enable pbm.service
|
11
|
-
* pbm_web
|
12
|
-
* sudo systemctl link /usr/share/pbm/current/systemd_units/pbm_web.service
|
13
|
-
* sudo systemctl enable pbm_web.service
|
14
10
|
|
15
11
|
## systemdを使ってサービスから解除する方法
|
16
12
|
* sudo systemctl disable pbm.service
|
17
|
-
* sudo systemctl disable pbm_web.service
|
18
13
|
|
19
14
|
### CheatSheet
|
20
15
|
* systemctl daemon-reload
|
data/project_template/app.rb
CHANGED
@@ -2,20 +2,31 @@
|
|
2
2
|
|
3
3
|
require 'bundler/inline'
|
4
4
|
|
5
|
+
retry_count_on_git_command_error = 0
|
5
6
|
begin
|
7
|
+
if retry_count_on_git_command_error > 10
|
8
|
+
STDOUT.puts "Stopped the procon_bypass_man program because could not download any source codes."
|
9
|
+
exit 1
|
10
|
+
end
|
11
|
+
|
6
12
|
gemfile do
|
7
13
|
source 'https://rubygems.org'
|
8
14
|
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
|
9
|
-
gem 'procon_bypass_man', '0.
|
15
|
+
gem 'procon_bypass_man', '0.3.0'
|
10
16
|
end
|
11
17
|
rescue Bundler::Source::Git::GitCommandError => e
|
18
|
+
retry_count_on_git_command_error = retry_count_on_git_command_error + 1
|
19
|
+
sleep(5) # サービスの起動順によっては、まだoffline状態なので待機する
|
20
|
+
|
12
21
|
# install中に強制終了するとgitの管理ファイルが不正状態になり、次のエラーが起きるので発生したらcache directoryを削除する
|
13
22
|
#"Git error: command `git fetch --force --quiet --tags https://github.com/splaplapla/procon_bypass_man refs/heads/\\*:refs/heads/\\*` in directory /home/pi/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/cache/bundler/git/procon_bypass_man-ae4c9016d76b667658c8ba66f3bbd2eebf2656af has failed.\n\nIf this error persists you could try removing the cache directory '/home/pi/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/cache/bundler/git/procon_bypass_man-ae4c9016d76b667658c8ba66f3bbd2eebf2656af'"
|
14
|
-
if /try removing the cache directory '([^']+)'/ =~ e.message
|
23
|
+
if /try removing the cache directory '([^']+)'/ =~ e.message && $1&.start_with?('/home/pi/.rbenv')
|
15
24
|
require 'fileutils'
|
16
25
|
FileUtils.rm_rf($1)
|
17
|
-
|
26
|
+
STDOUT.puts "Deleted #{$1}"
|
18
27
|
end
|
28
|
+
|
29
|
+
retry
|
19
30
|
end
|
20
31
|
|
21
32
|
ProconBypassMan.configure do |config|
|
@@ -26,8 +37,9 @@ ProconBypassMan.configure do |config|
|
|
26
37
|
# バイパスするログを全部app.logに流すか
|
27
38
|
config.verbose_bypass_log = false
|
28
39
|
|
29
|
-
# webからProconBypassManを操作できるweb
|
30
|
-
#
|
40
|
+
# webからProconBypassManを操作できるwebサービスと連携します
|
41
|
+
# 連携中はエラーログ、パフォーマンスに関するメトリクスを送信します
|
42
|
+
# config.api_servers = 'https://pbm-cloud.herokuapp.com'
|
31
43
|
|
32
44
|
# エラーが起きたらerror.logに書き込みます
|
33
45
|
config.enable_critical_error_logging = true
|
@@ -35,14 +47,8 @@ ProconBypassMan.configure do |config|
|
|
35
47
|
# pbm-cloudで使う場合はnever_exitにtrueをセットしてください. trueがセットされている場合、不慮の事故が発生してもプロセスが終了しなくなります
|
36
48
|
config.never_exit_accidentally = true
|
37
49
|
|
38
|
-
# 毎秒行ったIOをログに出力するか
|
39
|
-
config.io_monitor_logging = false
|
40
|
-
|
41
50
|
# 接続に成功したらコントローラーのHOME LEDを光らせるか
|
42
51
|
config.enable_home_led_on_connect = true
|
43
|
-
|
44
|
-
# 操作が高頻度で固まるときは、 gadget_to_procon_interval の数値を大きくしてください
|
45
|
-
config.bypass_mode = { mode: :normal, gadget_to_procon_interval: 10 }
|
46
52
|
end
|
47
53
|
|
48
54
|
ProconBypassMan.run(setting_path: "/usr/share/pbm/current/setting.yml")
|
@@ -0,0 +1,59 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/inline'
|
4
|
+
|
5
|
+
retry_count_on_git_command_error = 0
|
6
|
+
begin
|
7
|
+
if retry_count_on_git_command_error > 10
|
8
|
+
STDOUT.puts "Stopped the procon_bypass_man program because could not download any source codes."
|
9
|
+
exit 1
|
10
|
+
end
|
11
|
+
|
12
|
+
gemfile do
|
13
|
+
source 'https://rubygems.org'
|
14
|
+
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
|
15
|
+
gem 'procon_bypass_man', '0.3.0'
|
16
|
+
end
|
17
|
+
rescue Bundler::Source::Git::GitCommandError => e
|
18
|
+
retry_count_on_git_command_error = retry_count_on_git_command_error + 1
|
19
|
+
sleep(5) # サービスの起動順によっては、まだoffline状態なので待機する
|
20
|
+
|
21
|
+
# install中に強制終了するとgitの管理ファイルが不正状態になり、次のエラーが起きるので発生したらcache directoryを削除する
|
22
|
+
#"Git error: command `git fetch --force --quiet --tags https://github.com/splaplapla/procon_bypass_man refs/heads/\\*:refs/heads/\\*` in directory /home/pi/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/cache/bundler/git/procon_bypass_man-ae4c9016d76b667658c8ba66f3bbd2eebf2656af has failed.\n\nIf this error persists you could try removing the cache directory '/home/pi/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/cache/bundler/git/procon_bypass_man-ae4c9016d76b667658c8ba66f3bbd2eebf2656af'"
|
23
|
+
if /try removing the cache directory '([^']+)'/ =~ e.message && $1&.start_with?('/home/pi/.rbenv')
|
24
|
+
require 'fileutils'
|
25
|
+
FileUtils.rm_rf($1)
|
26
|
+
STDOUT.puts "Deleted #{$1}"
|
27
|
+
end
|
28
|
+
|
29
|
+
retry
|
30
|
+
end
|
31
|
+
|
32
|
+
ProconBypassMan.configure do |config|
|
33
|
+
config.root = File.expand_path(__dir__)
|
34
|
+
config.logger = Logger.new("#{ProconBypassMan.root}/app.log", 1, 1024 * 1024 * 1)
|
35
|
+
config.logger.level = :debug
|
36
|
+
|
37
|
+
# バイパスするログを全部app.logに流すか
|
38
|
+
config.verbose_bypass_log = false
|
39
|
+
|
40
|
+
# webからProconBypassManを操作できるwebサービスと連携します
|
41
|
+
# 連携中はエラーログ、パフォーマンスに関するメトリクスを送信します
|
42
|
+
<%- api_server_config = "config.api_servers = 'https://pbm-cloud.herokuapp.com'" -%>
|
43
|
+
<%- if enable_integration_with_pbm_cloud -%>
|
44
|
+
<%= api_server_config %>
|
45
|
+
<%- else -%>
|
46
|
+
<%= "# #{api_server_config}" %>
|
47
|
+
<%- end -%>
|
48
|
+
|
49
|
+
# エラーが起きたらerror.logに書き込みます
|
50
|
+
config.enable_critical_error_logging = true
|
51
|
+
|
52
|
+
# pbm-cloudで使う場合はnever_exitにtrueをセットしてください. trueがセットされている場合、不慮の事故が発生してもプロセスが終了しなくなります
|
53
|
+
config.never_exit_accidentally = true
|
54
|
+
|
55
|
+
# 接続に成功したらコントローラーのHOME LEDを光らせるか
|
56
|
+
config.enable_home_led_on_connect = true
|
57
|
+
end
|
58
|
+
|
59
|
+
ProconBypassMan.run(setting_path: "/usr/share/pbm/current/setting.yml")
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require "erb"
|
2
|
+
|
3
|
+
# NOTE pbmenvで参照しているクラス
|
4
|
+
# 後方互換を維持するために、パラメータの削除・必須をしてはいけない
|
5
|
+
class AppGenerator
|
6
|
+
attr_reader :prefix_path
|
7
|
+
|
8
|
+
# @param [String] prefix_path
|
9
|
+
# @param [Boolean] enable_integration_with_pbm_cloud
|
10
|
+
def initialize(prefix_path: , enable_integration_with_pbm_cloud: )
|
11
|
+
@prefix_path = prefix_path
|
12
|
+
@enable_integration_with_pbm_cloud = enable_integration_with_pbm_cloud
|
13
|
+
end
|
14
|
+
|
15
|
+
def generate
|
16
|
+
erb = File.read(template_path)
|
17
|
+
enable_integration_with_pbm_cloud = @enable_integration_with_pbm_cloud
|
18
|
+
app_rb = ERB.new(erb, nil, '-').result(binding)
|
19
|
+
File.write(output_path, app_rb)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def template_path
|
25
|
+
File.join(prefix_path, "app.rb.erb")
|
26
|
+
end
|
27
|
+
|
28
|
+
def output_path
|
29
|
+
File.join(prefix_path, "app.rb")
|
30
|
+
end
|
31
|
+
end
|
data/project_template/web.rb
CHANGED
@@ -10,7 +10,7 @@ end
|
|
10
10
|
|
11
11
|
ProconBypassMan::Web.configure do |config|
|
12
12
|
config.root = File.expand_path(__dir__)
|
13
|
-
config.logger = Logger.new("#{ProconBypassMan::Web.root}/web.log", 1, 1024 * 1024 *
|
13
|
+
config.logger = Logger.new("#{ProconBypassMan::Web.root}/web.log", 1, 1024 * 1024 * 1)
|
14
14
|
end
|
15
15
|
|
16
16
|
ProconBypassMan::Web::Server.start
|
data/sig/main.rbs
CHANGED
@@ -174,6 +174,8 @@ class ProconBypassMan::Configuration
|
|
174
174
|
|
175
175
|
def pid_path: () -> String
|
176
176
|
|
177
|
+
def worker_pid_path: () -> String
|
178
|
+
|
177
179
|
def digest_path: () -> String
|
178
180
|
|
179
181
|
def cache: () -> ProconBypassMan::OnMemoryCache
|
@@ -186,7 +188,6 @@ class ProconBypassMan::Configuration
|
|
186
188
|
attr_reader api_server: untyped
|
187
189
|
attr_reader api_servers: untyped
|
188
190
|
attr_writer never_exit_accidentally: bool
|
189
|
-
attr_writer io_monitor_logging: bool
|
190
191
|
|
191
192
|
attr_accessor enable_critical_error_logging: bool
|
192
193
|
|
@@ -213,9 +214,13 @@ class ProconBypassMan::Configuration
|
|
213
214
|
|
214
215
|
def enable_ws?: () -> bool
|
215
216
|
|
216
|
-
def
|
217
|
+
def has_api_server?: () -> bool
|
218
|
+
|
219
|
+
def enable_procon_performance_measurement?: () -> bool
|
217
220
|
|
218
|
-
def
|
221
|
+
def server: () -> untyped
|
222
|
+
|
223
|
+
def internal_server: () -> untyped
|
219
224
|
|
220
225
|
def internal_servers: () -> ::Array[string | nil]
|
221
226
|
|
@@ -226,8 +231,6 @@ class ProconBypassMan::Configuration
|
|
226
231
|
def verbose_bypass_log: () -> bool
|
227
232
|
|
228
233
|
def never_exit_accidentally: () -> bool
|
229
|
-
|
230
|
-
def io_monitor_logging: () -> bool
|
231
234
|
end
|
232
235
|
|
233
236
|
|
@@ -274,35 +277,6 @@ class ProconBypassMan::DeviceConnector
|
|
274
277
|
def init_devices: () -> untyped
|
275
278
|
end
|
276
279
|
|
277
|
-
module ProconBypassMan
|
278
|
-
class Counter
|
279
|
-
attr_accessor label: untyped
|
280
|
-
|
281
|
-
attr_accessor table: untyped
|
282
|
-
|
283
|
-
attr_accessor previous_table: untyped
|
284
|
-
|
285
|
-
def initialize: (label: untyped label) -> untyped
|
286
|
-
|
287
|
-
# アクティブなバケットは1つだけ
|
288
|
-
def record: (untyped event_name) -> untyped
|
289
|
-
|
290
|
-
def formated_previous_table: () -> ::String
|
291
|
-
end
|
292
|
-
|
293
|
-
module IOMonitor
|
294
|
-
def self.new: (label: untyped label) -> untyped
|
295
|
-
|
296
|
-
# @return [Array<Counter>]
|
297
|
-
def self.targets: () -> untyped
|
298
|
-
|
299
|
-
# ここで集計する
|
300
|
-
def self.start!: () -> untyped
|
301
|
-
|
302
|
-
def self.reset!: () -> untyped
|
303
|
-
end
|
304
|
-
end
|
305
|
-
|
306
280
|
class ProconBypassMan::Processor
|
307
281
|
# @return [String] binary
|
308
282
|
def initialize: (untyped binary) -> untyped
|
@@ -598,11 +572,11 @@ end
|
|
598
572
|
|
599
573
|
module ProconBypassMan
|
600
574
|
class HttpClient
|
601
|
-
@
|
575
|
+
@server: untyped
|
602
576
|
@uri: ::URI
|
603
577
|
@retry_on_connection_error: false
|
604
578
|
|
605
|
-
def initialize: (path: String,
|
579
|
+
def initialize: (path: String, server: untyped, ?retry_on_connection_error: false) -> void
|
606
580
|
def get: -> nil
|
607
581
|
def post: (request_body: untyped) -> nil
|
608
582
|
def put: (request_body: untyped) -> nil
|
@@ -645,22 +619,6 @@ module ProconBypassMan
|
|
645
619
|
end
|
646
620
|
end
|
647
621
|
|
648
|
-
module ProconBypassMan
|
649
|
-
class ServerPool
|
650
|
-
@servers: Array[String]
|
651
|
-
@index: Integer?
|
652
|
-
|
653
|
-
def initialize: (servers: Array[String]) -> void
|
654
|
-
def pick: -> String?
|
655
|
-
def server: -> String?
|
656
|
-
def next!: -> nil
|
657
|
-
|
658
|
-
private
|
659
|
-
def reset: -> Integer
|
660
|
-
def inc_index: -> Integer
|
661
|
-
end
|
662
|
-
end
|
663
|
-
|
664
622
|
module ProconBypassMan
|
665
623
|
class CompressArray
|
666
624
|
@array: [String]
|
data/tmp/.keep
ADDED
File without changes
|