dolphin 0.1.2 → 0.1.3
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.
- checksums.yaml +4 -4
- data/README.md +15 -1
- data/lib/dolphin/base.rb +20 -1
- data/lib/dolphin/ubuntu/mongodb.rb +96 -0
- data/lib/dolphin/ubuntu/postgres.rb +160 -0
- data/lib/dolphin/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f9f3b9fb1215ac9b545eaa9867df9279430e6ca
|
4
|
+
data.tar.gz: 213425f42e5a6b40cf386cf1f160a85f2ddd3264
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ac99c14dc64a47fd0207cf19c8212ff1d592483dd5ec5ac85a4358f86d060bc86af015cb1d1134a027f5e10272aa5a70feb26b290a40409c695c6fdffed0dc8
|
7
|
+
data.tar.gz: 3f376724b4f8fc15e73e2f6d72dda1359a1596670dd92016f2b4cc7929f6129d527121d38c90f442d3d1732ed1d76ec2897febe40a1aec2a1c0f07eb52aa0211
|
data/README.md
CHANGED
@@ -253,7 +253,7 @@ Relevant settings in bin/dolphin are:
|
|
253
253
|
|
254
254
|
Sometimes we need to take some actions on only one specific group, which may contains arbitrary number of servers. Just pass the --group (or -g for short) option when issue command. Notice that in @group_hash, we difine a key-value pair for each group. So we only need to pass the key for that specific group as the -g option.
|
255
255
|
|
256
|
-
bin/dolphin
|
256
|
+
bin/dolphin mongo install -g mongo
|
257
257
|
|
258
258
|
Relevant settings in bin/dolphin are:
|
259
259
|
|
@@ -268,6 +268,11 @@ Relevant settings in bin/dolphin are:
|
|
268
268
|
@servers = @group_hash[options[:group].to_sym].map {|item| @server_hash[item]}
|
269
269
|
end
|
270
270
|
|
271
|
+
### Dry-run mode
|
272
|
+
Passing the --dry (or -d for short) option to enter dry-run mode.
|
273
|
+
|
274
|
+
bin/dolphin deploy go -d
|
275
|
+
|
271
276
|
## Extend with custom modules
|
272
277
|
|
273
278
|
To extend dolphin's functionality with your custom modules is easy. It is Ruby anyway. For example, to add Centos related functions:
|
@@ -306,6 +311,15 @@ To extend dolphin's functionality with your custom modules is easy. It is Ruby a
|
|
306
311
|
register(Dolphin::Centos, 'centos', 'centos', 'Adjust Centos config')
|
307
312
|
end
|
308
313
|
|
314
|
+
## Select Linux distribution specific modules
|
315
|
+
Dolphin contains some modules that are Linux distribution specific. For example, if you are using Ubuntu, you can include an Ubuntu specific module by adding the following to bin/dolphin:
|
316
|
+
|
317
|
+
require "dolphin/ubuntu/mongodb"
|
318
|
+
|
319
|
+
class Dolphin::CLI < Thor
|
320
|
+
register(Dolphin::Mongodb, 'mongodb', 'mongodb', 'MongoDB related tasks')
|
321
|
+
end
|
322
|
+
|
309
323
|
## Related gems
|
310
324
|
|
311
325
|
* [capistrano]
|
data/lib/dolphin/base.rb
CHANGED
@@ -18,6 +18,8 @@ class Dolphin::Base < Thor
|
|
18
18
|
class_option :group, aliases: '-g', type: :string, default: nil
|
19
19
|
# deploy to localhost
|
20
20
|
class_option :local, aliases: '-l', type: :boolean, default: false
|
21
|
+
# dry-run
|
22
|
+
class_option :dry, aliases: '-d', type: :boolean, default: false
|
21
23
|
|
22
24
|
def initialize(args=[], options={}, config={})
|
23
25
|
super(args, options, config)
|
@@ -65,6 +67,12 @@ class Dolphin::Base < Thor
|
|
65
67
|
end
|
66
68
|
|
67
69
|
def capture(command, server)
|
70
|
+
# dry-run
|
71
|
+
if options[:dry]
|
72
|
+
puts "Capture on #{server}: #{command}"
|
73
|
+
return '' # empty string for default unix return result
|
74
|
+
end
|
75
|
+
|
68
76
|
# capture output from one target server
|
69
77
|
output = ''
|
70
78
|
session = ssh_connection(server)
|
@@ -107,6 +115,13 @@ class Dolphin::Base < Thor
|
|
107
115
|
target = @servers
|
108
116
|
end
|
109
117
|
|
118
|
+
# dry-run
|
119
|
+
if options[:dry]
|
120
|
+
puts "Running on: #{target}"
|
121
|
+
puts "#{'='*60}\n"
|
122
|
+
return
|
123
|
+
end
|
124
|
+
|
110
125
|
# record output to display at the end
|
111
126
|
output = {}
|
112
127
|
|
@@ -186,7 +201,11 @@ class Dolphin::Base < Thor
|
|
186
201
|
Parallel.map(target, in_threads: tracks) do |server|
|
187
202
|
command = "scp #{source} #{@user}@#{server}:#{dest}"
|
188
203
|
puts command
|
189
|
-
|
204
|
+
|
205
|
+
# dry-run
|
206
|
+
unless options[:dry]
|
207
|
+
raise unless system(command, out: $stdout, err: :out)
|
208
|
+
end
|
190
209
|
end
|
191
210
|
end
|
192
211
|
|
@@ -0,0 +1,96 @@
|
|
1
|
+
# Mongodb related tasks
|
2
|
+
class Dolphin::Mongodb < Dolphin::Base
|
3
|
+
|
4
|
+
desc "install", "install mongodb"
|
5
|
+
def install
|
6
|
+
menu = [
|
7
|
+
"
|
8
|
+
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
|
9
|
+
sudo echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/10gen.list
|
10
|
+
sudo apt-get update
|
11
|
+
sudo apt-get -y install mongodb-10gen
|
12
|
+
",
|
13
|
+
]
|
14
|
+
|
15
|
+
execute menu
|
16
|
+
end
|
17
|
+
|
18
|
+
desc "disable", "disable mongodb"
|
19
|
+
def disable
|
20
|
+
menu = [
|
21
|
+
"
|
22
|
+
sudo stop mongodb
|
23
|
+
sudo sh -c 'echo manual > /etc/init/mongodb.override'
|
24
|
+
",
|
25
|
+
]
|
26
|
+
|
27
|
+
execute menu
|
28
|
+
end
|
29
|
+
|
30
|
+
desc "enable", "enable mongodb"
|
31
|
+
def enable
|
32
|
+
menu = [
|
33
|
+
"
|
34
|
+
sudo rm -f /etc/init/mongodb.override
|
35
|
+
sudo start mongodb
|
36
|
+
",
|
37
|
+
]
|
38
|
+
|
39
|
+
execute menu
|
40
|
+
end
|
41
|
+
|
42
|
+
desc "config", "config mongodb"
|
43
|
+
def config
|
44
|
+
# upload files
|
45
|
+
upload("#{@config_root}/mongo/*", "/tmp")
|
46
|
+
|
47
|
+
# allow access from peers
|
48
|
+
ufw = [
|
49
|
+
'# ufw',
|
50
|
+
'sudo ufw allow from 192.168.0.0/16 to any port 27017',
|
51
|
+
'sudo ufw allow from 192.168.0.0/16 to any port 28017',
|
52
|
+
]
|
53
|
+
@group_hash[:mg].each do |item|
|
54
|
+
ufw << "sudo ufw allow from #{@server_hash[item]}/32 to any port 27017"
|
55
|
+
ufw << "sudo ufw allow from #{@server_hash[item]}/32 to any port 28017"
|
56
|
+
end
|
57
|
+
ufw << "sudo ufw status numbered"
|
58
|
+
|
59
|
+
menu = [
|
60
|
+
ufw.join("\n"),
|
61
|
+
|
62
|
+
# config files
|
63
|
+
%{
|
64
|
+
sudo mv /tmp/mongodb.conf /etc/
|
65
|
+
sudo chown root:root /etc/mongodb.conf
|
66
|
+
sudo mv /tmp/keyfile.txt /etc/
|
67
|
+
sudo chown mongodb:mongodb /etc/keyfile.txt
|
68
|
+
sudo chmod go-r /etc/keyfile.txt
|
69
|
+
sudo restart mongodb
|
70
|
+
},
|
71
|
+
|
72
|
+
]
|
73
|
+
|
74
|
+
execute menu
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
desc "backup", "backup mongodb"
|
79
|
+
def backup
|
80
|
+
# upload files
|
81
|
+
upload("#{@config_root}/mongo/*", "/tmp")
|
82
|
+
|
83
|
+
menu = [
|
84
|
+
%{
|
85
|
+
mkdir -p ~/backups/mongodb
|
86
|
+
mv /tmp/mg* ~/backups/mongodb
|
87
|
+
# # add cron job to /var/spool/cron/crontabs/user
|
88
|
+
crontab /tmp/cron.txt
|
89
|
+
},
|
90
|
+
|
91
|
+
]
|
92
|
+
|
93
|
+
execute menu
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
@@ -0,0 +1,160 @@
|
|
1
|
+
# postgres related tasks
|
2
|
+
class Dolphin::Postgres < Dolphin::Base
|
3
|
+
|
4
|
+
desc "install", "install postgres"
|
5
|
+
def install
|
6
|
+
menu = [
|
7
|
+
%{
|
8
|
+
sudo echo 'deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main' | sudo tee /etc/apt/sources.list.d/pgdg.list
|
9
|
+
wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | sudo apt-key add -
|
10
|
+
sudo apt-get update
|
11
|
+
sudo apt-get -y install postgresql postgresql-contrib libpq-dev
|
12
|
+
},
|
13
|
+
|
14
|
+
]
|
15
|
+
|
16
|
+
execute menu
|
17
|
+
end
|
18
|
+
|
19
|
+
desc "disable", "disable postgresql"
|
20
|
+
def disable
|
21
|
+
menu = [
|
22
|
+
"
|
23
|
+
sudo service postgresql stop
|
24
|
+
sudo update-rc.d postgresql disable
|
25
|
+
",
|
26
|
+
]
|
27
|
+
|
28
|
+
execute menu
|
29
|
+
end
|
30
|
+
|
31
|
+
desc "enable", "enable postgresql"
|
32
|
+
def enable
|
33
|
+
menu = [
|
34
|
+
"
|
35
|
+
sudo update-rc.d postgresql enable
|
36
|
+
sudo service postgresql start
|
37
|
+
",
|
38
|
+
]
|
39
|
+
|
40
|
+
execute menu
|
41
|
+
end
|
42
|
+
|
43
|
+
desc "config", "config postgres"
|
44
|
+
def config
|
45
|
+
# upload files
|
46
|
+
upload("#{@config_root}/postgres/shared/*", "/tmp")
|
47
|
+
|
48
|
+
master = @server_hash[:pgm]
|
49
|
+
slave = @server_hash[:pgs]
|
50
|
+
menu = [
|
51
|
+
# set kernel sysctl
|
52
|
+
%{
|
53
|
+
cp /etc/sysctl.conf /tmp/
|
54
|
+
echo kernel.shmmax = 2147483648 >> /tmp/sysctl.conf
|
55
|
+
echo kernel.shmall = 2097152 >> /tmp/sysctl.conf
|
56
|
+
echo kernel.shmmni = 4096 >> /tmp/sysctl.conf
|
57
|
+
sudo mv /tmp/sysctl.conf /etc/
|
58
|
+
sudo sysctl -p
|
59
|
+
},
|
60
|
+
|
61
|
+
# conf
|
62
|
+
%{
|
63
|
+
sudo mv /tmp/postgresql.conf /etc/postgresql/9.2/main/
|
64
|
+
sudo chown postgres:postgres /etc/postgresql/9.2/main/postgresql.conf
|
65
|
+
},
|
66
|
+
|
67
|
+
# auth for replication
|
68
|
+
%{
|
69
|
+
echo hostssl replication replicator #{master}/32 trust >> /tmp/pg_hba.conf
|
70
|
+
echo hostssl replication replicator #{slave}/32 trust >> /tmp/pg_hba.conf
|
71
|
+
sudo mv /tmp/pg_hba.conf /etc/postgresql/9.2/main/
|
72
|
+
sudo chown postgres:postgres /etc/postgresql/9.2/main/pg_hba.conf
|
73
|
+
},
|
74
|
+
|
75
|
+
# firewall
|
76
|
+
%{
|
77
|
+
sudo ufw allow from 192.168.0.0/16 to any port 5432
|
78
|
+
# only for replicator
|
79
|
+
sudo ufw allow from #{master}/32 to any port 5432
|
80
|
+
sudo ufw allow from #{slave}/32 to any port 5432
|
81
|
+
},
|
82
|
+
]
|
83
|
+
|
84
|
+
execute menu
|
85
|
+
end
|
86
|
+
|
87
|
+
desc "master", "config pgmaster"
|
88
|
+
def master(user, password)
|
89
|
+
menu = [
|
90
|
+
%{
|
91
|
+
# plugin for pgadmin
|
92
|
+
sudo -u postgres psql -c 'CREATE EXTENSION adminpack;'
|
93
|
+
|
94
|
+
# create replicator user
|
95
|
+
sudo -u postgres psql -c "CREATE USER replicator REPLICATION LOGIN ENCRYPTED PASSWORD '#{password}';"
|
96
|
+
|
97
|
+
# create application user
|
98
|
+
sudo -u postgres psql -c "CREATE USER #{user} LOGIN ENCRYPTED PASSWORD '#{password}' NOSUPERUSER INHERIT CREATEDB CREATEROLE;"
|
99
|
+
|
100
|
+
sudo service postgresql restart
|
101
|
+
},
|
102
|
+
]
|
103
|
+
|
104
|
+
execute menu
|
105
|
+
end
|
106
|
+
|
107
|
+
desc "slave", "config pgslave"
|
108
|
+
def slave
|
109
|
+
# upload files
|
110
|
+
upload("#{@config_root}/postgres/slave/*", "/tmp")
|
111
|
+
|
112
|
+
master = @server_hash[:pgm]
|
113
|
+
menu = [
|
114
|
+
%{
|
115
|
+
sudo service postgresql stop
|
116
|
+
sudo -u postgres rm -rf /var/lib/postgresql/9.2/main
|
117
|
+
sudo -u postgres pg_basebackup -h #{master} -D /var/lib/postgresql/9.2/main -U replicator -v -P
|
118
|
+
|
119
|
+
sed -i 's/MASTER/#{master}/' /tmp/recovery.conf
|
120
|
+
sudo mv /tmp/recovery.conf /var/lib/postgresql/9.2/main/
|
121
|
+
sudo chown postgres:postgres /var/lib/postgresql/9.2/main/recovery.conf
|
122
|
+
|
123
|
+
sudo service postgresql start
|
124
|
+
|
125
|
+
},
|
126
|
+
]
|
127
|
+
|
128
|
+
execute menu
|
129
|
+
end
|
130
|
+
|
131
|
+
desc "createdb", "postgres createdb"
|
132
|
+
def createdb(dbname)
|
133
|
+
menu = [
|
134
|
+
%{
|
135
|
+
psql -d postgres -c 'CREATE DATABASE #{dbname}'
|
136
|
+
},
|
137
|
+
]
|
138
|
+
|
139
|
+
execute menu
|
140
|
+
end
|
141
|
+
|
142
|
+
desc "backup", "backup postgres"
|
143
|
+
def backup
|
144
|
+
# upload files
|
145
|
+
upload("#{@config_root}/postgres/slave/*", "/tmp")
|
146
|
+
|
147
|
+
menu = [
|
148
|
+
%{
|
149
|
+
mkdir -p ~/backups/postgresql
|
150
|
+
mv /tmp/pg_backup.* ~/backups/postgresql
|
151
|
+
# # add cron job to /var/spool/cron/crontabs/user
|
152
|
+
crontab /tmp/cron.txt
|
153
|
+
},
|
154
|
+
|
155
|
+
]
|
156
|
+
|
157
|
+
execute menu
|
158
|
+
end
|
159
|
+
|
160
|
+
end
|
data/lib/dolphin/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dolphin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Neng Xu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-10-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -102,6 +102,8 @@ files:
|
|
102
102
|
- lib/dolphin/nginx.rb
|
103
103
|
- lib/dolphin/puma.rb
|
104
104
|
- lib/dolphin/setup.rb
|
105
|
+
- lib/dolphin/ubuntu/mongodb.rb
|
106
|
+
- lib/dolphin/ubuntu/postgres.rb
|
105
107
|
- lib/dolphin/version.rb
|
106
108
|
- lib/generators/dolphin/install_generator.rb
|
107
109
|
- lib/generators/dolphin/puma_generator.rb
|