standup 0.3.9 → 0.3.10
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/VERSION +1 -1
- data/lib/standup/remoting.rb +5 -5
- data/scripts/basics.rb +3 -0
- data/scripts/db_backup.rb +2 -6
- data/scripts/download_db.rb +22 -11
- data/scripts/mysql.rb +40 -0
- data/scripts/passenger/nginx.conf +1 -1
- data/scripts/postgresql.rb +33 -3
- data/scripts/update.rb +2 -2
- data/scripts/upload_db.rb +2 -2
- data/scripts/webapp.rb +9 -8
- data/standup.gemspec +3 -2
- metadata +5 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.10
|
data/lib/standup/remoting.rb
CHANGED
@@ -92,9 +92,9 @@ module Standup
|
|
92
92
|
exec("if [ -e #{path} ]; then echo 'true'; fi") == "true\n"
|
93
93
|
end
|
94
94
|
|
95
|
-
def install_packages
|
96
|
-
|
97
|
-
sudo "apt-get -qqy install #{packages}"
|
95
|
+
def install_packages packages, opts = {}
|
96
|
+
input = opts[:input] ? "echo \"#{opts[:input].join("\n")}\" | sudo " : ''
|
97
|
+
sudo "#{input}apt-get -qqy install #{packages}"
|
98
98
|
end
|
99
99
|
alias :install_package :install_packages
|
100
100
|
|
@@ -112,12 +112,12 @@ module Standup
|
|
112
112
|
raise ArgumentError, ":section option is required" unless opts[:section]
|
113
113
|
user = opts[:user] || @node.scripts.ec2.params.ssh_user
|
114
114
|
commands = commands.strip.split("\n") if commands.is_a? String
|
115
|
-
commands = commands.map(&:strip).join(' && ')
|
115
|
+
commands = commands.map(&:strip).join(' && ').gsub(/%/, '\%')
|
116
116
|
|
117
117
|
in_temp_dir do |dir|
|
118
118
|
sudo "crontab -l -u #{user} > crontab.txt"
|
119
119
|
remote_update "#{dir}/crontab.txt",
|
120
|
-
"#{schedule} #{commands}
|
120
|
+
"#{schedule} (date && #{commands}) >> /var/log/cron.log 2>&1\n",
|
121
121
|
:delimiter => "# standup update_cron: #{opts[:section]}",
|
122
122
|
:sudo => true
|
123
123
|
sudo "crontab -u #{user} - < crontab.txt"
|
data/scripts/basics.rb
CHANGED
data/scripts/db_backup.rb
CHANGED
@@ -1,14 +1,10 @@
|
|
1
1
|
Standup.script :node do
|
2
|
-
self.description = 'Rails application database periodic backup to S3'
|
3
|
-
|
4
2
|
def run
|
5
3
|
exec "s3cmd mb #{bucket}"
|
6
4
|
|
7
5
|
update_cron '@hourly', <<-CMD, :section => name
|
8
|
-
|
9
|
-
|
10
|
-
sudo su -c "pg_dump -c #{scripts.webapp.db_name} | gzip > dump.gz" postgres
|
11
|
-
s3cmd put dump.gz #{path_prefix}/`date -u +%Y-%M-%d/%H_%m_%S`.gz
|
6
|
+
#{scripts.webapp.db.dump_command scripts.webapp.db_name, 'webapp', 'webapp'} | gzip > dump.gz
|
7
|
+
s3cmd put dump.gz #{path_prefix}/`date -u +%Y-%m-%d/%H-%M-%S`.gz
|
12
8
|
rm dump.gz
|
13
9
|
CMD
|
14
10
|
end
|
data/scripts/download_db.rb
CHANGED
@@ -3,29 +3,40 @@ Standup.script :node do
|
|
3
3
|
|
4
4
|
def run
|
5
5
|
in_temp_dir do |dir|
|
6
|
-
|
6
|
+
exec "#{scripts.webapp.db.dump_command scripts.webapp.db_name} > dump.sql"
|
7
7
|
local_exec "mkdir -p tmp/db"
|
8
8
|
download "#{dir}/dump.sql",
|
9
9
|
:to => 'tmp/db/dump.sql',
|
10
10
|
:sudo => true
|
11
11
|
end
|
12
12
|
|
13
|
-
|
13
|
+
create_user 'webapp', 'webapp'
|
14
|
+
create_database scripts.webapp.db_name, 'webapp'
|
14
15
|
|
15
|
-
local_exec "
|
16
|
+
local_exec "#{scripts.webapp.db.load_command scripts.webapp.db_name} < tmp/db/dump.sql"
|
16
17
|
end
|
17
18
|
|
18
|
-
def
|
19
|
-
|
20
|
-
|
19
|
+
def create_user name, password
|
20
|
+
if exec_sql("select user from mysql.user where user = '#{name}'").present?
|
21
|
+
false
|
22
|
+
else
|
23
|
+
exec_sql "create user '#{name}'@'localhost' identified by '#{password}'"
|
24
|
+
true
|
21
25
|
end
|
22
|
-
|
23
|
-
|
24
|
-
|
26
|
+
end
|
27
|
+
|
28
|
+
def create_database name, owner
|
29
|
+
if exec_sql("show databases like '#{name}'").present?
|
30
|
+
false
|
31
|
+
else
|
32
|
+
exec_sql "create database #{name}"
|
33
|
+
exec_sql "grant all on #{name}.* to '#{owner}'@'localhost'"
|
34
|
+
true
|
25
35
|
end
|
26
36
|
end
|
27
37
|
|
28
|
-
|
29
|
-
|
38
|
+
|
39
|
+
def exec_sql sql, db_name = 'mysql'
|
40
|
+
local_exec "mysql -uroot -proot #{db_name} -e \"#{sql}\""
|
30
41
|
end
|
31
42
|
end
|
data/scripts/mysql.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
Standup.script :node do
|
2
|
+
def run
|
3
|
+
install_package 'mysql-server-5.1', :input => ['root', 'root', 'root']
|
4
|
+
install_package 'libmysqlclient-dev'
|
5
|
+
|
6
|
+
# todo: tune performance
|
7
|
+
end
|
8
|
+
|
9
|
+
def exec_sql sql
|
10
|
+
exec "mysql -uroot -proot -e \"#{sql}\""
|
11
|
+
end
|
12
|
+
|
13
|
+
def create_user name, password
|
14
|
+
if exec_sql("select user from mysql.user where user = '#{name}'").present?
|
15
|
+
false
|
16
|
+
else
|
17
|
+
exec_sql "create user '#{name}'@'localhost' identified by '#{password}'"
|
18
|
+
true
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def create_database name, owner
|
23
|
+
if exec_sql("show databases like '#{name}'").present?
|
24
|
+
false
|
25
|
+
else
|
26
|
+
exec_sql "create database #{name}"
|
27
|
+
exec_sql "grant all on #{name}.* to '#{owner}'@'localhost'"
|
28
|
+
true
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def dump_command database, username = 'root', password = 'root'
|
33
|
+
"mysqldump -u#{username} -p#{password} --compact -e --create-options --add-drop-table #{database}"
|
34
|
+
end
|
35
|
+
|
36
|
+
def load_command database, username = 'root', password = 'root'
|
37
|
+
username = 'root' if username == :local
|
38
|
+
"mysql -u#{username} -p#{password} #{database}"
|
39
|
+
end
|
40
|
+
end
|
data/scripts/postgresql.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Standup.script :node do
|
2
2
|
def run
|
3
|
-
|
3
|
+
install_packages 'postgresql-8.4 libpq-dev'
|
4
4
|
|
5
5
|
upload script_file('postgresql.conf'),
|
6
6
|
:to => '/etc/postgresql/8.4/main/postgresql.conf',
|
@@ -11,8 +11,38 @@ Standup.script :node do
|
|
11
11
|
sudo 'service postgresql-8.4 restart'
|
12
12
|
end
|
13
13
|
|
14
|
-
def exec_sql
|
15
|
-
su_exec 'postgres', "psql -c \"#{
|
14
|
+
def exec_sql sql
|
15
|
+
su_exec 'postgres', "psql -c \"#{sql}\""
|
16
|
+
end
|
17
|
+
|
18
|
+
def create_user name, password
|
19
|
+
if exec_sql("select * from pg_user where usename = '#{name}'") =~ /1 row/
|
20
|
+
false
|
21
|
+
else
|
22
|
+
exec_sql "create user #{name} with password '#{password}'"
|
23
|
+
true
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def create_database name, owner
|
28
|
+
if exec_sql("select * from pg_database where datname = '#{name}'") =~ /1 row/
|
29
|
+
false
|
30
|
+
else
|
31
|
+
exec_sql "create database #{name} with owner #{owner}"
|
32
|
+
true
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def dump_command database, username = 'postgres', *args
|
37
|
+
"sudo su -c \"pg_dump -c #{database}\" #{username}"
|
38
|
+
end
|
39
|
+
|
40
|
+
def load_command database, username = 'postgres', *args
|
41
|
+
if username == :local
|
42
|
+
"psql #{database}"
|
43
|
+
else
|
44
|
+
"sudo su -c \"psql #{database}\" #{username}"
|
45
|
+
end
|
16
46
|
end
|
17
47
|
|
18
48
|
protected
|
data/scripts/update.rb
CHANGED
@@ -8,9 +8,9 @@ Standup.script :node do
|
|
8
8
|
sudo 'bundle install'
|
9
9
|
sudo "RAILS_ENV=#{scripts.webapp.params.rails_env} rake db:migrate"
|
10
10
|
sudo 'mkdir -p tmp'
|
11
|
-
sudo 'chown -R
|
11
|
+
sudo 'chown -R www-data:www-data .'
|
12
12
|
sudo 'touch tmp/restart.txt'
|
13
13
|
scripts.delayed_job.restart if scripts.setup.has_script? 'delayed_job'
|
14
14
|
end
|
15
15
|
end
|
16
|
-
end
|
16
|
+
end
|
data/scripts/upload_db.rb
CHANGED
@@ -3,14 +3,14 @@ Standup.script :node do
|
|
3
3
|
|
4
4
|
def run
|
5
5
|
local_exec "mkdir -p tmp/db"
|
6
|
-
local_exec "
|
6
|
+
local_exec "#{scripts.webapp.db.dump_command scripts.webapp.db_name, 'webapp', 'webapp'} > tmp/db/dump.sql"
|
7
7
|
|
8
8
|
in_temp_dir do |dir|
|
9
9
|
upload 'tmp/db/dump.sql',
|
10
10
|
:to => "#{dir}/dump.sql"
|
11
11
|
exec "chmod 777 #{dir}/dump.sql"
|
12
12
|
|
13
|
-
|
13
|
+
exec "#{scripts.webapp.db.load_command scripts.webapp.db_name, 'webapp', 'webapp'} < #{dir}/dump.sql"
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
data/scripts/webapp.rb
CHANGED
@@ -23,7 +23,7 @@ Standup.script :node do
|
|
23
23
|
|
24
24
|
bootstrap_db
|
25
25
|
|
26
|
-
sudo "chown -R
|
26
|
+
sudo "chown -R www-data:www-data #{scripts.webapp.app_path}"
|
27
27
|
|
28
28
|
with_processed_file script_file('webapp.conf') do |file|
|
29
29
|
scripts.passenger.add_server_conf file, "#{params.name}.conf"
|
@@ -38,6 +38,12 @@ Standup.script :node do
|
|
38
38
|
"#{params.name}_#{params.rails_env}"
|
39
39
|
end
|
40
40
|
|
41
|
+
def db
|
42
|
+
return scripts.postgresql if scripts.setup.has_script? 'postgresql'
|
43
|
+
return scripts.mysql if scripts.setup.has_script? 'mysql'
|
44
|
+
nil
|
45
|
+
end
|
46
|
+
|
41
47
|
protected
|
42
48
|
|
43
49
|
def ensure_github_access
|
@@ -57,13 +63,8 @@ Standup.script :node do
|
|
57
63
|
end
|
58
64
|
|
59
65
|
def bootstrap_db
|
60
|
-
|
61
|
-
|
62
|
-
end
|
63
|
-
|
64
|
-
unless scripts.postgresql.exec_sql("select * from pg_database where datname = '#{db_name}'") =~ /1 row/
|
65
|
-
scripts.postgresql.exec_sql "create database #{db_name} with owner webapp"
|
66
|
-
|
66
|
+
db.create_user 'webapp', 'webapp'
|
67
|
+
if db.create_database db_name, 'webapp'
|
67
68
|
in_dir scripts.webapp.app_path do
|
68
69
|
sudo 'bundle install'
|
69
70
|
exec "RAILS_ENV=#{params.rails_env} rake db:schema:load"
|
data/standup.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{standup}
|
8
|
-
s.version = "0.3.
|
8
|
+
s.version = "0.3.10"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Ilia Ablamonov", "Cloud Castle Inc."]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-12-06}
|
13
13
|
s.default_executable = %q{standup}
|
14
14
|
s.email = %q{ilia@flamefork.ru}
|
15
15
|
s.executables = ["standup"]
|
@@ -56,6 +56,7 @@ Gem::Specification.new do |s|
|
|
56
56
|
"scripts/monit/monit",
|
57
57
|
"scripts/monit/monitrc",
|
58
58
|
"scripts/monit/sshd.conf",
|
59
|
+
"scripts/mysql.rb",
|
59
60
|
"scripts/passenger.rb",
|
60
61
|
"scripts/passenger/nginx",
|
61
62
|
"scripts/passenger/nginx.conf",
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: standup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 7
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 10
|
10
|
+
version: 0.3.10
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ilia Ablamonov
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2010-
|
19
|
+
date: 2010-12-06 00:00:00 +03:00
|
20
20
|
default_executable: standup
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
@@ -173,6 +173,7 @@ files:
|
|
173
173
|
- scripts/monit/monit
|
174
174
|
- scripts/monit/monitrc
|
175
175
|
- scripts/monit/sshd.conf
|
176
|
+
- scripts/mysql.rb
|
176
177
|
- scripts/passenger.rb
|
177
178
|
- scripts/passenger/nginx
|
178
179
|
- scripts/passenger/nginx.conf
|