tengine_core 0.5.28
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/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +40 -0
- data/Gemfile.lock +95 -0
- data/README.md +54 -0
- data/Rakefile +44 -0
- data/VERSION +1 -0
- data/bin/tengine_atd +8 -0
- data/bin/tengine_heartbeat_watchd +8 -0
- data/bin/tengined +182 -0
- data/examples/VERSION +1 -0
- data/examples/uc01_execute_processing_for_event.rb +11 -0
- data/examples/uc02_fire_another_event.rb +16 -0
- data/examples/uc03_2handlers_for_1event.rb +16 -0
- data/examples/uc08_if_both_a_and_b_occurs.rb +11 -0
- data/examples/uc10_if_the_event_occurs_at_the_server.rb +15 -0
- data/examples/uc50_commit_event_at_first.rb +17 -0
- data/examples/uc51_commit_event_at_first_submit.rb +29 -0
- data/examples/uc52_commit_event_after_all_handler_submit.rb +31 -0
- data/examples/uc52_never_commit_event_unless_all_handler_submit.rb +31 -0
- data/examples/uc60_event_in_handler.rb +18 -0
- data/examples/uc62_session_in_driver.rb +16 -0
- data/examples/uc64_safety_countup.rb +14 -0
- data/examples/uc70_driver_enabled_on_activation.rb +13 -0
- data/examples/uc71_driver_disabled_on_activation.rb +14 -0
- data/examples/uc72_setup_eventmachine.rb +17 -0
- data/examples/uc80_raise_io_error.rb +10 -0
- data/examples/uc81_raise_runtime_error.rb +10 -0
- data/examples2/driver01.rb +18 -0
- data/examples2/driver02.rb +19 -0
- data/examples2/uc08_if_both_a_and_b_occurs.rb +13 -0
- data/examples2/uc10_if_the_event_occurs_at_the_server.rb +18 -0
- data/examples2/uc51_commit_event_at_first_submit_1.rb +16 -0
- data/examples2/uc51_commit_event_at_first_submit_2.rb +17 -0
- data/examples2/uc51_commit_event_at_first_submit_3.rb +17 -0
- data/examples2/uc62_session_in_driver.rb +16 -0
- data/examples2/uc71_driver_disabled_on_activation.rb +16 -0
- data/failure_examples/VERSION +1 -0
- data/failure_examples/uc53_submit_outside_of_handler.rb +15 -0
- data/failure_examples/uc61_event_outside_of_handler.rb +12 -0
- data/failure_examples/uc63_session_outside_of_driver.rb +13 -0
- data/lib/tengine/core.rb +74 -0
- data/lib/tengine/core/bootstrap.rb +123 -0
- data/lib/tengine/core/collection_accessible.rb +34 -0
- data/lib/tengine/core/config.rb +10 -0
- data/lib/tengine/core/config/atd.rb +225 -0
- data/lib/tengine/core/config/core.rb +319 -0
- data/lib/tengine/core/config/heartbeat_watcher.rb +229 -0
- data/lib/tengine/core/connection_test/.gitignore +1 -0
- data/lib/tengine/core/connection_test/fire_bar_on_foo.rb +16 -0
- data/lib/tengine/core/driveable.rb +213 -0
- data/lib/tengine/core/driver.rb +69 -0
- data/lib/tengine/core/driver/finder.rb +42 -0
- data/lib/tengine/core/dsl_evaluator.rb +110 -0
- data/lib/tengine/core/dsl_filter_def.rb +11 -0
- data/lib/tengine/core/dsl_loader.rb +108 -0
- data/lib/tengine/core/event.rb +145 -0
- data/lib/tengine/core/event/finder.rb +82 -0
- data/lib/tengine/core/event_exception_reportable.rb +88 -0
- data/lib/tengine/core/event_wrapper.rb +21 -0
- data/lib/tengine/core/find_by_name.rb +31 -0
- data/lib/tengine/core/handler.rb +152 -0
- data/lib/tengine/core/handler_path.rb +33 -0
- data/lib/tengine/core/heartbeat_watcher.rb +161 -0
- data/lib/tengine/core/io_to_logger.rb +22 -0
- data/lib/tengine/core/kernel.rb +510 -0
- data/lib/tengine/core/kernel_runtime.rb +91 -0
- data/lib/tengine/core/method_traceable.rb +38 -0
- data/lib/tengine/core/mongoid_fix.rb +19 -0
- data/lib/tengine/core/mutex.rb +177 -0
- data/lib/tengine/core/optimistic_lock.rb +69 -0
- data/lib/tengine/core/plugins.rb +54 -0
- data/lib/tengine/core/schedule.rb +21 -0
- data/lib/tengine/core/scheduler.rb +156 -0
- data/lib/tengine/core/selectable_attr.rb +29 -0
- data/lib/tengine/core/session.rb +21 -0
- data/lib/tengine/core/session_wrapper.rb +68 -0
- data/lib/tengine/core/setting.rb +21 -0
- data/lib/tengine/core/validation.rb +36 -0
- data/lib/tengine/errors.rb +18 -0
- data/lib/tengine/rspec.rb +8 -0
- data/lib/tengine/rspec/context_wrapper.rb +51 -0
- data/lib/tengine/rspec/extension.rb +53 -0
- data/lib/tengine_core.rb +23 -0
- data/spec/factories/tengine_core_drivers.rb +10 -0
- data/spec/factories/tengine_core_events.rb +14 -0
- data/spec/factories/tengine_core_handler_paths.rb +9 -0
- data/spec/factories/tengine_core_handlers.rb +9 -0
- data/spec/factories/tengine_core_sessions.rb +9 -0
- data/spec/mongoid.yml +35 -0
- data/spec/spec_helper.rb +48 -0
- data/spec/support/mongo_index_key_log.rb +91 -0
- data/spec/tengine/core/bootstrap_spec.rb +278 -0
- data/spec/tengine/core/bugfix/bind_dsl_file_in_multi_byte_dir_spec.rb +21 -0
- data/spec/tengine/core/bugfix/enabled_on_activation_spec.rb +112 -0
- data/spec/tengine/core/bugfix/receive_event_spec.rb +133 -0
- data/spec/tengine/core/bugfix/use_dsl_version_method.rb +12 -0
- data/spec/tengine/core/bugfix/use_dsl_version_method_spec.rb +28 -0
- data/spec/tengine/core/bugfix/use_event_in_handler_dsl.rb +11 -0
- data/spec/tengine/core/bugfix//351/235/236ACSII/343/201/256/343/203/206/343/202/231/343/202/243/343/203/254/343/202/257/343/203/210/343/203/252/345/220/215/source_location_encoding.rb +35 -0
- data/spec/tengine/core/bugfix//351/235/236ACSII/343/201/256/343/203/206/343/202/231/343/202/243/343/203/254/343/202/257/343/203/210/343/203/252/345/220/215//351/235/236ASCII/343/201/256/343/203/225/343/202/241/343/202/244/343/203/253/345/220/215_dsl.rb +38 -0
- data/spec/tengine/core/bugfix//351/235/236ACSII/343/201/256/343/203/207/343/202/243/343/203/254/343/202/257/343/203/210/343/203/252/345/220/215/source_location_encoding.rb +35 -0
- data/spec/tengine/core/bugfix//351/235/236ACSII/343/201/256/343/203/207/343/202/243/343/203/254/343/202/257/343/203/210/343/203/252/345/220/215//351/235/236ASCII/343/201/256/343/203/225/343/202/241/343/202/244/343/203/253/345/220/215_dsl.rb +38 -0
- data/spec/tengine/core/config/atd_spec.rb +62 -0
- data/spec/tengine/core/config/core_spec.rb +479 -0
- data/spec/tengine/core/config/heartbeat_watcher_spec.rb +62 -0
- data/spec/tengine/core/config/syntax_error_in_erb.yml.erb +13 -0
- data/spec/tengine/core/config/wrong_category_name.yml.erb +13 -0
- data/spec/tengine/core/config/wrong_field_name.yml.erb +12 -0
- data/spec/tengine/core/config/wrong_yaml.yml.erb +13 -0
- data/spec/tengine/core/config_spec/another_port.yml +54 -0
- data/spec/tengine/core/config_spec/config_with_dir_absolute_load_path.yml +16 -0
- data/spec/tengine/core/config_spec/config_with_dir_relative_load_path.yml +16 -0
- data/spec/tengine/core/config_spec/config_with_file_absolute_load_path.yml +16 -0
- data/spec/tengine/core/config_spec/config_with_file_relative_load_path.yml +16 -0
- data/spec/tengine/core/config_spec/log_config_spec.rb +235 -0
- data/spec/tengine/core/driveable_spec.rb +240 -0
- data/spec/tengine/core/driver_spec.rb +159 -0
- data/spec/tengine/core/dsl_loader_spec.rb +172 -0
- data/spec/tengine/core/dsls/uc08_if_both_a_and_b_occurs_spec.rb +35 -0
- data/spec/tengine/core/dsls/uc10_if_the_event_occurs_at_the_server_spec.rb +58 -0
- data/spec/tengine/core/dsls/uc50_commit_event_at_first_spec.rb +29 -0
- data/spec/tengine/core/dsls/uc52_commit_event_after_all_handler_submit_spec.rb +33 -0
- data/spec/tengine/core/dsls/uc52_never_commit_event_unless_all_handler_submit_spec.rb +37 -0
- data/spec/tengine/core/dsls/uc53_submit_outside_of_handler_spec.rb +37 -0
- data/spec/tengine/core/dsls/uc60_event_in_handler_spec.rb +31 -0
- data/spec/tengine/core/dsls/uc61_event_outside_of_handler_spec.rb +37 -0
- data/spec/tengine/core/dsls/uc62_session_in_driver_spec.rb +36 -0
- data/spec/tengine/core/dsls/uc63_session_outside_of_driver_spec.rb +35 -0
- data/spec/tengine/core/dsls/uc64_safety_countup_spec.rb +134 -0
- data/spec/tengine/core/dsls/uc70_driver_enabled_on_activation_spec.rb +39 -0
- data/spec/tengine/core/dsls/uc71_driver_disabled_on_activation_spec.rb +36 -0
- data/spec/tengine/core/dsls/uc72_setup_eventmachine_spec.rb +39 -0
- data/spec/tengine/core/dsls/uc80_raise_io_error_spec.rb +53 -0
- data/spec/tengine/core/dsls/uc81_raise_runtime_error_spec.rb +49 -0
- data/spec/tengine/core/event/finder_spec.rb +136 -0
- data/spec/tengine/core/event_exception_reportable_spec.rb +33 -0
- data/spec/tengine/core/event_spec.rb +161 -0
- data/spec/tengine/core/event_wrapper_spec.rb +35 -0
- data/spec/tengine/core/handler_path_spec.rb +87 -0
- data/spec/tengine/core/handler_spec.rb +190 -0
- data/spec/tengine/core/heartbeat_watcher_spec.rb +131 -0
- data/spec/tengine/core/io_to_logger_spec.rb +30 -0
- data/spec/tengine/core/kernel_spec.rb +885 -0
- data/spec/tengine/core/mutex_spec.rb +184 -0
- data/spec/tengine/core/optimistic_lock_spec.rb +55 -0
- data/spec/tengine/core/scheculer_spec.rb +121 -0
- data/spec/tengine/core/selectable_attr_spec.rb +30 -0
- data/spec/tengine/core/session_spec.rb +104 -0
- data/spec/tengine/core/setting_spec.rb +79 -0
- data/spec/tengine/core_spec.rb +13 -0
- data/spec/tengine_spec.rb +14 -0
- data/tengine_core.gemspec +248 -0
- data/tmp/log/.gitignore +1 -0
- data/tmp/tengined_status/.gitignore +1 -0
- metadata +421 -0
data/.document
ADDED
data/.rspec
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
--color
|
data/Gemfile
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
source "http://rubygems.org"
|
|
3
|
+
|
|
4
|
+
# Add dependencies required to use your gem here.
|
|
5
|
+
# Example:
|
|
6
|
+
# gem "activesupport", ">= 2.3.5"
|
|
7
|
+
|
|
8
|
+
gem "activesupport", "~> 3.1.0"
|
|
9
|
+
gem "activemodel" , "~> 3.1.0"
|
|
10
|
+
|
|
11
|
+
gem "selectable_attr", "~> 0.3.15"
|
|
12
|
+
|
|
13
|
+
gem "bson" , "~> 1.5.2"
|
|
14
|
+
gem "bson_ext", "~> 1.5.2"
|
|
15
|
+
gem "mongo" , "~> 1.5.2"
|
|
16
|
+
|
|
17
|
+
gem "mongoid", "~> 2.3.3"
|
|
18
|
+
|
|
19
|
+
gem "tengine_support", "~> 0.3.12"
|
|
20
|
+
gem "tengine_event", "~> 0.4.0"
|
|
21
|
+
|
|
22
|
+
gem "daemons", "~> 1.1.4"
|
|
23
|
+
|
|
24
|
+
# Add dependencies to develop your gem here.
|
|
25
|
+
# Include everything needed to run rake, tests, features, etc.
|
|
26
|
+
group :development do
|
|
27
|
+
gem "rspec", "~> 2.6.0"
|
|
28
|
+
gem "factory_girl", "~> 2.1.2"
|
|
29
|
+
gem "yard", "~> 0.7.2"
|
|
30
|
+
gem "bundler", "~> 1.0.18"
|
|
31
|
+
gem "jeweler", "~> 1.6.4"
|
|
32
|
+
# gem "rcov", ">= 0"
|
|
33
|
+
gem "simplecov", "~> 0.5.3"
|
|
34
|
+
gem "ZenTest", "~> 4.6.2"
|
|
35
|
+
|
|
36
|
+
# for markdown
|
|
37
|
+
gem 'rdiscount'
|
|
38
|
+
gem 'kramdown'
|
|
39
|
+
|
|
40
|
+
end
|
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
GEM
|
|
2
|
+
remote: http://rubygems.org/
|
|
3
|
+
specs:
|
|
4
|
+
ZenTest (4.6.2)
|
|
5
|
+
activemodel (3.1.3)
|
|
6
|
+
activesupport (= 3.1.3)
|
|
7
|
+
builder (~> 3.0.0)
|
|
8
|
+
i18n (~> 0.6)
|
|
9
|
+
activesupport (3.1.3)
|
|
10
|
+
multi_json (~> 1.0)
|
|
11
|
+
amq-client (0.8.7)
|
|
12
|
+
amq-protocol (>= 0.8.4)
|
|
13
|
+
eventmachine
|
|
14
|
+
amq-protocol (0.8.4)
|
|
15
|
+
amqp (0.8.4)
|
|
16
|
+
amq-client (~> 0.8.7)
|
|
17
|
+
amq-protocol (~> 0.8.4)
|
|
18
|
+
eventmachine
|
|
19
|
+
bson (1.5.2)
|
|
20
|
+
bson_ext (1.5.2)
|
|
21
|
+
bson (= 1.5.2)
|
|
22
|
+
builder (3.0.0)
|
|
23
|
+
daemons (1.1.8)
|
|
24
|
+
diff-lcs (1.1.3)
|
|
25
|
+
eventmachine (0.12.10)
|
|
26
|
+
factory_girl (2.1.2)
|
|
27
|
+
activesupport
|
|
28
|
+
git (1.2.5)
|
|
29
|
+
i18n (0.6.0)
|
|
30
|
+
jeweler (1.6.4)
|
|
31
|
+
bundler (~> 1.0)
|
|
32
|
+
git (>= 1.2.5)
|
|
33
|
+
rake
|
|
34
|
+
kramdown (0.13.4)
|
|
35
|
+
macaddr (1.5.0)
|
|
36
|
+
systemu (>= 2.4.0)
|
|
37
|
+
mongo (1.5.2)
|
|
38
|
+
bson (= 1.5.2)
|
|
39
|
+
mongoid (2.3.4)
|
|
40
|
+
activemodel (~> 3.1)
|
|
41
|
+
mongo (~> 1.3)
|
|
42
|
+
tzinfo (~> 0.3.22)
|
|
43
|
+
multi_json (1.0.4)
|
|
44
|
+
rake (0.9.2.2)
|
|
45
|
+
rdiscount (1.6.8)
|
|
46
|
+
rspec (2.6.0)
|
|
47
|
+
rspec-core (~> 2.6.0)
|
|
48
|
+
rspec-expectations (~> 2.6.0)
|
|
49
|
+
rspec-mocks (~> 2.6.0)
|
|
50
|
+
rspec-core (2.6.4)
|
|
51
|
+
rspec-expectations (2.6.0)
|
|
52
|
+
diff-lcs (~> 1.1.2)
|
|
53
|
+
rspec-mocks (2.6.0)
|
|
54
|
+
selectable_attr (0.3.15)
|
|
55
|
+
i18n
|
|
56
|
+
simplecov (0.5.4)
|
|
57
|
+
multi_json (~> 1.0.3)
|
|
58
|
+
simplecov-html (~> 0.5.3)
|
|
59
|
+
simplecov-html (0.5.3)
|
|
60
|
+
systemu (2.4.2)
|
|
61
|
+
tengine_event (0.4.6)
|
|
62
|
+
activesupport (>= 3.0.0)
|
|
63
|
+
amqp (~> 0.8.0)
|
|
64
|
+
tengine_support (>= 0.3.24)
|
|
65
|
+
uuid (~> 2.3.4)
|
|
66
|
+
tengine_support (0.3.24)
|
|
67
|
+
activesupport (>= 3.0.0)
|
|
68
|
+
tzinfo (0.3.31)
|
|
69
|
+
uuid (2.3.5)
|
|
70
|
+
macaddr (~> 1.0)
|
|
71
|
+
yard (0.7.5)
|
|
72
|
+
|
|
73
|
+
PLATFORMS
|
|
74
|
+
ruby
|
|
75
|
+
|
|
76
|
+
DEPENDENCIES
|
|
77
|
+
ZenTest (~> 4.6.2)
|
|
78
|
+
activemodel (~> 3.1.0)
|
|
79
|
+
activesupport (~> 3.1.0)
|
|
80
|
+
bson (~> 1.5.2)
|
|
81
|
+
bson_ext (~> 1.5.2)
|
|
82
|
+
bundler (~> 1.0.18)
|
|
83
|
+
daemons (~> 1.1.4)
|
|
84
|
+
factory_girl (~> 2.1.2)
|
|
85
|
+
jeweler (~> 1.6.4)
|
|
86
|
+
kramdown
|
|
87
|
+
mongo (~> 1.5.2)
|
|
88
|
+
mongoid (~> 2.3.3)
|
|
89
|
+
rdiscount
|
|
90
|
+
rspec (~> 2.6.0)
|
|
91
|
+
selectable_attr (~> 0.3.15)
|
|
92
|
+
simplecov (~> 0.5.3)
|
|
93
|
+
tengine_event (~> 0.4.0)
|
|
94
|
+
tengine_support (~> 0.3.12)
|
|
95
|
+
yard (~> 0.7.2)
|
data/README.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# tengine_core
|
|
2
|
+
|
|
3
|
+
tengineはデータセンター運用のためのフレームワークおよび実行環境です。
|
|
4
|
+
|
|
5
|
+
## 概要
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
## 関連パッケージ
|
|
9
|
+
### tengine_resource
|
|
10
|
+
### tengine_schedule
|
|
11
|
+
### tengine_job
|
|
12
|
+
#### tengine_job_agent
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
## インストールとセットアップ
|
|
16
|
+
### インストール
|
|
17
|
+
|
|
18
|
+
* rabbitmqのインストール
|
|
19
|
+
* MongoDBのインストール
|
|
20
|
+
|
|
21
|
+
gem install tengine_core --source http://bts.tenginefw.com/gemserver
|
|
22
|
+
|
|
23
|
+
### セットアップ
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
## 使用方法
|
|
28
|
+
|
|
29
|
+
### DSL
|
|
30
|
+
|
|
31
|
+
#### API
|
|
32
|
+
|
|
33
|
+
DSLを使用するためのAPIについては以下のモジュールのAPIを参照してください。
|
|
34
|
+
[Tengine::Core::DslLoader](Tengine/Core/DslLoader.html)
|
|
35
|
+
[Tengine::Core::DslBinder](Tengine/Core/DslBinder.html)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
## Contributing to tengine_core
|
|
39
|
+
|
|
40
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
|
41
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
|
42
|
+
* Fork the project
|
|
43
|
+
* Start a feature/bugfix branch
|
|
44
|
+
* Commit and push until you are happy with your contribution
|
|
45
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
|
46
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
## License
|
|
50
|
+
tengine_event is distributed under the MPL2.0 or LGPLv3 or the dual license of MPL2.0/LGPLv3
|
|
51
|
+
|
|
52
|
+
## Copyright
|
|
53
|
+
|
|
54
|
+
Copyright (c) 2011 nautilus-technologies.com.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'rubygems'
|
|
4
|
+
require 'bundler'
|
|
5
|
+
begin
|
|
6
|
+
Bundler.setup(:default, :development)
|
|
7
|
+
rescue Bundler::BundlerError => e
|
|
8
|
+
$stderr.puts e.message
|
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
|
10
|
+
exit e.status_code
|
|
11
|
+
end
|
|
12
|
+
require 'rake'
|
|
13
|
+
|
|
14
|
+
require 'jeweler'
|
|
15
|
+
Jeweler::Tasks.new do |gem|
|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
|
17
|
+
gem.name = "tengine_core"
|
|
18
|
+
gem.homepage = "http://github.com/tengine/tengine_core"
|
|
19
|
+
gem.license = "MPL2.0/LGPLv3"
|
|
20
|
+
gem.summary = %Q{tengine_core is a framework/engine to support distributed processing}
|
|
21
|
+
gem.description = %Q{tengine_core is a framework/engine to support distributed processing}
|
|
22
|
+
gem.email = "tengine@nautilus-technologies.com"
|
|
23
|
+
gem.authors = %w[taigou totty g-morita shyouhei akm hiroshinakao]
|
|
24
|
+
gem.bindir = 'bin'
|
|
25
|
+
gem.executables = ['tengined', 'tengine_heartbeat_watchd', 'tengine_atd']
|
|
26
|
+
# dependencies defined in Gemfile
|
|
27
|
+
end
|
|
28
|
+
Jeweler::RubygemsDotOrgTasks.new
|
|
29
|
+
|
|
30
|
+
require 'rspec/core'
|
|
31
|
+
require 'rspec/core/rake_task'
|
|
32
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
|
33
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
|
37
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
|
38
|
+
spec.rcov = true
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
task :default => :spec
|
|
42
|
+
|
|
43
|
+
require 'yard'
|
|
44
|
+
YARD::Rake::YardocTask.new
|
data/VERSION
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0.5.28
|
data/bin/tengine_atd
ADDED
data/bin/tengined
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
require 'rubygems'
|
|
4
|
+
require 'optparse'
|
|
5
|
+
require 'daemons'
|
|
6
|
+
require 'fileutils'
|
|
7
|
+
|
|
8
|
+
$LOAD_PATH << File.expand_path('../lib', File.dirname(__FILE__))
|
|
9
|
+
require 'tengine_core'
|
|
10
|
+
|
|
11
|
+
@__config__ = Tengine::Core::Config::Core.parse(ARGV)
|
|
12
|
+
Signal.trap(:INT) {puts ":INT"; @__bootstrap__.stop_kernel}
|
|
13
|
+
|
|
14
|
+
# 必要なディレクトリの生成
|
|
15
|
+
FileUtils.mkdir_p(File.expand_path(@__config__[:process][:pid_dir]))
|
|
16
|
+
FileUtils.mkdir_p(File.expand_path(@__config__[:tengined][:status_dir]))
|
|
17
|
+
FileUtils.mkdir_p(File.expand_path(@__config__[:tengined][:activation_dir]))
|
|
18
|
+
|
|
19
|
+
@__verbose__ = @__config__[:verbose]
|
|
20
|
+
def verbose(msg, output = STDOUT)
|
|
21
|
+
if @__verbose__
|
|
22
|
+
if block_given?
|
|
23
|
+
output.puts("#{msg} begin")
|
|
24
|
+
begin
|
|
25
|
+
yield
|
|
26
|
+
output.puts("#{msg} end")
|
|
27
|
+
rescue Exception => e
|
|
28
|
+
STDERR.puts("Exception occurred in #{msg}\n[#{e.class.name}] #{e.message}\n " << e.backtrace.join("\n "))
|
|
29
|
+
end
|
|
30
|
+
else
|
|
31
|
+
output.puts(msg)
|
|
32
|
+
end
|
|
33
|
+
else
|
|
34
|
+
yield if block_given?
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
verbose "define stop_process" do
|
|
39
|
+
def stop_process(signal)
|
|
40
|
+
verbose("stop_process") do
|
|
41
|
+
pids = Dir.glob(File.expand_path(@__config__[:process][:pid_dir] + "/*")).map do |pid_path|
|
|
42
|
+
File.open(pid_path, "r"){|f| f.gets.chomp.to_i}
|
|
43
|
+
end
|
|
44
|
+
results = pids.map{|pid|
|
|
45
|
+
begin
|
|
46
|
+
Process.kill(signal, pid)
|
|
47
|
+
STDOUT.puts("Process stop successfully [#{pid}]")
|
|
48
|
+
rescue
|
|
49
|
+
# pid_dir には、古いpidファイルが残っていることを考慮して古いpidのkillシグナルの
|
|
50
|
+
# 失敗は無視して起動しているプロセスに対してkillします
|
|
51
|
+
verbose("warning: #$! [#{pid}]")
|
|
52
|
+
end
|
|
53
|
+
}
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
verbose "define show_status" do
|
|
59
|
+
def show_status
|
|
60
|
+
verbose("show_status") do
|
|
61
|
+
pid_to_status = {}
|
|
62
|
+
Dir.glob(File.expand_path(@__config__[:tengined][:status_dir] + "/*.status")).map do |status_filepath|
|
|
63
|
+
pid_to_status[File.basename(status_filepath).scan(/\d+/).first.to_i] = File.read(status_filepath).chomp
|
|
64
|
+
end
|
|
65
|
+
pid_lines = []
|
|
66
|
+
pid_lines = `ps -opid -p #{pid_to_status.keys.join(',')}`.split(/\n/) unless pid_to_status.empty?
|
|
67
|
+
living_pids = pid_lines.select{|line| line =~ /^\s*\d+\s*$/}.map(&:to_i)
|
|
68
|
+
pid_to_status.each do |pid, status|
|
|
69
|
+
puts "%6d %s" % [pid, living_pids.include?(pid) ? status : "terminated"]
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
verbose "define run_daemons" do
|
|
76
|
+
def run_daemons(options={}, &block)
|
|
77
|
+
verbose("run_daemons") do
|
|
78
|
+
daemonize_options = {
|
|
79
|
+
:ARGV => ['start'],
|
|
80
|
+
:ontop => !@__config__[:process][:daemon],
|
|
81
|
+
:dir_mode => :normal,
|
|
82
|
+
:dir => File.expand_path(@__config__[:process][:pid_dir]),
|
|
83
|
+
# :log_dir => File.expand_path("../#{@__config__[:tengined][:log_dir]}", File.dirname(__FILE__)),
|
|
84
|
+
# :log_output => false
|
|
85
|
+
}.update(options)
|
|
86
|
+
daemonize_options.update(:ARGV => ['start'])
|
|
87
|
+
current_dir = Dir.pwd
|
|
88
|
+
begin
|
|
89
|
+
if @__config__[:action].to_sym == :start
|
|
90
|
+
# pidファイルは、"tengined.0.pid"の数字の部分を連番でふります
|
|
91
|
+
pids = Dir.glob("#{daemonize_options[:dir]}/tengined.*.pid")
|
|
92
|
+
if pids.count == 0
|
|
93
|
+
max_pid_num = 0
|
|
94
|
+
else
|
|
95
|
+
max_pid_num = pids.map{|pid_path| File.basename(pid_path).scan(/\d+/).first.to_i}.max.succ
|
|
96
|
+
end
|
|
97
|
+
pid_file_name = "#{File.basename(@__daemon_proc_path__)}.#{max_pid_num}"
|
|
98
|
+
else
|
|
99
|
+
pid_file_name = "#{File.basename(@__daemon_proc_path__)}_#{@__config__[:action]}"
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
Daemons.run_proc(pid_file_name, daemonize_options) do
|
|
103
|
+
Dir.chdir(current_dir, &block)
|
|
104
|
+
end
|
|
105
|
+
rescue SystemExit => e
|
|
106
|
+
verbose("Daemons.run_proc exit successfully") if e.status == 0
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
verbose "define make_activations" do
|
|
113
|
+
def make_activations
|
|
114
|
+
verbose("make_activations") do
|
|
115
|
+
Dir.glob(File.expand_path(@__config__[:process][:pid_dir] + "/tengined.*.pid")).each do |pid_path|
|
|
116
|
+
pid = File.open(pid_path, "r"){|f| f.gets.chomp}
|
|
117
|
+
File.new(File.expand_path(@__config__[:tengined][:activation_dir] + "/tengined_#{pid}.activation"), "w").close
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
verbose "define run" do
|
|
124
|
+
def run(&block)
|
|
125
|
+
verbose("run") do
|
|
126
|
+
options = {}
|
|
127
|
+
case @__config__[:action].to_sym
|
|
128
|
+
when :stop then stop_process("HUP")
|
|
129
|
+
when :force_stop then stop_process("KILL")
|
|
130
|
+
when :status then show_status
|
|
131
|
+
when :load then
|
|
132
|
+
options = {:ontop => true}
|
|
133
|
+
run_daemons(options, &block)
|
|
134
|
+
when :test, :start, :enable then
|
|
135
|
+
run_daemons(options, &block)
|
|
136
|
+
when :activate then make_activations
|
|
137
|
+
else
|
|
138
|
+
verbose("Unknown action: #{@__config__[:action]}", STDERR)
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
rescue SystemExit
|
|
142
|
+
verbose("Exception occurred in run\n[#{$!.class.name}] #{$!.message}\n " << $!.backtrace.join("\n "), STDERR)
|
|
143
|
+
raise
|
|
144
|
+
rescue Exception
|
|
145
|
+
verbose("Exception occurred in run\n[#{$!.class.name}] #{$!.message}\n " << $!.backtrace.join("\n "), STDERR)
|
|
146
|
+
raise
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
@__daemon_proc_path__ = File.expand_path(__FILE__)
|
|
151
|
+
tengined_root = File.expand_path("..", File.expand_path(File.dirname(__FILE__)))
|
|
152
|
+
|
|
153
|
+
if @__verbose__
|
|
154
|
+
verbose "configurations:"
|
|
155
|
+
require 'pp'; pp @__config__.to_hash
|
|
156
|
+
verbose "tengined_root: #{tengined_root}"
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
run do
|
|
160
|
+
verbose "Dir.pwd: #{Dir.pwd}"
|
|
161
|
+
|
|
162
|
+
config = nil
|
|
163
|
+
begin
|
|
164
|
+
config = @__config__
|
|
165
|
+
config.setup_loggers
|
|
166
|
+
rescue Exception
|
|
167
|
+
puts "[#{$!.class.name}] #{$!.message}\n " << $!.backtrace.join("\n ")
|
|
168
|
+
raise
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
require 'mongoid'
|
|
172
|
+
require File.expand_path('./lib/tengine_core', tengined_root)
|
|
173
|
+
require 'tengine/core/mongoid_fix'
|
|
174
|
+
Mongoid.config.from_hash(config[:db])
|
|
175
|
+
Mongoid.config.option(:persist_in_safe_mode, :default => true)
|
|
176
|
+
Mongoid.config.option(:autocreate_indexes, :default => true) # http://mongoid.org/docs/indexing.html
|
|
177
|
+
require 'amqp'
|
|
178
|
+
Mongoid.logger = AMQP::Session.logger = Tengine.logger
|
|
179
|
+
Tengine::Core::MethodTraceable.disabled = !@__config__[:verbose] # Tengine::Core::Bootstrapが動く前に設定しないと余計なログが出ます
|
|
180
|
+
@__bootstrap__ = Tengine::Core::Bootstrap.new(config)
|
|
181
|
+
@__bootstrap__.boot
|
|
182
|
+
end
|