tengine_resource 0.5.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. data/.document +5 -0
  2. data/.rspec +1 -0
  3. data/Gemfile +30 -0
  4. data/Gemfile.lock +106 -0
  5. data/README.rdoc +20 -0
  6. data/Rakefile +42 -0
  7. data/VERSION +1 -0
  8. data/bin/tengine_resource_watchd +8 -0
  9. data/config/.gitignore +2 -0
  10. data/config/watchd.yml.erb.example +52 -0
  11. data/lib/tengine/resource.rb +29 -0
  12. data/lib/tengine/resource/config.rb +6 -0
  13. data/lib/tengine/resource/config/resource.rb +194 -0
  14. data/lib/tengine/resource/credential.rb +156 -0
  15. data/lib/tengine/resource/credential/ec2.rb +5 -0
  16. data/lib/tengine/resource/credential/ec2/dummy.rb +148 -0
  17. data/lib/tengine/resource/credential/ec2/launch_options.rb +179 -0
  18. data/lib/tengine/resource/drivers/resource_control_driver.rb +58 -0
  19. data/lib/tengine/resource/net_ssh.rb +134 -0
  20. data/lib/tengine/resource/observer.rb +25 -0
  21. data/lib/tengine/resource/physical_server.rb +7 -0
  22. data/lib/tengine/resource/provider.rb +82 -0
  23. data/lib/tengine/resource/provider/ec2.rb +187 -0
  24. data/lib/tengine/resource/provider/wakame.rb +615 -0
  25. data/lib/tengine/resource/server.rb +62 -0
  26. data/lib/tengine/resource/virtual_server.rb +62 -0
  27. data/lib/tengine/resource/virtual_server_image.rb +34 -0
  28. data/lib/tengine/resource/virtual_server_type.rb +21 -0
  29. data/lib/tengine/resource/watcher.rb +121 -0
  30. data/lib/tengine_resource.rb +4 -0
  31. data/spec/fixtures/goku_at_ec2_ap_northeast.rb +177 -0
  32. data/spec/mongoid.yml +35 -0
  33. data/spec/spec_helper.rb +40 -0
  34. data/spec/support/ec2.rb +129 -0
  35. data/spec/support/mongo_index_key_log.rb +91 -0
  36. data/spec/tengine/resource/bugfix/watcher_for_wakame_spec.rb +232 -0
  37. data/spec/tengine/resource/credential_spec.rb +205 -0
  38. data/spec/tengine/resource/drivers/resource_control_driver_spec.rb +84 -0
  39. data/spec/tengine/resource/net_ssh_spec.rb +148 -0
  40. data/spec/tengine/resource/physical_server_spec.rb +47 -0
  41. data/spec/tengine/resource/provider/ec2_spec.rb +473 -0
  42. data/spec/tengine/resource/provider/test_files/describe_host_nodes.json +22 -0
  43. data/spec/tengine/resource/provider/test_files/describe_images.json +23 -0
  44. data/spec/tengine/resource/provider/test_files/describe_instance_specs.json +23 -0
  45. data/spec/tengine/resource/provider/test_files/describe_instances.json +56 -0
  46. data/spec/tengine/resource/provider/test_files/run_instances.json +30 -0
  47. data/spec/tengine/resource/provider/test_files/terminate_instances.json +3 -0
  48. data/spec/tengine/resource/provider/wakame/00_describe_host_nodes_0_physical_servers.json +8 -0
  49. data/spec/tengine/resource/provider/wakame/01_describe_host_nodes_10_physical_servers.json +139 -0
  50. data/spec/tengine/resource/provider/wakame/02_describe_host_nodes_60_physical_servers.json +795 -0
  51. data/spec/tengine/resource/provider/wakame/10_describe_instances_0_virtual_servers.json +8 -0
  52. data/spec/tengine/resource/provider/wakame/11_describe_instances_10_virtual_servers.json +469 -0
  53. data/spec/tengine/resource/provider/wakame/12_describe_instances_after_run_instances.json +280 -0
  54. data/spec/tengine/resource/provider/wakame/13_describe_instances_after_terminate_instances.json +279 -0
  55. data/spec/tengine/resource/provider/wakame/20_describe_images_0_virtual_server_images.json +8 -0
  56. data/spec/tengine/resource/provider/wakame/21_describe_images_5_virtual_server_images.json +84 -0
  57. data/spec/tengine/resource/provider/wakame/22_describe_images_60_virtual_server_images.json +856 -0
  58. data/spec/tengine/resource/provider/wakame/30_describe_instance_specs_0_virtual_server_specs.json +8 -0
  59. data/spec/tengine/resource/provider/wakame/31_describe_instance_specs_4_virtual_server_specs.json +66 -0
  60. data/spec/tengine/resource/provider/wakame/40_run_instances_0_virtual_servers.json +1 -0
  61. data/spec/tengine/resource/provider/wakame/41_run_instances_1_virtual_servers.json +22 -0
  62. data/spec/tengine/resource/provider/wakame/42_run_instances_5_virtual_servers.json +106 -0
  63. data/spec/tengine/resource/provider/wakame/50_terminate_instances_0_virtual_servers.json +1 -0
  64. data/spec/tengine/resource/provider/wakame/51_terminate_instances_3_virtual_servers.json +5 -0
  65. data/spec/tengine/resource/provider/wakame/sync_physical_servers_spec.rb +114 -0
  66. data/spec/tengine/resource/provider/wakame/sync_virtual_server_images_spec.rb +116 -0
  67. data/spec/tengine/resource/provider/wakame/sync_virtual_server_types_spec.rb +116 -0
  68. data/spec/tengine/resource/provider/wakame/sync_virtual_servers_spec.rb +216 -0
  69. data/spec/tengine/resource/provider/wakame_api_spec.rb +319 -0
  70. data/spec/tengine/resource/provider/wakame_spec.rb +339 -0
  71. data/spec/tengine/resource/provider_spec.rb +252 -0
  72. data/spec/tengine/resource/server_spec.rb +195 -0
  73. data/spec/tengine/resource/test_files/.gitignore +6 -0
  74. data/spec/tengine/resource/test_files/00_describe_host_nodes_0_physical_servers.json +8 -0
  75. data/spec/tengine/resource/test_files/01_describe_host_nodes_10_physical_servers.json +139 -0
  76. data/spec/tengine/resource/test_files/02_describe_host_nodes_60_physical_servers.json +795 -0
  77. data/spec/tengine/resource/test_files/10_describe_instances_0_virtual_servers.json +8 -0
  78. data/spec/tengine/resource/test_files/11_describe_instances_10_virtual_servers.json +469 -0
  79. data/spec/tengine/resource/test_files/12_describe_instances_after_run_instances.json +280 -0
  80. data/spec/tengine/resource/test_files/13_describe_instances_after_terminate_instances.json +279 -0
  81. data/spec/tengine/resource/test_files/14_describe_instances_after_run_1_instance.json +55 -0
  82. data/spec/tengine/resource/test_files/20_describe_images_0_virtual_server_images.json +8 -0
  83. data/spec/tengine/resource/test_files/21_describe_images_5_virtual_server_images.json +84 -0
  84. data/spec/tengine/resource/test_files/22_describe_images_60_virtual_server_images.json +856 -0
  85. data/spec/tengine/resource/test_files/30_describe_instance_specs_0_virtual_server_specs.json +8 -0
  86. data/spec/tengine/resource/test_files/31_describe_instance_specs_4_virtual_server_specs.json +66 -0
  87. data/spec/tengine/resource/test_files/40_run_instances_0_virtual_servers.json +1 -0
  88. data/spec/tengine/resource/test_files/41_run_instances_1_virtual_servers.json +22 -0
  89. data/spec/tengine/resource/test_files/42_run_instances_5_virtual_servers.json +106 -0
  90. data/spec/tengine/resource/test_files/43_run_instances_1_virtual_servers_without_aws_availability_zone.json +22 -0
  91. data/spec/tengine/resource/test_files/50_terminate_instances_0_virtual_servers.json +1 -0
  92. data/spec/tengine/resource/test_files/51_terminate_instances_3_virtual_servers.json +5 -0
  93. data/spec/tengine/resource/virtual_server_image_spec.rb +94 -0
  94. data/spec/tengine/resource/virtual_server_spec.rb +116 -0
  95. data/spec/tengine/resource/virtual_server_type_spec.rb +4 -0
  96. data/spec/tengine/resource/watcher_spec.rb +1026 -0
  97. data/spec/tengine_resource_spec.rb +5 -0
  98. data/tengine_resource.gemspec +171 -0
  99. data/tmp/log/.gitignore +1 -0
  100. metadata +286 -0
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,30 @@
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 "tengine_support", "~> 0.3.24"
9
+ gem "tengine_core", "~> 0.5.23"
10
+
11
+ gem "wakame-adapters-tengine", "~> 0.0.0"
12
+
13
+ # http://rightaws.rubyforge.org/
14
+ # http://github.com/rightscale/right_aws
15
+ gem "right_aws", "~> 2.1.0"
16
+
17
+ gem "net-ssh", "~> 2.2.1"
18
+
19
+ # Add dependencies to develop your gem here.
20
+ # Include everything needed to run rake, tests, features, etc.
21
+ group :development do
22
+ gem "rspec", "~> 2.6.0"
23
+ gem "factory_girl", "~> 2.1.2"
24
+ gem "yard", "~> 0.7.2"
25
+ gem "bundler", "~> 1.0.18"
26
+ gem "jeweler", "~> 1.6.4"
27
+ # gem "rcov", ">= 0"
28
+ gem "simplecov", "~> 0.5.3"
29
+ gem "ZenTest", "~> 4.6.2"
30
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,106 @@
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
+ json (1.6.5)
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
+ net-ssh (2.2.2)
45
+ rake (0.9.2.2)
46
+ right_aws (2.1.0)
47
+ right_http_connection (>= 1.2.5)
48
+ right_http_connection (1.3.0)
49
+ rspec (2.6.0)
50
+ rspec-core (~> 2.6.0)
51
+ rspec-expectations (~> 2.6.0)
52
+ rspec-mocks (~> 2.6.0)
53
+ rspec-core (2.6.4)
54
+ rspec-expectations (2.6.0)
55
+ diff-lcs (~> 1.1.2)
56
+ rspec-mocks (2.6.0)
57
+ selectable_attr (0.3.15)
58
+ i18n
59
+ simplecov (0.5.4)
60
+ multi_json (~> 1.0.3)
61
+ simplecov-html (~> 0.5.3)
62
+ simplecov-html (0.5.3)
63
+ systemu (2.4.2)
64
+ tengine_core (0.5.28)
65
+ activemodel (~> 3.1.0)
66
+ activesupport (~> 3.1.0)
67
+ bson (~> 1.5.2)
68
+ bson_ext (~> 1.5.2)
69
+ daemons (~> 1.1.4)
70
+ mongo (~> 1.5.2)
71
+ mongoid (~> 2.3.3)
72
+ selectable_attr (~> 0.3.15)
73
+ tengine_event (~> 0.4.0)
74
+ tengine_support (~> 0.3.12)
75
+ tengine_event (0.4.6)
76
+ activesupport (>= 3.0.0)
77
+ amqp (~> 0.8.0)
78
+ tengine_support (>= 0.3.24)
79
+ uuid (~> 2.3.4)
80
+ tengine_support (0.3.24)
81
+ activesupport (>= 3.0.0)
82
+ tzinfo (0.3.31)
83
+ uuid (2.3.5)
84
+ macaddr (~> 1.0)
85
+ wakame-adapters-tengine (0.0.6)
86
+ json
87
+ right_aws (~> 2.1.0)
88
+ rspec
89
+ yard (0.7.5)
90
+
91
+ PLATFORMS
92
+ ruby
93
+
94
+ DEPENDENCIES
95
+ ZenTest (~> 4.6.2)
96
+ bundler (~> 1.0.18)
97
+ factory_girl (~> 2.1.2)
98
+ jeweler (~> 1.6.4)
99
+ net-ssh (~> 2.2.1)
100
+ right_aws (~> 2.1.0)
101
+ rspec (~> 2.6.0)
102
+ simplecov (~> 0.5.3)
103
+ tengine_core (~> 0.5.23)
104
+ tengine_support (~> 0.3.24)
105
+ wakame-adapters-tengine (~> 0.0.0)
106
+ yard (~> 0.7.2)
data/README.rdoc ADDED
@@ -0,0 +1,20 @@
1
+ = tengine_resource
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to tengine_resource
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * 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.
14
+
15
+ == License
16
+ tengine_event is distributed under the MPL2.0 or LGPLv3 or the dual license of MPL2.0/LGPLv3
17
+
18
+ == Copyright
19
+
20
+ Copyright (c) 2011 nautilus-technologies.com
data/Rakefile ADDED
@@ -0,0 +1,42 @@
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_resource"
18
+ gem.homepage = "http://github.com/tengine/tengine_resource"
19
+ gem.license = "MPL2.0/LGPLv3"
20
+ gem.summary = %Q{tengine_resource provides physical/virtual server management}
21
+ gem.description = %Q{tengine_resource provides physical/virtual server management}
22
+ gem.email = "tengine@nautilus-technologies.com"
23
+ gem.authors = %w[taigou totty g-morita shyouhei akm hiroshinakao]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :default => :spec
40
+
41
+ require 'yard'
42
+ YARD::Rake::YardocTask.new
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.5.13
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+ $LOAD_PATH << File.expand_path("../lib", File.dirname(__FILE__))
4
+ require "tengine_resource"
5
+
6
+ @__watcher__ = Tengine::Resource::Watcher.new(ARGV)
7
+ @__watcher__.run(__FILE__)
8
+ Signal.trap(:INT) { @__watcher__.shutdown }
data/config/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ /watchd.yml
2
+ /watchd.yml.erb
@@ -0,0 +1,52 @@
1
+ process:
2
+ daemon: false
3
+ pid_dir: "./tmp/watchd_pids"
4
+
5
+ db:
6
+ host: localhost
7
+ port: 27017
8
+ username:
9
+ password:
10
+ database: tengine_production
11
+
12
+ event_queue:
13
+ connection:
14
+ host: localhost
15
+ port: 5672
16
+ vhost: '/'
17
+ user: 'guest'
18
+ pass: 'guest'
19
+ logging: false
20
+ insist: false
21
+ auto_reconnect_delay: 1
22
+ exchange:
23
+ name: 'tengine_event_exchange'
24
+ type: 'direct'
25
+ durable: true
26
+ queue:
27
+ name: 'tengine_event_queue'
28
+ durable: true
29
+
30
+ log_common:
31
+ output:
32
+ rotation: 3
33
+ rotation_size: 1024 * 1024
34
+ level: 'debug'
35
+
36
+ application_log:
37
+ output:
38
+ rotation:
39
+ rotation_size:
40
+ level:
41
+
42
+ process_stdout_log:
43
+ output: STDOUT
44
+ rotation:
45
+ rotation_size:
46
+ level:
47
+
48
+ process_stderr_log:
49
+ output: STDERR
50
+ rotation:
51
+ rotation_size:
52
+ level:
@@ -0,0 +1,29 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'tengine_resource'
3
+
4
+ module Tengine::Resource
5
+ # モデル
6
+ autoload :Server , 'tengine/resource/server'
7
+ autoload :PhysicalServer , 'tengine/resource/physical_server'
8
+ autoload :VirtualServer , 'tengine/resource/virtual_server'
9
+ autoload :VirtualServerImage, 'tengine/resource/virtual_server_image'
10
+ autoload :VirtualServerType , 'tengine/resource/virtual_server_type'
11
+ autoload :Credential , 'tengine/resource/credential'
12
+ autoload :Provider , 'tengine/resource/provider'
13
+
14
+ # モデルの更新を受けてイベントを発火するオブザーバ
15
+ autoload :Observer , 'tengine/resource/observer'
16
+
17
+ autoload :Watcher , 'tengine/resource/watcher'
18
+ autoload :Config , 'tengine/resource/config'
19
+
20
+ def self.notify ctx, msg
21
+ # called from tengine_core/lib/tengine/core/plugins.rb
22
+ case msg when :after___evalate__
23
+ Dir.glob(File.expand_path("../resource/drivers/*.rb", __FILE__)) do |f|
24
+ ctx.instance_eval File.read(f), f # load additional drivers
25
+ end
26
+ end
27
+ end
28
+
29
+ end
@@ -0,0 +1,6 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'tengine/resource'
3
+
4
+ module Tengine::Resource::Config
5
+ autoload :Resource, 'tengine/resource/config/resource'
6
+ end
@@ -0,0 +1,194 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'tengine/core/config'
3
+ require 'tengine/resource/config'
4
+
5
+ require 'yaml'
6
+ require 'optparse'
7
+ require 'active_support/memoizable'
8
+
9
+ require 'tengine/support/yaml_with_erb'
10
+
11
+ class Tengine::Resource::Config::Resource < Tengine::Support::Config::Definition::Suite
12
+ # memoize については http://wota.jp/ac/?date=20081025#p11 などを参照してください
13
+ extend ActiveSupport::Memoizable
14
+
15
+ class << self
16
+ def default_hash
17
+ new.to_hash
18
+ end
19
+ alias_method :skelton_hash, :default_hash
20
+
21
+ def parse_to_hash(args)
22
+ config = new
23
+ config.parse!(args)
24
+ result = new
25
+ result.config = config.config
26
+ result.to_hash
27
+ end
28
+
29
+ def parse(args)
30
+ config = new
31
+ config.parse!(args)
32
+ config
33
+ end
34
+
35
+ end
36
+
37
+ def initialize(hash_or_filepath = nil)
38
+ build if respond_to?(:build)
39
+ case hash_or_filepath
40
+ when Hash then
41
+ if config = hash_or_filepath[:config]
42
+ load_file(config)
43
+ else
44
+ load(hash_or_filepath)
45
+ end
46
+ when String then load_file(hash_or_filepath)
47
+ end
48
+ end
49
+
50
+ def load_file(filepath)
51
+ super
52
+ rescue Exception => e
53
+ raise Tengine::Core::ConfigError, "[#{e.class.name}] #{e.message} when loading configuration file: #{filepath}."
54
+ end
55
+
56
+
57
+ def build
58
+ banner <<EOS
59
+ Usage: tengine_resource_watchd [-k action] [-f path_to_config]
60
+ [-o mq_conn_host] [-p mq_conn_port] [-u mq_conn_user]
61
+ [-s mq_conn_pass] [-e mq_exchange_name] [-q mq_queue_name]
62
+ EOS
63
+
64
+ field(:action, "start|stop|force-stop|status", :type => :string, :default => "start")
65
+ load_config(:config, "path/to/config_file", :type => :string)
66
+
67
+ add(:process, Tengine::Resource::Config::Resource::Process)
68
+ add(:watchd, Tengine::Resource::Config::Resource::Watchd)
69
+ field(:db, "settings to connect to db", :type => :hash, :default => {
70
+ 'host' => 'localhost',
71
+ 'port' => 27017,
72
+ 'username' => nil,
73
+ 'password' => nil,
74
+ 'database' => 'tengine_production',
75
+ })
76
+
77
+ group(:event_queue) do
78
+ add(:connection, Tengine::Core::Config::Core::AmqpConnection)
79
+ add(:exchange , Tengine::Support::Config::Amqp::Exchange, :defaults => {:name => 'tengine_event_exchange'})
80
+ add(:queue , Tengine::Support::Config::Amqp::Queue , :defaults => {:name => 'tengine_event_queue'})
81
+ end
82
+
83
+ add(:log_common, Tengine::Support::Config::Logger,
84
+ :defaults => {
85
+ :rotation => 3 ,
86
+ :rotation_size => 1024 * 1024,
87
+ :level => 'info' ,
88
+ })
89
+ add(:application_log, Tengine::Resource::Config::Resource::LoggerConfig,
90
+ :parameters => {:logger_name => "application"},
91
+ :dependencies => { :process_config => :process, :log_common => :log_common,}){
92
+ self.formatter = lambda{|level, t, prog, msg| "#{t.iso8601} #{level} #{@process_identifier} #{msg}\n"}
93
+ }
94
+ add(:process_stdout_log, Tengine::Resource::Config::Resource::LoggerConfig,
95
+ :parameters => {:logger_name => "#{File.basename($PROGRAM_NAME)}_#{::Process.pid}_stdout"},
96
+ :dependencies => { :process_config => :process, :log_common => :log_common,}){
97
+ self.formatter = lambda{|level, t, prog, msg| "#{t.iso8601} STDOUT #{@process_identifier} #{msg}\n"}
98
+ }
99
+ add(:process_stderr_log, Tengine::Resource::Config::Resource::LoggerConfig,
100
+ :parameters => {:logger_name => "#{File.basename($PROGRAM_NAME)}_#{::Process.pid}_stderr"},
101
+ :dependencies => { :process_config => :process, :log_common => :log_common,},
102
+ :defaults => {
103
+ :output => proc{ process_config.daemon ? "./log/#{logger_name}.log" : "STDERR" }}){
104
+ self.formatter = lambda{|level, t, prog, msg| "#{t.iso8601} STDERR #{@process_identifier} #{msg}\n"}
105
+ }
106
+
107
+ group(:heartbeat, :hidden => true) do
108
+ add(:resourcew, Tengine::Core::Config::Core::Heartbeat)
109
+ end
110
+
111
+ separator("\nGeneral:")
112
+ field(:verbose, "Show detail to this command", :type => :boolean)
113
+ __action__(:version, "show version"){ STDOUT.puts Tengine::Resource.version.to_s; exit }
114
+ __action__(:dump_skelton, "dump skelton of config"){ STDOUT.puts YAML.dump(root.to_hash); exit }
115
+ __action__(:help , "show this help message"){ STDOUT.puts option_parser.help; exit }
116
+
117
+ mapping({
118
+ [:action] => :k,
119
+ [:config] => :f,
120
+ [:process, :daemon] => :D,
121
+
122
+ [:event_queue, :connection, :host] => :o,
123
+ [:event_queue, :connection, :port] => :p,
124
+ [:event_queue, :connection, :user] => :u,
125
+ [:event_queue, :connection, :pass] => :s,
126
+ [:event_queue, :exchange , :name] => :e,
127
+ [:event_queue, :queue , :name] => :q,
128
+
129
+ [:verbose] => :V,
130
+ [:version] => :v,
131
+ [:help] => :h
132
+ })
133
+ end
134
+
135
+ class Process
136
+ include Tengine::Support::Config::Definition
137
+
138
+ field :daemon, "process works on background.", :type => :boolean, :default => false
139
+ field :pid_dir, "path/to/dir for PID created.", :type => :directory, :default => "./tmp/watchd_pids"
140
+ end
141
+
142
+ class Watchd
143
+ include Tengine::Support::Config::Definition
144
+
145
+ # field :heartbeat_period , "the second of period which heartbeat event be fired. disable heartbeat if 0.", :type => :integer, :default => 0
146
+ end
147
+
148
+ # class AmqpConnection < Tengine::Support::Config::Amqp::Connection
149
+ # field :vhost, :default => '/'
150
+ # field :user , :default => 'guest'
151
+ # field :pass , :default => 'guest'
152
+ # field :logging, :type => :boolean, :default => false
153
+ # field :insist, :type => :boolean, :default => false
154
+ # field :auto_reconnect_delay, :type => :integer, :default => 1
155
+ # end
156
+
157
+ class LoggerConfig < Tengine::Support::Config::Logger
158
+ parameter :logger_name
159
+ depends :process_config
160
+ depends :log_common
161
+ field :output,
162
+ :default => proc{
163
+ process_config.daemon ?
164
+ "./log/#{logger_name}.log" : "STDOUT" },
165
+ :default_description => proc{"if daemon process then \"./log/#{logger_name}.log\" else \"STDOUT\""}
166
+ field :rotation,
167
+ :default => proc{ log_common.rotation },
168
+ :default_description => proc{"value of #{log_common.long_opt}-rotation"}
169
+ field :rotation_size,
170
+ :default => proc{ log_common.rotation_size },
171
+ :default_description => proc{"value of #{log_common.long_opt}-rotation-size"}
172
+ field :level,
173
+ :default => proc{ log_common.level },
174
+ :default_description => proc{"value of #{log_common.long_opt}-level"}
175
+ end
176
+
177
+ class Heartbeat
178
+ include Tengine::Support::Config::Definition
179
+ field :interval, "heartbeat interval seconds", :type => :integer, :default => 30
180
+ field :expire , "heartbeat expire seconds" , :type => :integer, :default => 120
181
+ end
182
+
183
+ def setup_loggers
184
+ Tengine.logger = application_log.new_logger
185
+ Tengine::Core.stdout_logger = process_stdout_log.new_logger
186
+ Tengine::Core.stderr_logger = process_stderr_log.new_logger
187
+
188
+ Tengine::Core.stdout_logger.info("#{self.class.name}#setup_loggers complete")
189
+ rescue Exception
190
+ Tengine::Core.stderr_logger.info("#{self.class.name}#setup_loggers failure")
191
+ raise
192
+ end
193
+
194
+ end