bitgirder-platform 0.1.7
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/LICENSE.txt +176 -0
- data/bin/ensure-test-db +117 -0
- data/bin/install-mysql +375 -0
- data/bin/tomcat7 +569 -0
- data/lib/bitgirder/concurrent.rb +400 -0
- data/lib/bitgirder/core.rb +1235 -0
- data/lib/bitgirder/etl.rb +58 -0
- data/lib/bitgirder/event/file.rb +485 -0
- data/lib/bitgirder/event/logger/testing.rb +140 -0
- data/lib/bitgirder/event/logger.rb +137 -0
- data/lib/bitgirder/event/testing.rb +88 -0
- data/lib/bitgirder/http.rb +255 -0
- data/lib/bitgirder/io/testing.rb +33 -0
- data/lib/bitgirder/io.rb +959 -0
- data/lib/bitgirder/irb.rb +35 -0
- data/lib/bitgirder/mysql.rb +60 -0
- data/lib/bitgirder/ops/java.rb +117 -0
- data/lib/bitgirder/ops/ruby.rb +235 -0
- data/lib/bitgirder/testing.rb +152 -0
- data/lib/doc-gen0.rb +0 -0
- data/lib/doc-gen1.rb +0 -0
- data/lib/doc-gen10.rb +0 -0
- data/lib/doc-gen11.rb +0 -0
- data/lib/doc-gen12.rb +0 -0
- data/lib/doc-gen13.rb +0 -0
- data/lib/doc-gen14.rb +0 -0
- data/lib/doc-gen15.rb +0 -0
- data/lib/doc-gen16.rb +0 -0
- data/lib/doc-gen17.rb +14 -0
- data/lib/doc-gen18.rb +0 -0
- data/lib/doc-gen19.rb +0 -0
- data/lib/doc-gen2.rb +0 -0
- data/lib/doc-gen20.rb +182 -0
- data/lib/doc-gen21.rb +0 -0
- data/lib/doc-gen3.rb +0 -0
- data/lib/doc-gen4.rb +0 -0
- data/lib/doc-gen5.rb +0 -0
- data/lib/doc-gen6.rb +0 -0
- data/lib/doc-gen7.rb +0 -0
- data/lib/doc-gen8.rb +0 -0
- data/lib/doc-gen9.rb +0 -0
- data/lib/mingle/bincodec.rb +512 -0
- data/lib/mingle/codec.rb +54 -0
- data/lib/mingle/http.rb +156 -0
- data/lib/mingle/io/stream.rb +142 -0
- data/lib/mingle/io.rb +160 -0
- data/lib/mingle/json.rb +257 -0
- data/lib/mingle/service.rb +110 -0
- data/lib/mingle-em.rb +92 -0
- data/lib/mingle.rb +2917 -0
- metadata +100 -0
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
data/bin/ensure-test-db
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'bitgirder/core'
|
|
4
|
+
include BitGirder::Core
|
|
5
|
+
|
|
6
|
+
require 'bitgirder/mysql'
|
|
7
|
+
|
|
8
|
+
module BitGirder
|
|
9
|
+
module MySql
|
|
10
|
+
|
|
11
|
+
class App < BitGirderClass
|
|
12
|
+
|
|
13
|
+
class TestUser < BitGirderClass
|
|
14
|
+
|
|
15
|
+
bg_attr :user
|
|
16
|
+
bg_attr :pass
|
|
17
|
+
|
|
18
|
+
def self.parse( str )
|
|
19
|
+
|
|
20
|
+
if /^(?<user>[^:]+):(?<pass>.+)$/ =~ str
|
|
21
|
+
TestUser.new( user: user, pass: pass )
|
|
22
|
+
else
|
|
23
|
+
raise "Invalid user:pass string: #{str}"
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
bg_attr :connect_user
|
|
29
|
+
bg_attr :connect_pass
|
|
30
|
+
bg_attr :connect_socket, validation: :file_exists
|
|
31
|
+
|
|
32
|
+
bg_attr :db
|
|
33
|
+
|
|
34
|
+
bg_attr :user,
|
|
35
|
+
is_list: true,
|
|
36
|
+
processor: lambda { |elt| TestUser.parse( elt ) }
|
|
37
|
+
|
|
38
|
+
private
|
|
39
|
+
def get_connect_opts
|
|
40
|
+
|
|
41
|
+
{
|
|
42
|
+
user: connect_user(),
|
|
43
|
+
password: connect_pass(),
|
|
44
|
+
socket: connect_socket(),
|
|
45
|
+
db: "mysql"
|
|
46
|
+
}
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
private
|
|
50
|
+
def create_db( db )
|
|
51
|
+
|
|
52
|
+
db.query( <<-SQL
|
|
53
|
+
create database if not exists #{db.escape_string( db() )}
|
|
54
|
+
default character set = utf8
|
|
55
|
+
SQL
|
|
56
|
+
)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# Returns quoted [ user, host ] strings as side effect
|
|
60
|
+
private
|
|
61
|
+
def ensure_account( db, tu, host )
|
|
62
|
+
|
|
63
|
+
usr_nm = db.escape_string( tu.user )
|
|
64
|
+
ps_str = db.escape_string( tu.pass )
|
|
65
|
+
host_nm = db.escape_string( host )
|
|
66
|
+
|
|
67
|
+
has_user_sql = <<-SQL
|
|
68
|
+
select user from user
|
|
69
|
+
where user = '#{usr_nm}' and host = '#{host_nm}'
|
|
70
|
+
SQL
|
|
71
|
+
|
|
72
|
+
has_user = db.query( has_user_sql ).size == 1
|
|
73
|
+
|
|
74
|
+
create_user_sql =
|
|
75
|
+
"create user '#{usr_nm}'@'#{host_nm}' identified by '#{ps_str}'"
|
|
76
|
+
|
|
77
|
+
db.query( create_user_sql ) unless has_user
|
|
78
|
+
|
|
79
|
+
[ usr_nm, host_nm ]
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
private
|
|
83
|
+
def init_user( db, tu, host )
|
|
84
|
+
|
|
85
|
+
usr_nm, host_nm = ensure_account( db, tu, host )
|
|
86
|
+
db_nm = db.escape_string( db() )
|
|
87
|
+
|
|
88
|
+
db.query( "grant all on `#{db_nm}`.* to '#{usr_nm}'@'#{host_nm}'" )
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
private
|
|
92
|
+
def init_users( db )
|
|
93
|
+
|
|
94
|
+
@user.each do |tu|
|
|
95
|
+
%w{ localhost 127.0.0.1 ::1 }.each do |host|
|
|
96
|
+
init_user( db, tu, host )
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
public
|
|
102
|
+
def run( run_ctx )
|
|
103
|
+
|
|
104
|
+
MySql.open( get_connect_opts ) do |db|
|
|
105
|
+
|
|
106
|
+
create_db( db )
|
|
107
|
+
init_users( db )
|
|
108
|
+
MySql.flush_privileges( db )
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
BitGirderCliApplication.run( App )
|
|
115
|
+
|
|
116
|
+
end
|
|
117
|
+
end
|
data/bin/install-mysql
ADDED
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'bitgirder/core'
|
|
4
|
+
include BitGirder::Core
|
|
5
|
+
|
|
6
|
+
require 'bitgirder/io'
|
|
7
|
+
|
|
8
|
+
require 'bitgirder/mysql'
|
|
9
|
+
|
|
10
|
+
module BitGirder
|
|
11
|
+
module MySql
|
|
12
|
+
|
|
13
|
+
class App < BitGirderClass
|
|
14
|
+
|
|
15
|
+
LOCALHOST = "127.0.0.1"
|
|
16
|
+
|
|
17
|
+
require 'erb'
|
|
18
|
+
require 'socket'
|
|
19
|
+
|
|
20
|
+
include BitGirder::Io
|
|
21
|
+
|
|
22
|
+
bg_attr :mysql_distro, validation: :file_exists
|
|
23
|
+
|
|
24
|
+
bg_attr :install_to
|
|
25
|
+
|
|
26
|
+
bg_attr :wipe_install_dir, processor: :boolean, default: false
|
|
27
|
+
bg_attr :skip_install, processor: :boolean, default: false
|
|
28
|
+
bg_attr :skip_init_db, processor: :boolean, default: false
|
|
29
|
+
|
|
30
|
+
bg_attr :port, processor: :integer, validation: :positive
|
|
31
|
+
|
|
32
|
+
bg_attr :root_pass
|
|
33
|
+
bg_attr :root_user, default: "root"
|
|
34
|
+
|
|
35
|
+
private
|
|
36
|
+
def sock_file
|
|
37
|
+
"#@install_to/mysql.sock"
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
private
|
|
41
|
+
def my_cnf
|
|
42
|
+
"#@install_to/my.cnf"
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
private
|
|
46
|
+
def base_dir
|
|
47
|
+
@mysql_distro
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
private
|
|
51
|
+
def data_dir
|
|
52
|
+
"#@install_to/data"
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
private
|
|
56
|
+
def log_dir
|
|
57
|
+
"#@install_to/log"
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
private
|
|
61
|
+
def mysql_binary( f )
|
|
62
|
+
file_exists( "#{base_dir()}/bin/#{f}" )
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
private
|
|
66
|
+
def mysqladmin
|
|
67
|
+
mysql_binary( "mysqladmin" )
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
private
|
|
71
|
+
def mysqld
|
|
72
|
+
mysql_binary( "mysqld" )
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
private
|
|
76
|
+
def mysql
|
|
77
|
+
mysql_binary( "mysql" )
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
private
|
|
81
|
+
def bash
|
|
82
|
+
which( "bash" ) or raise "Can't find: bash"
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
private
|
|
86
|
+
def do_wipe_install
|
|
87
|
+
|
|
88
|
+
if File.exist?( f = sock_file() )
|
|
89
|
+
raise "Socket #{f} exists; will not wipe installation"
|
|
90
|
+
else
|
|
91
|
+
fu().rm_rf( install_to() )
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
private
|
|
96
|
+
def init_install_to
|
|
97
|
+
|
|
98
|
+
if File.exist?( @install_to )
|
|
99
|
+
|
|
100
|
+
if @wipe_install_dir
|
|
101
|
+
do_wipe_install
|
|
102
|
+
else
|
|
103
|
+
raise "#@install_to already exists"
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
private
|
|
109
|
+
def write_my_cnf
|
|
110
|
+
|
|
111
|
+
File.open( cnf = ensure_parent( my_cnf() ), "w" ) do |io|
|
|
112
|
+
|
|
113
|
+
code( "Writing conf file #{cnf}" )
|
|
114
|
+
io.print ERB.new( MY_CNF_TEMPLATE ).result( binding )
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
private
|
|
119
|
+
def ensure_dirs
|
|
120
|
+
[ data_dir(), log_dir() ].each { |d| fu().mkdir_p( d ) }
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
private
|
|
124
|
+
def run_install_script( verbose )
|
|
125
|
+
|
|
126
|
+
cmd = file_exists( "#{base_dir()}/scripts/mysql_install_db" )
|
|
127
|
+
|
|
128
|
+
argv = [ "--basedir=#{base_dir()}",
|
|
129
|
+
"--datadir=#{data_dir()}",
|
|
130
|
+
"--defaults-file=#{my_cnf()}",
|
|
131
|
+
"--skip-name-resolve" ]
|
|
132
|
+
|
|
133
|
+
argv << "--verbose" if verbose
|
|
134
|
+
|
|
135
|
+
UnixProcessBuilder.new( cmd: cmd, argv: argv ).system
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
private
|
|
139
|
+
def install_db( run_ctx )
|
|
140
|
+
|
|
141
|
+
init_install_to
|
|
142
|
+
write_my_cnf
|
|
143
|
+
ensure_dirs
|
|
144
|
+
run_install_script( run_ctx[ :verbose ] )
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
private
|
|
148
|
+
def start_db
|
|
149
|
+
|
|
150
|
+
argv = [ "--defaults-file=#{my_cnf()}" ]
|
|
151
|
+
|
|
152
|
+
UnixProcessBuilder.new( cmd: mysqld(), argv: argv ).spawn
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
private
|
|
156
|
+
def await_sock( tries_remain = 3, stall = 2 )
|
|
157
|
+
|
|
158
|
+
code( "Attempting connect to #@port" )
|
|
159
|
+
|
|
160
|
+
begin
|
|
161
|
+
TCPSocket.new( LOCALHOST, @port ).close
|
|
162
|
+
code( "Connected" )
|
|
163
|
+
|
|
164
|
+
rescue Errno::ECONNREFUSED => e
|
|
165
|
+
|
|
166
|
+
if tries_remain > 0
|
|
167
|
+
|
|
168
|
+
code( "No connection, will retry in #{stall}s" )
|
|
169
|
+
sleep( stall )
|
|
170
|
+
await_sock( tries_remain - 1, stall * 2 )
|
|
171
|
+
else
|
|
172
|
+
raise "Could not connect to #@port"
|
|
173
|
+
end
|
|
174
|
+
end
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
private
|
|
178
|
+
def update_root_accounts( db )
|
|
179
|
+
|
|
180
|
+
sql = <<-SQL
|
|
181
|
+
update mysql.user
|
|
182
|
+
set password = password( '#{db.escape_string( root_pass() )}' )
|
|
183
|
+
where user = 'root'
|
|
184
|
+
SQL
|
|
185
|
+
|
|
186
|
+
db.query( sql )
|
|
187
|
+
db.query( "flush privileges" )
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
private
|
|
191
|
+
def set_root_pass( opts )
|
|
192
|
+
MySql.open( opts ) { |db| update_root_accounts( db ) }
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
private
|
|
196
|
+
def remove_anon_accounts( db )
|
|
197
|
+
db.query( "delete from mysql.user where user = '' or user is null" )
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
private
|
|
201
|
+
def remove_test_db( db )
|
|
202
|
+
|
|
203
|
+
db.query( "delete from mysql.db where db like 'test%'" )
|
|
204
|
+
db.query( "drop database test" )
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
private
|
|
208
|
+
def secure_db_install( opts )
|
|
209
|
+
|
|
210
|
+
MySql.open( opts ) do |db|
|
|
211
|
+
|
|
212
|
+
remove_anon_accounts( db )
|
|
213
|
+
remove_test_db( db )
|
|
214
|
+
|
|
215
|
+
db.query( "flush privileges" )
|
|
216
|
+
end
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
private
|
|
220
|
+
def run_db_init
|
|
221
|
+
|
|
222
|
+
# Initially we have an empty pass
|
|
223
|
+
opts = { user: "root", socket: sock_file(), db: "mysql" }
|
|
224
|
+
set_root_pass( opts )
|
|
225
|
+
|
|
226
|
+
# Now re-connect with pass (to verify that previous step worked)
|
|
227
|
+
opts.merge!( password: root_pass() )
|
|
228
|
+
secure_db_install( opts )
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
private
|
|
232
|
+
def stop_db( pid, with_pass )
|
|
233
|
+
|
|
234
|
+
argv = [ "--defaults-file=#{my_cnf()}", "-u", "root" ]
|
|
235
|
+
argv << "--password=#{root_pass()}" if with_pass
|
|
236
|
+
argv << "shutdown"
|
|
237
|
+
|
|
238
|
+
UnixProcessBuilder.new( cmd: mysqladmin(), argv: argv ).system
|
|
239
|
+
|
|
240
|
+
debug_wait2( name: "mysqld", pid: pid )
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
private
|
|
244
|
+
def init_db
|
|
245
|
+
|
|
246
|
+
init_done = false
|
|
247
|
+
pid = start_db
|
|
248
|
+
code( "Started mysqld as #{pid}" )
|
|
249
|
+
|
|
250
|
+
begin
|
|
251
|
+
await_sock
|
|
252
|
+
run_db_init
|
|
253
|
+
init_done = true
|
|
254
|
+
ensure
|
|
255
|
+
stop_db( pid, init_done )
|
|
256
|
+
end
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
private
|
|
260
|
+
def write_script( f )
|
|
261
|
+
|
|
262
|
+
script = ensure_parent( "#{install_to()}/#{f}" )
|
|
263
|
+
code( "Writing #{script}" )
|
|
264
|
+
|
|
265
|
+
File.open( script, "w" ) do |io|
|
|
266
|
+
|
|
267
|
+
io.chmod( 0755 )
|
|
268
|
+
yield( io )
|
|
269
|
+
end
|
|
270
|
+
end
|
|
271
|
+
|
|
272
|
+
private
|
|
273
|
+
def write_start_db_wrapper
|
|
274
|
+
|
|
275
|
+
mysqld = file_exists( "#{base_dir()}/bin/mysqld" )
|
|
276
|
+
mysqld_out = "#{log_dir()}/mysqld.out"
|
|
277
|
+
|
|
278
|
+
write_script( "bin/start-db" ) do |io|
|
|
279
|
+
|
|
280
|
+
io.print <<-END
|
|
281
|
+
#!#{bash()}
|
|
282
|
+
|
|
283
|
+
( ( ( exec #{mysqld} --defaults-file=#{my_cnf()} ) 2>&1 ) >> #{mysqld_out} ) &
|
|
284
|
+
END
|
|
285
|
+
end
|
|
286
|
+
end
|
|
287
|
+
|
|
288
|
+
private
|
|
289
|
+
def write_mysqladmin_wrapper
|
|
290
|
+
|
|
291
|
+
write_script( "bin/mysqladmin" ) do |io|
|
|
292
|
+
|
|
293
|
+
io.print <<-END
|
|
294
|
+
#!#{bash()}
|
|
295
|
+
|
|
296
|
+
exec #{mysqladmin()} --defaults-file=#{my_cnf()} -u #{root_user()} "$@"
|
|
297
|
+
END
|
|
298
|
+
end
|
|
299
|
+
end
|
|
300
|
+
|
|
301
|
+
private
|
|
302
|
+
def write_mysql_wrapper
|
|
303
|
+
|
|
304
|
+
write_script( "bin/mysql" ) do |io|
|
|
305
|
+
|
|
306
|
+
io.print <<-END
|
|
307
|
+
#!#{bash()}
|
|
308
|
+
|
|
309
|
+
exec #{mysql()} --defaults-file=#{my_cnf()} "$@"
|
|
310
|
+
END
|
|
311
|
+
end
|
|
312
|
+
end
|
|
313
|
+
|
|
314
|
+
private
|
|
315
|
+
def write_script_wrappers
|
|
316
|
+
|
|
317
|
+
write_start_db_wrapper
|
|
318
|
+
write_mysqladmin_wrapper
|
|
319
|
+
write_mysql_wrapper
|
|
320
|
+
end
|
|
321
|
+
|
|
322
|
+
def run( run_ctx )
|
|
323
|
+
|
|
324
|
+
install_db( run_ctx ) unless @skip_install
|
|
325
|
+
init_db unless @skip_init_db
|
|
326
|
+
write_script_wrappers
|
|
327
|
+
end
|
|
328
|
+
|
|
329
|
+
MY_CNF_TEMPLATE = <<-END_CNF
|
|
330
|
+
[client]
|
|
331
|
+
port = <%= @port %>
|
|
332
|
+
socket = <%= sock_file() %>
|
|
333
|
+
|
|
334
|
+
[mysqld]
|
|
335
|
+
port = <%= @port %>
|
|
336
|
+
socket = <%= sock_file %>
|
|
337
|
+
skip-external-locking
|
|
338
|
+
key_buffer_size = 16M
|
|
339
|
+
max_allowed_packet = 1M
|
|
340
|
+
table_open_cache = 64
|
|
341
|
+
sort_buffer_size = 512K
|
|
342
|
+
net_buffer_length = 8K
|
|
343
|
+
read_buffer_size = 256K
|
|
344
|
+
read_rnd_buffer_size = 512K
|
|
345
|
+
myisam_sort_buffer_size = 8M
|
|
346
|
+
|
|
347
|
+
log_error = <%= log_dir() %>/error.log
|
|
348
|
+
general_log_file = <%= log_dir() %>/general.log
|
|
349
|
+
general_log = 0
|
|
350
|
+
datadir = <%= data_dir() %>
|
|
351
|
+
basedir = <%= base_dir() %>
|
|
352
|
+
default_storage_engine = innodb
|
|
353
|
+
|
|
354
|
+
log-bin=mysql-bin
|
|
355
|
+
binlog_format=mixed
|
|
356
|
+
server-id = 1
|
|
357
|
+
|
|
358
|
+
[mysql]
|
|
359
|
+
no-auto-rehash
|
|
360
|
+
|
|
361
|
+
[myisamchk]
|
|
362
|
+
key_buffer_size = 20M
|
|
363
|
+
sort_buffer_size = 20M
|
|
364
|
+
read_buffer = 2M
|
|
365
|
+
write_buffer = 2M
|
|
366
|
+
|
|
367
|
+
[mysqlhotcopy]
|
|
368
|
+
interactive-timeout
|
|
369
|
+
END_CNF
|
|
370
|
+
end
|
|
371
|
+
|
|
372
|
+
BitGirder::Core::BitGirderCliApplication.run( App )
|
|
373
|
+
|
|
374
|
+
end
|
|
375
|
+
end
|