wakame 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. data/History.txt +18 -0
  2. data/README.rdoc +2 -4
  3. data/Rakefile +4 -1
  4. data/VERSION +1 -1
  5. data/app_generators/wakame/templates/config/cluster.rb +36 -0
  6. data/app_generators/wakame/wakame_generator.rb +1 -0
  7. data/lib/wakame/action.rb +19 -34
  8. data/lib/wakame/actions/launch_cluster.rb +6 -3
  9. data/lib/wakame/actions/launch_vm.rb +57 -0
  10. data/lib/wakame/actions/migrate_service.rb +6 -25
  11. data/lib/wakame/actions/propagate_instances.rb +16 -41
  12. data/lib/wakame/actions/reload_service.rb +2 -2
  13. data/lib/wakame/actions/shutdown_cluster.rb +4 -0
  14. data/lib/wakame/actions/start_service.rb +30 -9
  15. data/lib/wakame/actions/stop_service.rb +1 -4
  16. data/lib/wakame/actions/util.rb +0 -24
  17. data/lib/wakame/actor/mysql.rb +106 -0
  18. data/lib/wakame/actor/service_monitor.rb +10 -0
  19. data/lib/wakame/actor/system.rb +19 -9
  20. data/lib/wakame/actor.rb +1 -1
  21. data/lib/wakame/agent.rb +23 -17
  22. data/lib/wakame/command/action_status.rb +7 -38
  23. data/lib/wakame/command/agent_status.rb +18 -0
  24. data/lib/wakame/command/launch_cluster.rb +0 -4
  25. data/lib/wakame/command/launch_vm.rb +11 -0
  26. data/lib/wakame/command/migrate_service.rb +12 -9
  27. data/lib/wakame/command/propagate_service.rb +15 -7
  28. data/lib/wakame/command/reload_service.rb +21 -0
  29. data/lib/wakame/command/shutdown_cluster.rb +0 -5
  30. data/lib/wakame/command/shutdown_vm.rb +20 -0
  31. data/lib/wakame/command/status.rb +6 -66
  32. data/lib/wakame/command/stop_service.rb +31 -0
  33. data/lib/wakame/command.rb +3 -0
  34. data/lib/wakame/command_queue.rb +76 -5
  35. data/lib/wakame/configuration.rb +6 -1
  36. data/lib/wakame/event.rb +6 -5
  37. data/lib/wakame/event_dispatcher.rb +5 -3
  38. data/lib/wakame/initializer.rb +1 -1
  39. data/lib/wakame/master.rb +14 -10
  40. data/lib/wakame/monitor/agent.rb +1 -6
  41. data/lib/wakame/monitor/service.rb +13 -1
  42. data/lib/wakame/packets.rb +51 -13
  43. data/lib/wakame/rule_engine.rb +7 -18
  44. data/lib/wakame/runner/administrator_command.rb +517 -46
  45. data/lib/wakame/service.rb +104 -173
  46. data/lib/wakame/trigger.rb +1 -10
  47. data/lib/wakame/triggers/process_command.rb +9 -2
  48. data/lib/wakame/util.rb +21 -21
  49. data/lib/wakame/vm_manipulator.rb +1 -0
  50. data/tests/test_service.rb +30 -6
  51. data/wakame_generators/resource/templates/ec2_elb/ec2_elb.rb +80 -0
  52. data/wakame_generators/resource/templates/mysql_master/conf/my.cnf +3 -1
  53. data/wakame_generators/resource/templates/mysql_master/init.d/mysql +3 -3
  54. data/wakame_generators/resource/templates/mysql_master/mysql_master.rb +11 -12
  55. data/{app_generators/wakame/templates/cluster/resources/mysql_master → wakame_generators/resource/templates/mysql_slave}/conf/my.cnf +19 -9
  56. data/{app_generators/wakame/templates/cluster/resources/mysql_master/init.d/mysql → wakame_generators/resource/templates/mysql_slave/init.d/mysql-slave} +4 -4
  57. data/wakame_generators/resource/templates/mysql_slave/mysql_slave.rb +123 -0
  58. data/wakame_generators/resource/templates/nginx/conf/nginx.conf +166 -0
  59. data/wakame_generators/resource/templates/nginx/init.d/nginx +70 -0
  60. data/{app_generators/wakame/templates/cluster/resources/apache_lb/apache_lb.rb → wakame_generators/resource/templates/nginx/nginx.rb} +28 -17
  61. metadata +46 -27
  62. data/app_generators/wakame/templates/cluster/resources/apache_app/apache_app.rb +0 -54
  63. data/app_generators/wakame/templates/cluster/resources/apache_app/conf/apache2.conf +0 -46
  64. data/app_generators/wakame/templates/cluster/resources/apache_app/conf/envvars-app +0 -7
  65. data/app_generators/wakame/templates/cluster/resources/apache_app/conf/sites-app.conf +0 -23
  66. data/app_generators/wakame/templates/cluster/resources/apache_app/conf/system-app.conf +0 -67
  67. data/app_generators/wakame/templates/cluster/resources/apache_app/init.d/apache2-app +0 -192
  68. data/app_generators/wakame/templates/cluster/resources/apache_lb/conf/apache2.conf +0 -46
  69. data/app_generators/wakame/templates/cluster/resources/apache_lb/conf/envvars-lb +0 -6
  70. data/app_generators/wakame/templates/cluster/resources/apache_lb/conf/sites-lb.conf +0 -54
  71. data/app_generators/wakame/templates/cluster/resources/apache_lb/conf/system-lb.conf +0 -75
  72. data/app_generators/wakame/templates/cluster/resources/apache_lb/init.d/apache2-lb +0 -192
  73. data/app_generators/wakame/templates/cluster/resources/apache_www/apache_www.rb +0 -50
  74. data/app_generators/wakame/templates/cluster/resources/apache_www/conf/apache2.conf +0 -47
  75. data/app_generators/wakame/templates/cluster/resources/apache_www/conf/envvars-www +0 -7
  76. data/app_generators/wakame/templates/cluster/resources/apache_www/conf/sites-www.conf +0 -23
  77. data/app_generators/wakame/templates/cluster/resources/apache_www/conf/system-www.conf +0 -63
  78. data/app_generators/wakame/templates/cluster/resources/apache_www/init.d/apache2-www +0 -192
  79. data/app_generators/wakame/templates/cluster/resources/ec2_elastic_ip/ec2_elastic_ip.rb +0 -39
  80. data/app_generators/wakame/templates/cluster/resources/mysql_master/mysql_master.rb +0 -174
  81. data/tests/conf/a +0 -1
  82. data/tests/conf/b +0 -1
  83. data/tests/conf/c +0 -1
@@ -1,174 +0,0 @@
1
-
2
- class MySQL_Master < Wakame::Service::Resource
3
-
4
- def_attribute :duplicable, false
5
- def_attribute :mysqld_basedir, '/home/wakame/mysql'
6
- def_attribute :mysqld_server_id, 1
7
- def_attribute :mysqld_port, 3306
8
-
9
- def_attribute :ebs_volume, ''
10
- def_attribute :ebs_device, '/dev/sdm'
11
- def_attribute :ebs_mount_option, 'noatime'
12
-
13
- def basedir
14
- File.join(Wakame.config.root_path, 'cluster', 'resources', 'mysql_master')
15
- end
16
-
17
- def mysqld_datadir
18
- File.expand_path('data', mysqld_basedir)
19
- end
20
-
21
- def mysqld_log_bin
22
- File.expand_path('mysql-bin.log', mysqld_datadir)
23
- end
24
-
25
- def render_config(template)
26
- template.cp(%w(init.d/mysql))
27
- template.render(%w(conf/my.cnf))
28
- template.chmod("init.d/mysql", 0755)
29
- end
30
-
31
-
32
- def start(svc, action)
33
- vm_manipulator = Wakame::VmManipulator.create
34
-
35
- # $ echo "GRANT REPLICATION SLAVE, REPLICATION CLIENT, RELOAD ON *.* TO 'wakame-repl'@'%' IDENTIFIED BY 'wakame-slave';" | /usr/bin/mysql -h#{mysql_master_ip} -uroot
36
-
37
- require 'right_aws'
38
- ec2 = RightAws::Ec2.new(Wakame.config.aws_access_key, Wakame.config.aws_secret_key)
39
-
40
- res = ec2.describe_volumes([@ebs_volume])[0]
41
- ec2_instance_id = res[:aws_instance_id]
42
- if res[:aws_status] == 'in-use' && ec2_instance_id == svc.agent.attr[:instance_id]
43
- # Nothin to be done
44
- elsif res[:aws_status] == 'in-use' && ec2_instance_id != svc.agent.attr[:instance_id]
45
- ec2.detach_volume(@ebs_volume)
46
- cond = ConditionalWait.new { |c|
47
- c.poll {
48
- res1 = ec2.describe_volumes([@ebs_volume])[0]
49
- res1[:aws_status] == 'available'
50
- }
51
- }
52
- cond.wait
53
-
54
- ec2.attach_volume(@ebs_volume, svc.agent.attr[:instance_id], @ebs_device)
55
- cond = ConditionalWait.new { |c|
56
- c.poll {
57
- res1 = ec2.describe_volumes([@ebs_volume])[0]
58
- res1[:aws_status] == 'in-use'
59
- }
60
- }
61
- cond.wait
62
-
63
- elsif res[:aws_status] == 'available'
64
- ec2.attach_volume(@ebs_volume, svc.agent.attr[:instance_id], @ebs_device)
65
- cond = ConditionalWait.new { |c|
66
- c.poll {
67
- res1 = ec2.describe_volumes([@ebs_volume])[0]
68
- res1[:aws_status] == 'in-use'
69
- }
70
- }
71
- cond.wait
72
-
73
- end
74
- # in-use:
75
- # res = vm_manipulator.describe_volume(@ebs_volume)
76
- # Wakame.log.debug("describe_volume(#{@ebs_volume}): #{res.inspect}")
77
- # ec2_instance_id=nil
78
- # if res['attachmentSet']
79
- # ec2_instance_id = res['attachmentSet']['item'][0]['instanceId']
80
- # end
81
-
82
- # if res['status'] == 'in-use' && ec2_instance_id == svc.agent.agent_id
83
- # # Nothin to be done
84
- # elsif res['status'] == 'in-use' && ec2_instance_id != svc.agent.agent_id
85
- # vm_manipulator.detach_volume(@ebs_volume)
86
- # sleep 1.0
87
- # res = vm_manipulator.attach_volume(svc.agent.agent_id, @ebs_volume, @ebs_device)
88
- # Wakame.log.debug(res.inspect)
89
- # # sync
90
- # 3.times do |i|
91
- # system("/bin/sync")
92
- # sleep 1.0
93
- # end
94
- # elsif res['status'] == 'available'
95
- # res = vm_manipulator.attach_volume(svc.agent.agent_id, @ebs_volume, @ebs_device)
96
- # Wakame.log.debug(res.inspect)
97
- # # sync
98
- # 3.times do |i|
99
- # system("/bin/sync")
100
- # sleep 1.0
101
- # end
102
- # else
103
- # raise "The EBS volume is not ready to attach: #{@ebs_volume}"
104
- # end
105
-
106
- cond = ConditionalWait.new { |cond|
107
- cond.wait_event(Wakame::Event::ServiceOnline) { |event|
108
- event.instance_id == svc.instance_id
109
- }
110
- }
111
-
112
- action.actor_request(svc.agent.agent_id,
113
- '/service_monitor/register',
114
- svc.instance_id,
115
- :command, "/usr/bin/mysqladmin --defaults-file=#{svc.agent.root_path}/tmp/config/mysql_master/conf/my.cnf ping > /dev/null") { |req|
116
- }
117
-
118
- action.actor_request(svc.agent.agent_id, '/system/mount', @ebs_device, @mysqld_datadir, @ebs_mount_option) { |req|
119
- req.wait
120
- Wakame.log.debug("MySQL volume was mounted: #{@mysqld_datadir}")
121
- }
122
-
123
- action.actor_request(svc.agent.agent_id, '/daemon/start', 'mysql_master', 'init.d/mysql') { |req|
124
- req.wait
125
- Wakame.log.debug("MySQL process started")
126
- }
127
-
128
- #request.wait
129
- cond.wait
130
-
131
-
132
- # mount_point_dev=`df "#{@mysqld_datadir}" | awk 'NR==2 {print $1}'`
133
- # if mount_point_dev != @ebs_device
134
- # Wakame.log.debug("Mounting EBS volume: #{@ebs_device} as #{@mysqld_datadir} (with option: #{@ebs_mount_option})")
135
- # system("/bin/mount -o #{@ebs_mount_option} #{@ebs_device} #{@mysqld_datadir}")
136
- # # sync
137
- # 3.times do |i|
138
- # system("/bin/sync")
139
- # sleep 1.0
140
- # end
141
- # end
142
- # system(Wakame.config.root + "/config/init.d/mysql start")
143
- end
144
-
145
- #def check
146
- # system("/usr/bin/mysqladmin --defaults-file=/home/wakame/config/mysql/my.cnf ping > /dev/null")
147
- # return false if $? != 0
148
- # true
149
- #end
150
-
151
- def stop(svc, action)
152
- cond = ConditionalWait.new { |cond|
153
- cond.wait_event(Wakame::Event::ServiceOffline) { |event|
154
- event.instance_id == svc.instance_id
155
- }
156
- }
157
-
158
- action.actor_request(svc.agent.agent_id, '/daemon/stop', 'mysql_master', 'init.d/mysql') { |req| req.wait }
159
- action.actor_request(svc.agent.agent_id, '/system/umount', @mysqld_datadir) { |req|
160
- req.wait
161
- Wakame.log.debug("MySQL volume unmounted")
162
- }
163
-
164
- #request.wait
165
- cond.wait
166
-
167
- action.actor_request(svc.agent.agent_id,
168
- '/service_monitor/unregister',
169
- svc.instance_id).request
170
-
171
-
172
- #system(Wakame.config.root + "/config/init.d/mysql stop")
173
- end
174
- end
data/tests/conf/a DELETED
@@ -1 +0,0 @@
1
- aaaaaa
data/tests/conf/b DELETED
@@ -1 +0,0 @@
1
- bbbbbbb
data/tests/conf/c DELETED
@@ -1 +0,0 @@
1
- ccccccc