wakame 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +20 -0
- data/README.rdoc +63 -0
- data/Rakefile +86 -0
- data/VERSION +1 -0
- data/app_generators/wakame/templates/README +0 -0
- data/app_generators/wakame/templates/Rakefile +18 -0
- data/app_generators/wakame/templates/bin/wakame-agent +9 -0
- data/app_generators/wakame/templates/bin/wakame-master +9 -0
- data/app_generators/wakame/templates/bin/wakameadm +9 -0
- data/app_generators/wakame/templates/cluster/resources/apache_app/apache_app.rb +54 -0
- data/app_generators/wakame/templates/cluster/resources/apache_app/conf/apache2.conf +46 -0
- data/app_generators/wakame/templates/cluster/resources/apache_app/conf/envvars-app +7 -0
- data/app_generators/wakame/templates/cluster/resources/apache_app/conf/sites-app.conf +23 -0
- data/app_generators/wakame/templates/cluster/resources/apache_app/conf/system-app.conf +67 -0
- data/app_generators/wakame/templates/cluster/resources/apache_app/init.d/apache2-app +192 -0
- data/app_generators/wakame/templates/cluster/resources/apache_lb/apache_lb.rb +56 -0
- data/app_generators/wakame/templates/cluster/resources/apache_lb/conf/apache2.conf +46 -0
- data/app_generators/wakame/templates/cluster/resources/apache_lb/conf/envvars-lb +6 -0
- data/app_generators/wakame/templates/cluster/resources/apache_lb/conf/sites-lb.conf +54 -0
- data/app_generators/wakame/templates/cluster/resources/apache_lb/conf/system-lb.conf +75 -0
- data/app_generators/wakame/templates/cluster/resources/apache_lb/init.d/apache2-lb +192 -0
- data/app_generators/wakame/templates/cluster/resources/apache_www/apache_www.rb +50 -0
- data/app_generators/wakame/templates/cluster/resources/apache_www/conf/apache2.conf +47 -0
- data/app_generators/wakame/templates/cluster/resources/apache_www/conf/envvars-www +7 -0
- data/app_generators/wakame/templates/cluster/resources/apache_www/conf/sites-www.conf +23 -0
- data/app_generators/wakame/templates/cluster/resources/apache_www/conf/system-www.conf +63 -0
- data/app_generators/wakame/templates/cluster/resources/apache_www/init.d/apache2-www +192 -0
- data/app_generators/wakame/templates/cluster/resources/ec2_elastic_ip/ec2_elastic_ip.rb +39 -0
- data/app_generators/wakame/templates/cluster/resources/mysql_master/conf/my.cnf +154 -0
- data/app_generators/wakame/templates/cluster/resources/mysql_master/init.d/mysql +185 -0
- data/app_generators/wakame/templates/cluster/resources/mysql_master/mysql_master.rb +174 -0
- data/app_generators/wakame/templates/config/boot.rb +85 -0
- data/app_generators/wakame/templates/config/cluster.rb +64 -0
- data/app_generators/wakame/templates/config/environments/common.rb +0 -0
- data/app_generators/wakame/templates/config/environments/ec2.rb +3 -0
- data/app_generators/wakame/templates/config/environments/stand_alone.rb +0 -0
- data/app_generators/wakame/templates/config/init.d/wakame-agent +72 -0
- data/app_generators/wakame/templates/config/init.d/wakame-master +73 -0
- data/app_generators/wakame/wakame_generator.rb +124 -0
- data/bin/wakame +18 -0
- data/contrib/imagesetup.sh +77 -0
- data/lib/ext/eventmachine.rb +86 -0
- data/lib/ext/shellwords.rb +172 -0
- data/lib/ext/uri.rb +15 -0
- data/lib/wakame/action.rb +156 -0
- data/lib/wakame/actions/destroy_instances.rb +39 -0
- data/lib/wakame/actions/launch_cluster.rb +31 -0
- data/lib/wakame/actions/migrate_service.rb +65 -0
- data/lib/wakame/actions/propagate_instances.rb +95 -0
- data/lib/wakame/actions/reload_service.rb +21 -0
- data/lib/wakame/actions/scaleout_when_high_load.rb +44 -0
- data/lib/wakame/actions/shutdown_cluster.rb +22 -0
- data/lib/wakame/actions/shutdown_vm.rb +19 -0
- data/lib/wakame/actions/start_service.rb +64 -0
- data/lib/wakame/actions/stop_service.rb +49 -0
- data/lib/wakame/actions/util.rb +71 -0
- data/lib/wakame/actor/daemon.rb +37 -0
- data/lib/wakame/actor/service_monitor.rb +21 -0
- data/lib/wakame/actor/system.rb +46 -0
- data/lib/wakame/actor.rb +33 -0
- data/lib/wakame/agent.rb +226 -0
- data/lib/wakame/amqp_client.rb +219 -0
- data/lib/wakame/command/action_status.rb +62 -0
- data/lib/wakame/command/actor.rb +23 -0
- data/lib/wakame/command/clone_service.rb +12 -0
- data/lib/wakame/command/launch_cluster.rb +15 -0
- data/lib/wakame/command/migrate_service.rb +21 -0
- data/lib/wakame/command/propagate_service.rb +24 -0
- data/lib/wakame/command/shutdown_cluster.rb +15 -0
- data/lib/wakame/command/status.rb +81 -0
- data/lib/wakame/command.rb +31 -0
- data/lib/wakame/command_queue.rb +44 -0
- data/lib/wakame/configuration.rb +93 -0
- data/lib/wakame/daemonize.rb +96 -0
- data/lib/wakame/event.rb +232 -0
- data/lib/wakame/event_dispatcher.rb +154 -0
- data/lib/wakame/graph.rb +79 -0
- data/lib/wakame/initializer.rb +162 -0
- data/lib/wakame/instance_counter.rb +78 -0
- data/lib/wakame/logger.rb +12 -0
- data/lib/wakame/manager/commands.rb +134 -0
- data/lib/wakame/master.rb +369 -0
- data/lib/wakame/monitor/agent.rb +50 -0
- data/lib/wakame/monitor/service.rb +183 -0
- data/lib/wakame/monitor.rb +69 -0
- data/lib/wakame/packets.rb +160 -0
- data/lib/wakame/queue_declare.rb +14 -0
- data/lib/wakame/rule.rb +116 -0
- data/lib/wakame/rule_engine.rb +202 -0
- data/lib/wakame/runner/administrator_command.rb +112 -0
- data/lib/wakame/runner/agent.rb +81 -0
- data/lib/wakame/runner/master.rb +93 -0
- data/lib/wakame/scheduler.rb +251 -0
- data/lib/wakame/service.rb +914 -0
- data/lib/wakame/template.rb +189 -0
- data/lib/wakame/trigger.rb +66 -0
- data/lib/wakame/triggers/instance_count_update.rb +45 -0
- data/lib/wakame/triggers/load_history.rb +107 -0
- data/lib/wakame/triggers/maintain_ssh_known_hosts.rb +43 -0
- data/lib/wakame/triggers/process_command.rb +34 -0
- data/lib/wakame/triggers/shutdown_unused_vm.rb +16 -0
- data/lib/wakame/util.rb +569 -0
- data/lib/wakame/vm_manipulator.rb +186 -0
- data/lib/wakame.rb +59 -0
- data/tasks/ec2.rake +127 -0
- data/tests/cluster.json +3 -0
- data/tests/conf/a +1 -0
- data/tests/conf/b +1 -0
- data/tests/conf/c +1 -0
- data/tests/setup_agent.rb +39 -0
- data/tests/setup_master.rb +28 -0
- data/tests/test_actor.rb +54 -0
- data/tests/test_agent.rb +218 -0
- data/tests/test_amqp_client.rb +94 -0
- data/tests/test_graph.rb +36 -0
- data/tests/test_master.rb +167 -0
- data/tests/test_monitor.rb +47 -0
- data/tests/test_rule_engine.rb +127 -0
- data/tests/test_scheduler.rb +123 -0
- data/tests/test_service.rb +60 -0
- data/tests/test_template.rb +67 -0
- data/tests/test_uri_amqp.rb +19 -0
- data/tests/test_util.rb +71 -0
- data/wakame_generators/resource/resource_generator.rb +54 -0
- data/wakame_generators/resource/templates/apache_app/apache_app.rb +60 -0
- data/wakame_generators/resource/templates/apache_app/conf/apache2.conf +46 -0
- data/wakame_generators/resource/templates/apache_app/conf/envvars-app +7 -0
- data/wakame_generators/resource/templates/apache_app/conf/sites-app.conf +23 -0
- data/wakame_generators/resource/templates/apache_app/conf/system-app.conf +67 -0
- data/wakame_generators/resource/templates/apache_app/init.d/apache2-app +192 -0
- data/wakame_generators/resource/templates/apache_lb/apache_lb.rb +67 -0
- data/wakame_generators/resource/templates/apache_lb/conf/apache2.conf +46 -0
- data/wakame_generators/resource/templates/apache_lb/conf/envvars-lb +6 -0
- data/wakame_generators/resource/templates/apache_lb/conf/sites-lb.conf +54 -0
- data/wakame_generators/resource/templates/apache_lb/conf/system-lb.conf +75 -0
- data/wakame_generators/resource/templates/apache_lb/init.d/apache2-lb +192 -0
- data/wakame_generators/resource/templates/apache_www/apache_www.rb +56 -0
- data/wakame_generators/resource/templates/apache_www/conf/apache2.conf +47 -0
- data/wakame_generators/resource/templates/apache_www/conf/envvars-www +7 -0
- data/wakame_generators/resource/templates/apache_www/conf/sites-www.conf +23 -0
- data/wakame_generators/resource/templates/apache_www/conf/system-www.conf +63 -0
- data/wakame_generators/resource/templates/apache_www/init.d/apache2-www +192 -0
- data/wakame_generators/resource/templates/ec2_elastic_ip/ec2_elastic_ip.rb +39 -0
- data/wakame_generators/resource/templates/mysql_master/conf/my.cnf +154 -0
- data/wakame_generators/resource/templates/mysql_master/init.d/mysql +185 -0
- data/wakame_generators/resource/templates/mysql_master/mysql_master.rb +119 -0
- metadata +289 -0
@@ -0,0 +1,174 @@
|
|
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
|
@@ -0,0 +1,85 @@
|
|
1
|
+
|
2
|
+
require 'pathname'
|
3
|
+
WAKAME_ROOT = Pathname.new((ENV['WAKAME_ROOT'] || "#{File.dirname(__FILE__)}/..").dup).realpath unless defined?(WAKAME_ROOT)
|
4
|
+
|
5
|
+
module Wakame
|
6
|
+
module Bootstrap
|
7
|
+
class << self
|
8
|
+
def boot_master!
|
9
|
+
boot!(:process_master)
|
10
|
+
end
|
11
|
+
def boot_agent!
|
12
|
+
boot!(:process_agent)
|
13
|
+
end
|
14
|
+
def boot_cli!
|
15
|
+
boot!(:process_cli)
|
16
|
+
end
|
17
|
+
|
18
|
+
def boot!(method=:process)
|
19
|
+
unless booted?
|
20
|
+
run_bootstrap
|
21
|
+
Wakame::Initializer.run(method)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def booted?
|
26
|
+
#defined?(Wakame::Initializer)
|
27
|
+
!@bootclass.nil?
|
28
|
+
end
|
29
|
+
|
30
|
+
def boot_type
|
31
|
+
@bootclass.class
|
32
|
+
end
|
33
|
+
|
34
|
+
def run_bootstrap
|
35
|
+
@bootclass = (framework_bundled? ? VendorBoot : GemBoot).new
|
36
|
+
@bootclass.run
|
37
|
+
end
|
38
|
+
|
39
|
+
def framework_bundled?
|
40
|
+
File.exists?("#{WAKAME_ROOT}/vendor/wakame")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
class Boot
|
45
|
+
def run
|
46
|
+
load_initializer
|
47
|
+
end
|
48
|
+
|
49
|
+
def load_initializer
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
class VendorBoot < Boot
|
54
|
+
def load_initializer
|
55
|
+
require "#{WAKAME_ROOT}/vendor/wakame/lib/wakame/initializer"
|
56
|
+
require "#{WAKAME_ROOT}/vendor/wakame/lib/wakame/configuration"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
class GemBoot < Boot
|
61
|
+
def load_initializer
|
62
|
+
load_rubygems
|
63
|
+
gem 'wakame'
|
64
|
+
require 'wakame/initializer'
|
65
|
+
require 'wakame/configuration'
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
def load_rubygems
|
70
|
+
require 'rubygems'
|
71
|
+
unless rubygems_version >= '1.3.0'
|
72
|
+
$stderr.puts "Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again."
|
73
|
+
exit 1
|
74
|
+
end
|
75
|
+
|
76
|
+
rescue LoadError
|
77
|
+
$stderr.puts "Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org"
|
78
|
+
exit 1
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
class WebCluster < Wakame::Service::ServiceCluster
|
2
|
+
attr_accessor :propagation_priority
|
3
|
+
|
4
|
+
module HttpAppServer; end
|
5
|
+
module HttpAssetServer; end
|
6
|
+
module HttpLoadBalanceServer; end
|
7
|
+
|
8
|
+
VirtualHost = Class.new(OpenStruct)
|
9
|
+
def initialize(master, &blk)
|
10
|
+
super(master) { |c|
|
11
|
+
c.add_resource(Ec2ElasticIp.new)
|
12
|
+
c.add_resource(Apache_WWW.new)
|
13
|
+
c.add_resource(Apache_APP.new)
|
14
|
+
c.add_resource(Apache_LB.new)
|
15
|
+
c.add_resource(MySQL_Master.new)
|
16
|
+
|
17
|
+
c.set_dependency(Apache_LB, Ec2ElasticIp)
|
18
|
+
c.set_dependency(Apache_WWW, Apache_LB)
|
19
|
+
c.set_dependency(Apache_APP, Apache_LB)
|
20
|
+
c.set_dependency(MySQL_Master, Apache_APP)
|
21
|
+
}
|
22
|
+
|
23
|
+
define_rule { |r|
|
24
|
+
r.register_trigger(Wakame::Triggers::ProcessCommand.new)
|
25
|
+
r.register_trigger(Wakame::Triggers::MaintainSshKnownHosts.new)
|
26
|
+
#r.register_trigger(Wakame::Triggers::LoadHistoryMonitor.new)
|
27
|
+
#r.register_trigger(Wakame::Triggers::InstanceCountUpdate.new)
|
28
|
+
#r.register_trigger(Wakame::Triggers::ScaleOutWhenHighLoad.new)
|
29
|
+
#r.register_trigger(Wakame::Triggers::ShutdownUnusedVM.new)
|
30
|
+
}
|
31
|
+
|
32
|
+
add_virtual_host(VirtualHost.new(:server_name=>'aaa.test', :document_root=>'/home/wakame/app/development/test/public'))
|
33
|
+
add_virtual_host(VirtualHost.new(:server_name=>'bbb.test', :document_root=>'/home/wakame/app/development/test/public'))
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
def virtual_hosts
|
38
|
+
@virtual_hosts ||= []
|
39
|
+
end
|
40
|
+
|
41
|
+
def add_virtual_host(vh)
|
42
|
+
virtual_hosts << vh
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
def each_app(&blk)
|
47
|
+
each_instance(HttpAppServer) { |n|
|
48
|
+
blk.call(n)
|
49
|
+
}
|
50
|
+
end
|
51
|
+
|
52
|
+
def each_www(&blk)
|
53
|
+
each_instance(HttpAssetServer) { |n|
|
54
|
+
blk.call(n)
|
55
|
+
}
|
56
|
+
end
|
57
|
+
|
58
|
+
def each_mysql(&blk)
|
59
|
+
each_instance(MySQL_Master) { |n|
|
60
|
+
blk.call(n)
|
61
|
+
}
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
File without changes
|
File without changes
|
@@ -0,0 +1,72 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
# Start/stop the wakame agent daemon.
|
3
|
+
#
|
4
|
+
### BEGIN INIT INFO
|
5
|
+
# Provides: wakame-agent
|
6
|
+
# Required-Start: $local_fs $network rabbitmq-server wakame-master
|
7
|
+
# Required-Stop: $local_fs $network rabbitmq-server wakame-master
|
8
|
+
# Default-Start: 2 3 4 5
|
9
|
+
# Default-Stop: 0 1 6
|
10
|
+
# Short-Description:
|
11
|
+
# Description: cron is a standard UNIX program that runs user-specified
|
12
|
+
# programs at periodic scheduled times. vixie cron adds a
|
13
|
+
# number of features to the basic UNIX cron, including better
|
14
|
+
# security and more powerful configuration options.
|
15
|
+
### END INIT INFO
|
16
|
+
|
17
|
+
PIDFILE=/var/run/wakame/wakame-agent.pid
|
18
|
+
|
19
|
+
#LSBNAMES='-l' # Uncomment for LSB name support in /etc/cron.d/
|
20
|
+
|
21
|
+
. /lib/lsb/init-functions
|
22
|
+
if [ -z $WAKAME_HOME ]; then
|
23
|
+
[ -f /etc/default/wakame ] && . /etc/default/wakame
|
24
|
+
export GEM_HOME WAKAME_HOME WAKAME_ENV
|
25
|
+
fi
|
26
|
+
|
27
|
+
start_agent()
|
28
|
+
{
|
29
|
+
typeset user_data i
|
30
|
+
# Prepare the parent directory for the pidfile.
|
31
|
+
typeset pid_dir=`dirname $PIDFILE`
|
32
|
+
[ -d $pid_dir ] || {
|
33
|
+
mkdir -p /var/run/wakame
|
34
|
+
}
|
35
|
+
|
36
|
+
user_data="`curl -s -f --retry 3 http://169.254.169.254/2008-02-01/user-data`"
|
37
|
+
if [ "$?" = 0 -a -n "$user_data" ]; then
|
38
|
+
for i in `echo "$user_data" | awk -F\= '$1 == "amqp_server" {print $2}'`
|
39
|
+
do
|
40
|
+
opts="$opts -s $i"
|
41
|
+
done
|
42
|
+
fi
|
43
|
+
start-stop-daemon --start --quiet --pidfile $PIDFILE --name wakame-agent --startas $WAKAME_HOME/bin/wakame-agent -- $opts $LSBNAMES
|
44
|
+
}
|
45
|
+
|
46
|
+
stop_agent()
|
47
|
+
{
|
48
|
+
start-stop-daemon --stop --quiet --pidfile $PIDFILE --name wakame-agent
|
49
|
+
}
|
50
|
+
|
51
|
+
case "$1" in
|
52
|
+
start) log_daemon_msg "Starting agent process for Wakame" "wakame-agent"
|
53
|
+
start_agent
|
54
|
+
log_end_msg $?
|
55
|
+
;;
|
56
|
+
stop) log_daemon_msg "Stopping agent process for Wakame" "wakame-agent"
|
57
|
+
stop_agent
|
58
|
+
log_end_msg $?
|
59
|
+
;;
|
60
|
+
restart) log_daemon_msg "Restarting agent process for Wakame" "wakame-agent"
|
61
|
+
stop_agent
|
62
|
+
start_agent
|
63
|
+
log_end_msg $?
|
64
|
+
;;
|
65
|
+
reload|force-reload) log_daemon_msg "Reloading configuration files for " ""
|
66
|
+
log_end_msg 0
|
67
|
+
;;
|
68
|
+
*) log_action_msg "Usage: /etc/init.d/wakame-agent {start|stop|restart|reload|force-reload}"
|
69
|
+
exit 2
|
70
|
+
;;
|
71
|
+
esac
|
72
|
+
exit 0
|
@@ -0,0 +1,73 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
# Start/stop the wakame master daemon.
|
3
|
+
#
|
4
|
+
### BEGIN INIT INFO
|
5
|
+
# Provides: wakame-master
|
6
|
+
# Required-Start: $local_fs $network rabbitmq-server
|
7
|
+
# Required-Stop: $local_fs $network rabbitmq-server
|
8
|
+
# Default-Start: 2 3 4 5
|
9
|
+
# Default-Stop: 0 1 6
|
10
|
+
# Short-Description:
|
11
|
+
# Description: cron is a standard UNIX program that runs user-specified
|
12
|
+
# programs at periodic scheduled times. vixie cron adds a
|
13
|
+
# number of features to the basic UNIX cron, including better
|
14
|
+
# security and more powerful configuration options.
|
15
|
+
### END INIT INFO
|
16
|
+
|
17
|
+
USER=wakame
|
18
|
+
GROUP=wakame
|
19
|
+
PIDFILE=/var/run/wakame/wakame-master.pid
|
20
|
+
|
21
|
+
#LSBNAMES='-l' # Uncomment for LSB name support in /etc/cron.d/
|
22
|
+
|
23
|
+
. /lib/lsb/init-functions
|
24
|
+
if [ -z $WAKAME_HOME ]; then
|
25
|
+
[ -f /etc/default/wakame ] && . /etc/default/wakame
|
26
|
+
export GEM_HOME WAKAME_HOME WAKAME_ENV
|
27
|
+
fi
|
28
|
+
|
29
|
+
start_master()
|
30
|
+
{
|
31
|
+
curl -s -f --retry 3 http://169.254.169.254/2008-02-01/user-data | grep "node=agent" > /dev/null && {
|
32
|
+
log_daemon_msg "Canceled to start master process for Wakame"
|
33
|
+
exit 0
|
34
|
+
}
|
35
|
+
# Prepare the parent directory for the pidfile.
|
36
|
+
typeset pid_dir=`dirname $PIDFILE`
|
37
|
+
if su -c "test -w $pid_dir" $USER; then
|
38
|
+
:
|
39
|
+
else
|
40
|
+
mkdir -p $pid_dir
|
41
|
+
chown "$USER:$GROUP" $pid_dir
|
42
|
+
fi
|
43
|
+
|
44
|
+
start-stop-daemon --start --quiet --pidfile $PIDFILE --name wakame-master --startas $WAKAME_HOME/bin/wakame-master -- -u $USER $LSBNAMES
|
45
|
+
|
46
|
+
}
|
47
|
+
stop_master()
|
48
|
+
{
|
49
|
+
start-stop-daemon --stop --quiet --pidfile $PIDFILE --name wakame-master
|
50
|
+
}
|
51
|
+
|
52
|
+
case "$1" in
|
53
|
+
start) log_daemon_msg "Starting master process for Wakame" "wakame-master"
|
54
|
+
start_master
|
55
|
+
log_end_msg $?
|
56
|
+
;;
|
57
|
+
stop) log_daemon_msg "Stopping master process for Wakame" "wakame-master"
|
58
|
+
stop_master
|
59
|
+
log_end_msg $?
|
60
|
+
;;
|
61
|
+
restart) log_daemon_msg "Restarting master process for Wakame" "wakame-master"
|
62
|
+
stop_master
|
63
|
+
start_master
|
64
|
+
log_end_msg $?
|
65
|
+
;;
|
66
|
+
reload|force-reload) log_daemon_msg "Reloading configuration files for " ""
|
67
|
+
log_end_msg 0
|
68
|
+
;;
|
69
|
+
*) log_action_msg "Usage: /etc/init.d/wakame-master {start|stop|restart|reload|force-reload}"
|
70
|
+
exit 2
|
71
|
+
;;
|
72
|
+
esac
|
73
|
+
exit 0
|
@@ -0,0 +1,124 @@
|
|
1
|
+
require 'rbconfig'
|
2
|
+
|
3
|
+
class WakameGenerator < RubiGen::Base
|
4
|
+
|
5
|
+
DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'],
|
6
|
+
Config::CONFIG['ruby_install_name'])
|
7
|
+
|
8
|
+
# Installation skeleton. Intermediate directories are automatically
|
9
|
+
# created so don't sweat their absence here.
|
10
|
+
BASEDIRS = %w(
|
11
|
+
bin
|
12
|
+
cluster
|
13
|
+
cluster/actors
|
14
|
+
cluster/actions
|
15
|
+
cluster/triggers
|
16
|
+
cluster/resources
|
17
|
+
cluster/commands
|
18
|
+
config
|
19
|
+
config/init.d
|
20
|
+
config/environments
|
21
|
+
lib
|
22
|
+
tasks
|
23
|
+
vendor
|
24
|
+
)
|
25
|
+
|
26
|
+
default_options :shebang => DEFAULT_SHEBANG,
|
27
|
+
:bin_name => nil,
|
28
|
+
:import_path => nil,
|
29
|
+
:version => '0.0.1'
|
30
|
+
|
31
|
+
|
32
|
+
attr_reader :gem_name, :module_name, :project_name
|
33
|
+
attr_reader :version, :version_str
|
34
|
+
|
35
|
+
# extensions/option
|
36
|
+
attr_reader :bin_names_list
|
37
|
+
|
38
|
+
def initialize(runtime_args, runtime_options = {})
|
39
|
+
super(config_args_and_runtime_args(runtime_args), runtime_options)
|
40
|
+
usage if args.empty?
|
41
|
+
@destination_root = File.expand_path(args.shift)
|
42
|
+
@gem_name = base_name
|
43
|
+
@module_name = gem_name.gsub('-','_').camelize
|
44
|
+
@project_name = @gem_name
|
45
|
+
extract_options
|
46
|
+
end
|
47
|
+
|
48
|
+
def manifest
|
49
|
+
# Use /usr/bin/env if no special shebang was specified
|
50
|
+
script_options = { :chmod => 0755, :shebang => options[:shebang] == DEFAULT_SHEBANG ? nil : options[:shebang] }
|
51
|
+
windows = (RUBY_PLATFORM =~ /dos|win32|cygwin/i) || (RUBY_PLATFORM =~ /(:?mswin|mingw)/)
|
52
|
+
source_dir = source_path('.').sub(%r{/\.\Z}, '')
|
53
|
+
|
54
|
+
record do |m|
|
55
|
+
# Root directory and all subdirectories.
|
56
|
+
m.directory ''
|
57
|
+
BASEDIRS.each { |path| m.directory path }
|
58
|
+
|
59
|
+
m.file_copy_each %w(Rakefile README)
|
60
|
+
m.file_copy_each %w(config/boot.rb config/cluster.rb config/environments/common.rb config/environments/stand_alone.rb config/environments/ec2.rb)
|
61
|
+
m.file_copy_each %w(config/init.d/wakame-master config/init.d/wakame-agent)
|
62
|
+
|
63
|
+
m.dependency "install_rubigen_scripts", [destination_root, :wakame]
|
64
|
+
|
65
|
+
%w(wakame-master wakame-agent wakameadm).each do |script|
|
66
|
+
m.template "bin/#{script}", "bin/#{script}", script_options
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
protected
|
73
|
+
def banner
|
74
|
+
<<-EOS
|
75
|
+
Usage: #{File.basename $0} /path/to/your/app [options]
|
76
|
+
EOS
|
77
|
+
end
|
78
|
+
|
79
|
+
def add_options!(opts)
|
80
|
+
opts.separator ''
|
81
|
+
opts.separator 'Options:'
|
82
|
+
opts.on("-b", "--bin-name=BIN_NAME[,BIN_NAME2]", String,
|
83
|
+
"Sets up executable scripts in the bin folder.",
|
84
|
+
"Default: none") { |x| options[:bin_name] = x }
|
85
|
+
opts.on("-i", "--install=generator", String,
|
86
|
+
"Installs a generator called install_<generator>.",
|
87
|
+
"For example, '-i cucumber' runs the install_cucumber generator.",
|
88
|
+
"Can be used multiple times for different generators.",
|
89
|
+
"Cannot be used for generators that require argumnts.",
|
90
|
+
"Default: none") do |generator|
|
91
|
+
options[:install] ||= []
|
92
|
+
options[:install] << generator
|
93
|
+
end
|
94
|
+
opts.on("-p", "--project=PROJECT", String,
|
95
|
+
"Rubyforge project name for the gem you are creating.",
|
96
|
+
"Default: same as gem name") { |x| options[:project] = x }
|
97
|
+
opts.on("-r", "--ruby=path", String,
|
98
|
+
"Path to the Ruby binary of your choice (otherwise scripts use env, dispatchers current path).",
|
99
|
+
"Default: #{DEFAULT_SHEBANG}") { |x| options[:shebang] = x }
|
100
|
+
opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.")
|
101
|
+
end
|
102
|
+
|
103
|
+
def extract_options
|
104
|
+
@version = options[:version].to_s.split(/\./)
|
105
|
+
@version_str = @version.join('.')
|
106
|
+
|
107
|
+
@bin_names_list = (options[:bin_name] || "").split(',')
|
108
|
+
@project_name = options[:project] if options.include?(:project)
|
109
|
+
@install_generators = options[:install] || []
|
110
|
+
end
|
111
|
+
|
112
|
+
# first attempt to merge config args (single string) and runtime args
|
113
|
+
def config_args_and_runtime_args(runtime_args)
|
114
|
+
newgem_config = File.expand_path(File.join(ENV['HOME'], '.newgem.yml'))
|
115
|
+
if File.exists?(newgem_config)
|
116
|
+
config = YAML.load(File.read(newgem_config))
|
117
|
+
if config_args = (config["default"] || config[config.keys.first])
|
118
|
+
return config_args.split(" ") + runtime_args
|
119
|
+
end
|
120
|
+
end
|
121
|
+
runtime_args
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
data/bin/wakame
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- ruby -*-
|
3
|
+
require 'rubygems' rescue ENV['NO_RUBYGEMS']
|
4
|
+
if %w(--version -v).include? ARGV.first
|
5
|
+
require File.dirname(__FILE__) + "/../lib/wakame"
|
6
|
+
puts "#{File.basename($0)} #{Wakame::VERSION}"
|
7
|
+
exit(0)
|
8
|
+
end
|
9
|
+
|
10
|
+
#app_path = ARGV.first
|
11
|
+
|
12
|
+
require 'rubigen'
|
13
|
+
require 'rubigen/scripts/generate'
|
14
|
+
RubiGen::Base.use_application_sources!
|
15
|
+
RubiGen::Base.append_sources RubiGen::PathSource.new(:application,
|
16
|
+
File.join(File.dirname(__FILE__), "../app_generators"))
|
17
|
+
#p RubiGen::Base.sources
|
18
|
+
RubiGen::Scripts::Generate.new.run(ARGV, :generator => 'wakame')
|