sml-rubber 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (147) hide show
  1. data/COPYING +339 -0
  2. data/README +6 -0
  3. data/TODO +9 -0
  4. data/VERSION +1 -0
  5. data/generators/vulcanize/USAGE +6 -0
  6. data/generators/vulcanize/templates/apache/config/rubber/deploy-apache.rb +45 -0
  7. data/generators/vulcanize/templates/apache/config/rubber/role/web/deflate.conf +10 -0
  8. data/generators/vulcanize/templates/apache/config/rubber/role/web/expires.conf +9 -0
  9. data/generators/vulcanize/templates/apache/config/rubber/role/web/headers.conf +6 -0
  10. data/generators/vulcanize/templates/apache/config/rubber/role/web/setenvif.conf +52 -0
  11. data/generators/vulcanize/templates/apache/config/rubber/role/web/vhost.conf +27 -0
  12. data/generators/vulcanize/templates/apache/config/rubber/rubber-apache.yml +15 -0
  13. data/generators/vulcanize/templates/apache/templates.yml +1 -0
  14. data/generators/vulcanize/templates/base/Capfile +17 -0
  15. data/generators/vulcanize/templates/base/config/deploy.rb +77 -0
  16. data/generators/vulcanize/templates/base/config/rubber/common/crontab +16 -0
  17. data/generators/vulcanize/templates/base/config/rubber/common/profile.rc +9 -0
  18. data/generators/vulcanize/templates/base/config/rubber/deploy-setup.rb +56 -0
  19. data/generators/vulcanize/templates/base/config/rubber/rubber.yml +221 -0
  20. data/generators/vulcanize/templates/base/lib/tasks/rubber.rake +18 -0
  21. data/generators/vulcanize/templates/base/script/cron-rake +18 -0
  22. data/generators/vulcanize/templates/base/script/cron-runner +18 -0
  23. data/generators/vulcanize/templates/base/script/cron-sh +67 -0
  24. data/generators/vulcanize/templates/base/templates.yml +1 -0
  25. data/generators/vulcanize/templates/complete_mysql/templates.yml +6 -0
  26. data/generators/vulcanize/templates/complete_passenger_mysql/templates.yml +8 -0
  27. data/generators/vulcanize/templates/cruise/config/rubber/deploy-cruise.rb +74 -0
  28. data/generators/vulcanize/templates/cruise/config/rubber/role/cruise/cruise +40 -0
  29. data/generators/vulcanize/templates/cruise/config/rubber/role/cruise/my.cnf +165 -0
  30. data/generators/vulcanize/templates/cruise/config/rubber/role/cruise/production.rb +8 -0
  31. data/generators/vulcanize/templates/cruise/config/rubber/role/cruise/site_config.rb +76 -0
  32. data/generators/vulcanize/templates/cruise/config/rubber/role/web_tools/cruise-nginx.conf +11 -0
  33. data/generators/vulcanize/templates/cruise/config/rubber/rubber-cruise.yml +18 -0
  34. data/generators/vulcanize/templates/cruise/templates.yml +1 -0
  35. data/generators/vulcanize/templates/haproxy/config/rubber/deploy-haproxy.rb +45 -0
  36. data/generators/vulcanize/templates/haproxy/config/rubber/role/haproxy/haproxy-default.conf +8 -0
  37. data/generators/vulcanize/templates/haproxy/config/rubber/role/haproxy/haproxy.conf +44 -0
  38. data/generators/vulcanize/templates/haproxy/config/rubber/role/haproxy/monit-haproxy.conf +9 -0
  39. data/generators/vulcanize/templates/haproxy/config/rubber/role/haproxy/syslog-haproxy.conf +6 -0
  40. data/generators/vulcanize/templates/haproxy/config/rubber/role/haproxy/syslogd-default.conf +17 -0
  41. data/generators/vulcanize/templates/haproxy/config/rubber/role/web_tools/haproxy-nginx.conf +10 -0
  42. data/generators/vulcanize/templates/haproxy/config/rubber/rubber-haproxy.yml +12 -0
  43. data/generators/vulcanize/templates/haproxy/templates.yml +1 -0
  44. data/generators/vulcanize/templates/memcached/config/memcached.yml +28 -0
  45. data/generators/vulcanize/templates/memcached/config/rubber/common/memcached.yml +14 -0
  46. data/generators/vulcanize/templates/memcached/config/rubber/role/memcached/memcached.conf +52 -0
  47. data/generators/vulcanize/templates/memcached/config/rubber/role/memcached/memcached_munin_plugin +249 -0
  48. data/generators/vulcanize/templates/memcached/config/rubber/rubber-memcached.yml +7 -0
  49. data/generators/vulcanize/templates/memcached/templates.yml +1 -0
  50. data/generators/vulcanize/templates/minimal_mysql/templates.yml +7 -0
  51. data/generators/vulcanize/templates/minimal_nodb/templates.yml +6 -0
  52. data/generators/vulcanize/templates/mongrel/config/rubber/deploy-mongrel.rb +75 -0
  53. data/generators/vulcanize/templates/mongrel/config/rubber/role/app/mongrel_cluster.yml +12 -0
  54. data/generators/vulcanize/templates/mongrel/config/rubber/role/app/monit-mongrel.conf +20 -0
  55. data/generators/vulcanize/templates/mongrel/config/rubber/rubber-mongrel.yml +9 -0
  56. data/generators/vulcanize/templates/mongrel/templates.yml +1 -0
  57. data/generators/vulcanize/templates/monit/config/rubber/common/monit-default.conf +15 -0
  58. data/generators/vulcanize/templates/monit/config/rubber/common/monit.conf +251 -0
  59. data/generators/vulcanize/templates/monit/config/rubber/deploy-monit.rb +32 -0
  60. data/generators/vulcanize/templates/monit/config/rubber/role/web_tools/monit-admin-nginx.conf +10 -0
  61. data/generators/vulcanize/templates/monit/config/rubber/rubber-monit.yml +6 -0
  62. data/generators/vulcanize/templates/monit/templates.yml +1 -0
  63. data/generators/vulcanize/templates/munin/config/rubber/common/monit-munin.conf +8 -0
  64. data/generators/vulcanize/templates/munin/config/rubber/common/munin-node.conf +48 -0
  65. data/generators/vulcanize/templates/munin/config/rubber/deploy-munin.rb +30 -0
  66. data/generators/vulcanize/templates/munin/config/rubber/role/web_tools/munin-nginx.conf +8 -0
  67. data/generators/vulcanize/templates/munin/config/rubber/role/web_tools/munin-plugins.conf +31 -0
  68. data/generators/vulcanize/templates/munin/config/rubber/role/web_tools/munin.conf +80 -0
  69. data/generators/vulcanize/templates/munin/config/rubber/rubber-munin.yml +8 -0
  70. data/generators/vulcanize/templates/munin/script/munin/example_mysql_query.rb +57 -0
  71. data/generators/vulcanize/templates/munin/script/munin/example_simple.rb +24 -0
  72. data/generators/vulcanize/templates/munin/templates.yml +1 -0
  73. data/generators/vulcanize/templates/mysql/config/rubber/common/database.yml +11 -0
  74. data/generators/vulcanize/templates/mysql/config/rubber/deploy-mysql.rb +178 -0
  75. data/generators/vulcanize/templates/mysql/config/rubber/role/db/crontab +14 -0
  76. data/generators/vulcanize/templates/mysql/config/rubber/role/db/monit-mysql.cnf +10 -0
  77. data/generators/vulcanize/templates/mysql/config/rubber/role/db/my.cnf +167 -0
  78. data/generators/vulcanize/templates/mysql/config/rubber/role/mysql_slave/mysql_slave_munin_plugin +51 -0
  79. data/generators/vulcanize/templates/mysql/config/rubber/rubber-mysql.yml +38 -0
  80. data/generators/vulcanize/templates/mysql/templates.yml +1 -0
  81. data/generators/vulcanize/templates/mysql_cluster/config/rubber/common/mysql_cluster_migrations.rb +13 -0
  82. data/generators/vulcanize/templates/mysql_cluster/config/rubber/deploy-mysql_cluster.rb +173 -0
  83. data/generators/vulcanize/templates/mysql_cluster/config/rubber/role/mysql_data/my.cnf +15 -0
  84. data/generators/vulcanize/templates/mysql_cluster/config/rubber/role/mysql_mgm/ndb_mgmd.cnf +39 -0
  85. data/generators/vulcanize/templates/mysql_cluster/config/rubber/role/mysql_sql/monit-mysql_cluster_sql.cnf +10 -0
  86. data/generators/vulcanize/templates/mysql_cluster/config/rubber/role/mysql_sql/my.cnf +23 -0
  87. data/generators/vulcanize/templates/mysql_cluster/config/rubber/rubber-mysql_cluster.yml +32 -0
  88. data/generators/vulcanize/templates/mysql_cluster/templates.yml +1 -0
  89. data/generators/vulcanize/templates/mysql_proxy/config/rubber/common/database.yml +16 -0
  90. data/generators/vulcanize/templates/mysql_proxy/config/rubber/common/monit-mysql_proxy.cnf +10 -0
  91. data/generators/vulcanize/templates/mysql_proxy/config/rubber/common/mysql-proxy +153 -0
  92. data/generators/vulcanize/templates/mysql_proxy/config/rubber/common/mysql-proxy.conf +10 -0
  93. data/generators/vulcanize/templates/mysql_proxy/config/rubber/common/mysql-proxy.lua +5 -0
  94. data/generators/vulcanize/templates/mysql_proxy/config/rubber/deploy-mysql_proxy.rb +52 -0
  95. data/generators/vulcanize/templates/mysql_proxy/config/rubber/rubber-mysql_proxy.yml +11 -0
  96. data/generators/vulcanize/templates/mysql_proxy/templates.yml +1 -0
  97. data/generators/vulcanize/templates/nginx/config/rubber/deploy-nginx.rb +45 -0
  98. data/generators/vulcanize/templates/nginx/config/rubber/role/web/crontab +9 -0
  99. data/generators/vulcanize/templates/nginx/config/rubber/role/web/monit-nginx.conf +9 -0
  100. data/generators/vulcanize/templates/nginx/config/rubber/role/web/nginx.conf +133 -0
  101. data/generators/vulcanize/templates/nginx/config/rubber/role/web_tools/index.html +23 -0
  102. data/generators/vulcanize/templates/nginx/config/rubber/role/web_tools/nginx-tools.conf +74 -0
  103. data/generators/vulcanize/templates/nginx/config/rubber/rubber-nginx.yml +33 -0
  104. data/generators/vulcanize/templates/nginx/templates.yml +1 -0
  105. data/generators/vulcanize/templates/passenger/config/rubber/deploy-passenger.rb +27 -0
  106. data/generators/vulcanize/templates/passenger/config/rubber/role/web/passenger.conf +8 -0
  107. data/generators/vulcanize/templates/passenger/config/rubber/rubber-passenger.yml +4 -0
  108. data/generators/vulcanize/templates/passenger/templates.yml +1 -0
  109. data/generators/vulcanize/templates/sphinx/config/rubber/common/sphinx.yml +46 -0
  110. data/generators/vulcanize/templates/sphinx/config/rubber/deploy-sphinx.rb +112 -0
  111. data/generators/vulcanize/templates/sphinx/config/rubber/role/sphinx/crontab +11 -0
  112. data/generators/vulcanize/templates/sphinx/config/rubber/role/sphinx/monit-sphinx.conf +10 -0
  113. data/generators/vulcanize/templates/sphinx/config/rubber/rubber-sphinx.yml +6 -0
  114. data/generators/vulcanize/templates/sphinx/templates.yml +1 -0
  115. data/generators/vulcanize/vulcanize_generator.rb +67 -0
  116. data/lib/capistrano/hostcmd.rb +12 -0
  117. data/lib/rubber.rb +37 -0
  118. data/lib/rubber/capistrano.rb +1 -0
  119. data/lib/rubber/cloud.rb +13 -0
  120. data/lib/rubber/cloud/aws.rb +261 -0
  121. data/lib/rubber/cloud/base.rb +16 -0
  122. data/lib/rubber/configuration.rb +47 -0
  123. data/lib/rubber/dns.rb +13 -0
  124. data/lib/rubber/dns/base.rb +69 -0
  125. data/lib/rubber/dns/dyndns.rb +63 -0
  126. data/lib/rubber/dns/nettica.rb +56 -0
  127. data/lib/rubber/dns/zerigo.rb +121 -0
  128. data/lib/rubber/environment.rb +161 -0
  129. data/lib/rubber/generator.rb +197 -0
  130. data/lib/rubber/instance.rb +113 -0
  131. data/lib/rubber/recipes/rubber.rb +88 -0
  132. data/lib/rubber/recipes/rubber/bundles.rb +28 -0
  133. data/lib/rubber/recipes/rubber/deploy.rb +66 -0
  134. data/lib/rubber/recipes/rubber/instances.rb +298 -0
  135. data/lib/rubber/recipes/rubber/security_groups.rb +149 -0
  136. data/lib/rubber/recipes/rubber/setup.rb +285 -0
  137. data/lib/rubber/recipes/rubber/static_ips.rb +107 -0
  138. data/lib/rubber/recipes/rubber/utils.rb +195 -0
  139. data/lib/rubber/recipes/rubber/volumes.rb +263 -0
  140. data/lib/rubber/tasks/rubber.rb +218 -0
  141. data/lib/rubber/util.rb +33 -0
  142. data/test/environment_test.rb +118 -0
  143. data/test/generator_test.rb +323 -0
  144. data/test/instance_test.rb +38 -0
  145. data/test/test_helper.rb +4 -0
  146. data/test/util_test.rb +16 -0
  147. metadata +246 -0
@@ -0,0 +1,14 @@
1
+ <%
2
+ @read_cmd = 'crontab -l'
3
+ @write_cmd = 'crontab -'
4
+ @additive = ["# rubber-mysql-start", "# rubber-mysql-end"]
5
+ %>
6
+
7
+ <%
8
+ # Backup db every 3 hours to secondary db if available, else primary db
9
+ backup_db_host = rubber_instances.for_role('db', {}).first rescue nil
10
+ backup_db_host ||= rubber_instances.for_role('db', 'primary' => true).first
11
+ if backup_db_host.name == rubber_env.host
12
+ %>
13
+ 0 */3 * * * BACKUP_DIR=/mnt/db_backups DBUSER=<%= rubber_env.db_user %> DBPASS=<%= rubber_env.db_pass %> DBNAME=<%= rubber_env.db_name %> DBHOST=<%= backup_db_host.full_name %> <%= RUBBER_ROOT %>/script/cron-rake rubber:backup_db
14
+ <% end %>
@@ -0,0 +1,10 @@
1
+ <%
2
+ @path = '/etc/monit/monit.d/monit-mysql.conf'
3
+ %>
4
+
5
+ check process mysql with pidfile /var/run/mysqld/mysqld.pid
6
+ group mysql-<%= RUBBER_ENV %>
7
+ start program = "/etc/init.d/mysql start"
8
+ stop program = "/etc/init.d/mysql stop"
9
+ if failed host 127.0.0.1 port 3306 protocol mysql then alert
10
+ if 5 restarts within 5 cycles then timeout
@@ -0,0 +1,167 @@
1
+ <%
2
+ data_dir = rubber_env.db_data_dir
3
+ log_dir = rubber_env.db_log_dir
4
+ server_id = rubber_env.db_server_id
5
+ @path = '/etc/mysql/my.cnf'
6
+ @post = "mkdir -p #{log_dir}; chown mysql:adm #{log_dir}; chmod 2750 #{log_dir}"
7
+ %>
8
+
9
+ # Generated by rubber for host <%= rubber_instances[rubber_env.host].external_ip %>
10
+ #
11
+ # The MySQL database server configuration file.
12
+ #
13
+ # You can copy this to one of:
14
+ # - "/etc/mysql/my.cnf" to set global options,
15
+ # - "~/.my.cnf" to set user-specific options.
16
+ #
17
+ # One can use all long options that the program supports.
18
+ # Run program with --help to get a list of available options and with
19
+ # --print-defaults to see which it would actually understand and use.
20
+ #
21
+ # For explanations see
22
+ # http://dev.mysql.com/doc/mysql/en/server-system-variables.html
23
+
24
+ # This will be passed to all mysql clients
25
+ # It has been reported that passwords should be enclosed with ticks/quotes
26
+ # escpecially if they contain "#" chars...
27
+ # Remember to edit /etc/mysql/debian.cnf when changing the socket location.
28
+ [client]
29
+ default-character-set = utf8
30
+ port = 3306
31
+ socket = /var/run/mysqld/mysqld.sock
32
+
33
+ # Here is entries for some specific programs
34
+ # The following values assume you have at least 32M ram
35
+
36
+ # This was formally known as [safe_mysqld]. Both versions are currently parsed.
37
+ [mysqld_safe]
38
+ socket = /var/run/mysqld/mysqld.sock
39
+ nice = 0
40
+
41
+ [mysqld]
42
+ #
43
+ # * Basic Settings
44
+ #
45
+ default-character-set = utf8
46
+ user = mysql
47
+ pid-file = /var/run/mysqld/mysqld.pid
48
+ socket = /var/run/mysqld/mysqld.sock
49
+ port = 3306
50
+ basedir = /usr
51
+ datadir = <%= data_dir %>
52
+ tmpdir = /tmp
53
+ language = /usr/share/mysql/english
54
+ skip-external-locking
55
+
56
+ #
57
+ # Instead of skip-networking the default is now to listen only on
58
+ # localhost which is more compatible and is not less secure.
59
+ # bind-address = 127.0.0.1
60
+ #
61
+ # * Fine Tuning
62
+ #
63
+ key_buffer = 16M
64
+ max_allowed_packet = 32M
65
+ thread_stack = 128K
66
+ thread_cache_size = 8
67
+ #table_cache=500
68
+ #max_heap_table_size=16M
69
+ #tmp_table_size=32M
70
+
71
+ #max_connections = 100
72
+ #table_cache = 64
73
+ #thread_concurrency = 10
74
+ #
75
+ # * Query Cache Configuration
76
+ #
77
+ query_cache_limit = 1M
78
+ query_cache_size = 16M
79
+ #
80
+ # * Logging and Replication
81
+ #
82
+ # Both location gets rotated by the cronjob.
83
+ # Be aware that this log type is a performance killer.
84
+ #log = /var/log/mysql/mysql.log
85
+ #
86
+ # Error logging goes to syslog. This is a Debian improvement :)
87
+ #
88
+ # Here you can see queries with especially long duration
89
+ log_slow_queries = /var/log/mysql/mysql-slow.log
90
+ long_query_time = 2
91
+ log-queries-not-using-indexes
92
+ #
93
+ # The following can be used as easy to replay backup logs or for replication.
94
+ # note: if you are setting up a replication slave, see README.Debian about
95
+ # other settings you may need to change.
96
+ server-id = <%= server_id %>
97
+ log_bin = <%= log_dir %>/mysql-bin.log
98
+ relay_log = <%= log_dir %>/mysql-relay-bin.log
99
+
100
+ # WARNING: Using expire_logs_days without bin_log crashes the server! See README.Debian!
101
+ expire_logs_days = 10
102
+ max_binlog_size = 100M
103
+ #binlog_do_db = include_database_name
104
+ #binlog_ignore_db = include_database_name
105
+ #
106
+ # * BerkeleyDB
107
+ #
108
+ # Using BerkeleyDB is now discouraged as its support will cease in 5.1.12.
109
+ skip-bdb
110
+ #
111
+ # * InnoDB
112
+ #
113
+ # InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
114
+ # Read the manual for more InnoDB related options. There are many!
115
+ # You might want to disable InnoDB to shrink the mysqld process by circa 100MB.
116
+ #skip-innodb
117
+
118
+ # Set buffer pool size to 50-80% of your computer's memory
119
+ #innodb_buffer_pool_size=512M
120
+ #innodb_additional_mem_pool_size=64M
121
+
122
+ # Set the log file size to about 25% of the buffer pool size
123
+ #innodb_log_file_size=128M
124
+ #innodb_log_buffer_size=32M
125
+ #innodb_flush_log_at_trx_commit=2
126
+
127
+ #
128
+ # * Security Features
129
+ #
130
+ # Read the manual, too, if you want chroot!
131
+ # chroot = /var/lib/mysql/
132
+ #
133
+ # For generating SSL certificates I recommend the OpenSSL GUI "tinyca".
134
+ #
135
+ # ssl-ca=/etc/mysql/cacert.pem
136
+ # ssl-cert=/etc/mysql/server-cert.pem
137
+ # ssl-key=/etc/mysql/server-key.pem
138
+
139
+
140
+
141
+ [mysqldump]
142
+ quick
143
+ quote-names
144
+ max_allowed_packet = 16M
145
+
146
+ [mysql]
147
+ #no-auto-rehash # faster start of mysql but no tab completition
148
+
149
+ [isamchk]
150
+ key_buffer = 16M
151
+
152
+ #
153
+ # * NDB Cluster
154
+ #
155
+ # See /usr/share/doc/mysql-server-*/README.Debian for more information.
156
+ #
157
+ # The following configuration is read by the NDB Data Nodes (ndbd processes)
158
+ # not from the NDB Management Nodes (ndb_mgmd processes).
159
+ #
160
+ # [MYSQL_CLUSTER]
161
+ # ndb-connectstring=127.0.0.1
162
+
163
+
164
+ #
165
+ # * IMPORTANT: Additional settings that can override those from this file!
166
+ #
167
+ !includedir /etc/mysql/conf.d/
@@ -0,0 +1,51 @@
1
+ <%
2
+ @path = "/etc/munin/plugins/mysql_slave"
3
+ @perms = 0755
4
+ %>#!/bin/sh
5
+ #
6
+ # Plugin to monitor the slave delay
7
+ #
8
+ # Parameters:
9
+ #
10
+ # config
11
+ # autoconf
12
+ #
13
+ # Configuration variables
14
+ #
15
+ # mysqlopts - Options to pass to mysql
16
+ #
17
+ #%# family=auto
18
+ #%# capabilities=autoconf
19
+
20
+ MYSQLOPTS="$mysqlopts"
21
+ MYSQLADMIN=${mysqladmin:-mysqladmin}
22
+
23
+ if [ "$1" = "autoconf" ]; then
24
+ $MYSQLADMIN --version 2>/dev/null >/dev/null
25
+ if [ $? -eq 0 ]
26
+ then
27
+ $MYSQLADMIN $MYSQLOPTS status 2>/dev/null >/dev/null
28
+ if [ $? -eq 0 ]
29
+ then
30
+ echo yes
31
+ exit 0
32
+ else
33
+ echo "no (could not connect to mysql)"
34
+ fi
35
+ else
36
+ echo "no (mysqladmin not found)"
37
+ fi
38
+ exit 1
39
+ fi
40
+
41
+ if [ "$1" = "config" ]; then
42
+ echo 'graph_title MySQL Slave Delay'
43
+ echo 'graph_vlabel seconds'
44
+ echo 'graph_category mysql'
45
+ echo 'slave.label slave delay'
46
+ echo 'graph_args --base 1000'
47
+ exit 0
48
+ fi
49
+
50
+ /usr/bin/printf "slave.value "
51
+ echo "show slave status\G"| mysql $MYSQLOPTS | grep "Seconds_Behind_Master" | awk '{print $2}'
@@ -0,0 +1,38 @@
1
+
2
+ # REQUIRED: The credentials for creating/accessong your app's database
3
+ #
4
+ db_user: "#{app_name[0,16]}"
5
+ db_pass:
6
+ db_name: "#{app_name}_#{RUBBER_ENV}"
7
+
8
+ db_slave_user: "#{('slave_' + db_user)[0,16]}"
9
+ db_replicator_user: "#{('replicator_' + db_user)[0,16]}"
10
+
11
+ # REQUIRED: The command to use to do a full backup of your database using
12
+ # "rake rubber:backup_db"
13
+ db_backup_cmd: "nice mysqldump -h %host% -u %user% --password=%pass% %name% | gzip -c > %backup_file%"
14
+ # REQUIRED: The command to use to restore the database using
15
+ # "rake rubber:restore_db_s3"
16
+ # This command will receive the data generated by db_backup_cmd via
17
+ # its standard input
18
+ db_restore_cmd: "zcat - | mysql -h %host% -u %user% --password=%pass% %name%"
19
+
20
+ # REQUIRED: The directory to store the db data in
21
+ #
22
+ db_root_dir: /mnt/mysql
23
+ db_data_dir: "#{db_root_dir}/data"
24
+ db_log_dir: "#{db_root_dir}/log"
25
+
26
+ packages: [mysql-client, libmysql-ruby]
27
+
28
+ roles:
29
+ mysql_master:
30
+ db_server_id: 1
31
+ mysql_slave:
32
+ db_server_id: 2
33
+ db:
34
+ packages: [
35
+ mysql-server,
36
+ maatkit, # useful mysql tools for replication
37
+ libdbi-perl, libdbd-mysql, libcache-cache-perl # for extended munin plugins
38
+ ]
@@ -0,0 +1 @@
1
+ description: The mysql module
@@ -0,0 +1,13 @@
1
+ <%
2
+ @path = "#{RUBBER_ROOT}/config/initializers/mysql_cluster_migrations.rb"
3
+ %>
4
+
5
+ # mysql adapter in rails hardcodes engine to be innodb, so if we want all
6
+ # rails tables to be clustered, we need to override this behavior
7
+ #
8
+ class ActiveRecord::ConnectionAdapters::MysqlAdapter
9
+ def create_table(table_name, options = {}) #:nodoc:
10
+ super(table_name, options.reverse_merge(:options => "ENGINE=ndbcluster"))
11
+ end
12
+ end
13
+
@@ -0,0 +1,173 @@
1
+
2
+ namespace :rubber do
3
+
4
+ namespace :mysql_cluster do
5
+
6
+ rubber.allow_optional_tasks(self)
7
+
8
+ after "rubber:create", "rubber:mysql_cluster:set_db_role"
9
+
10
+ # Capistrano needs db:primary role for migrate to work
11
+ task :set_db_role do
12
+ sql_instances = rubber_cfg.instance.for_role("mysql_sql")
13
+ sql_instances.each do |instance|
14
+ if ! instance.role_names.find {|n| n == 'db'}
15
+ role = Rubber::Configuration::RoleItem.new('db')
16
+ primary_exists = rubber_cfg.instance.for_role("db", "primary" => true).size > 0
17
+ role.options["primary"] = true unless primary_exists
18
+ instance.roles << role
19
+ end
20
+ end
21
+ rubber_cfg.instance.save()
22
+ load_roles() unless rubber_cfg.environment.bind().disable_auto_roles
23
+ end
24
+
25
+ before "rubber:install_packages", "rubber:mysql_cluster:install"
26
+
27
+ task :install, :roles => [:mysql_mgm, :mysql_data, :mysql_sql] do
28
+ # Setup apt sources to get a newer version of mysql cluster
29
+ # https://launchpad.net/~mysql-cge-testing/+archive
30
+ #
31
+
32
+ sources = <<-SOURCES
33
+ # for mysql cluster 6.2
34
+ # deb http://ppa.launchpad.net/mysql-cge-testing/ubuntu hardy main
35
+ # deb-src http://ppa.launchpad.net/mysql-cge-testing/ubuntu hardy main
36
+
37
+ # for mysql cluster 6.3
38
+ deb http://ppa.launchpad.net/ndb-bindings/ubuntu hardy main
39
+ deb-src http://ppa.launchpad.net/ndb-bindings/ubuntu hardy main
40
+ SOURCES
41
+ sources.gsub!(/^ */, '')
42
+ put(sources, "/etc/apt/sources.list.d/mysql_cluster.list")
43
+ end
44
+
45
+ after "rubber:bootstrap", "rubber:mysql_cluster:bootstrap"
46
+
47
+ task :bootstrap, :roles => [:mysql_mgm, :mysql_data, :mysql_sql] do
48
+ # mysql package install starts mysql, so stop it
49
+ sudo "/etc/init.d/mysql stop" rescue nil
50
+
51
+ # After everything installed on machines, we need the source tree
52
+ # on hosts in order to run rubber:config for bootstrapping the db
53
+ deploy.setup
54
+ deploy.update_code
55
+
56
+ # Conditionaly bootstrap for each node/role only if that node has not
57
+ # been boostrapped for that role before
58
+
59
+ rubber_cfg.instance.for_role("mysql_mgm").each do |ic|
60
+ task_name = "_bootstrap_mysql_mgm_#{ic.full_name}".to_sym()
61
+ task task_name, :hosts => ic.full_name do
62
+ exists = capture("if grep -c rubber.*mysql_mgm /etc/mysql/ndb_mgmd.cnf &> /dev/null; then echo exists; fi")
63
+ if exists.strip.size == 0
64
+ rubber.run_config(:RUBBER_ENV => rails_env, :FILE => "role/mysql_mgm", :deploy_path => release_path)
65
+ sudo "/etc/init.d/mysql-ndb-mgm start"
66
+ end
67
+ end
68
+ send task_name
69
+ end
70
+
71
+ rubber_cfg.instance.for_role("mysql_data").each do |ic|
72
+ task_name = "_bootstrap_mysql_data_#{ic.full_name}".to_sym()
73
+ task task_name, :hosts => ic.full_name do
74
+ exists = capture("if grep -c rubber.*mysql_data /etc/mysql/my.cnf &> /dev/null; then echo exists; fi")
75
+ if exists.strip.size == 0
76
+ rubber.run_config(:RUBBER_ENV => rails_env, :FILE => "role/mysql_data", :deploy_path => release_path)
77
+ sudo "/etc/init.d/mysql-ndb start-initial"
78
+ end
79
+ end
80
+ send task_name
81
+ end
82
+
83
+ rubber_cfg.instance.for_role("mysql_sql").each do |ic|
84
+ task_name = "_bootstrap_mysql_sql_#{ic.full_name}".to_sym()
85
+ task task_name, :hosts => ic.full_name do
86
+ exists = capture("if grep -c rubber.*mysql_sql /etc/mysql/my.cnf &> /dev/null; then echo exists; fi")
87
+ if exists.strip.size == 0
88
+ rubber.run_config(:RUBBER_ENV => rails_env, :FILE => "role/mysql_sql", :deploy_path => release_path)
89
+ sudo "/etc/init.d/mysql start"
90
+ env = rubber_cfg.environment.bind()
91
+ # For mysql 5.0 cluster, need to create users and database for EVERY sql node
92
+ pass = "identified by '#{env.db_pass}'" if env.db_pass
93
+ sudo "mysql -u root -e 'create database #{env.db_name};'"
94
+ sudo "mysql -u root -e \"grant all on #{env.db_name}.* to '#{env.db_user}'@'%' #{pass};\""
95
+ sudo "mysql -u root -e \"update user set Super_priv = 'N' where user = '#{env.db_user}';\" mysql"
96
+ end
97
+ end
98
+ send task_name
99
+ end
100
+
101
+ end
102
+
103
+ desc <<-DESC
104
+ Starts the mysql cluster management daemon on the management node
105
+ DESC
106
+ task :start_mgm, :roles => :mysql_mgm do
107
+ sudo "/etc/init.d/mysql-ndb-mgm start"
108
+ end
109
+
110
+ desc <<-DESC
111
+ Starts the mysql cluster storage daemon on the data nodes
112
+ DESC
113
+ task :start_data, :roles => :mysql_data do
114
+ sudo "/etc/init.d/mysql-ndb start"
115
+ end
116
+
117
+ desc <<-DESC
118
+ Starts the mysql cluster sql daemon on the sql nodes
119
+ DESC
120
+ task :start_sql, :roles => :mysql_sql do
121
+ sudo "/etc/init.d/mysql start"
122
+ end
123
+
124
+ desc <<-DESC
125
+ Stops the mysql cluster management daemon on the management node
126
+ DESC
127
+ task :stop_mgm, :roles => :mysql_mgm do
128
+ sudo "/etc/init.d/mysql-ndb-mgm stop"
129
+ end
130
+
131
+ desc <<-DESC
132
+ Stops the mysql cluster storage daemon on the data nodes
133
+ DESC
134
+ task :stop_data, :roles => :mysql_data do
135
+ sudo "/etc/init.d/mysql-ndb stop"
136
+ end
137
+
138
+ desc <<-DESC
139
+ Stops the mysql cluster sql daemon on the sql nodes
140
+ DESC
141
+ task :stop_sql, :roles => :mysql_sql do
142
+ sudo "/etc/init.d/mysql stop"
143
+ end
144
+
145
+ desc <<-DESC
146
+ Stops all the mysql cluster daemons
147
+ DESC
148
+ task :stop do
149
+ stop_sql
150
+ stop_data
151
+ stop_mgm
152
+ end
153
+
154
+ desc <<-DESC
155
+ Starts all the mysql cluster daemons
156
+ DESC
157
+ task :start do
158
+ start_mgm
159
+ start_data
160
+ start_sql
161
+ end
162
+
163
+ desc <<-DESC
164
+ Restarts all the mysql cluster daemons
165
+ DESC
166
+ task :restart do
167
+ stop
168
+ start
169
+ end
170
+
171
+ end
172
+
173
+ end