standup 0.3.8 → 0.3.9

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.8
1
+ 0.3.9
@@ -4,7 +4,6 @@ module Kernel
4
4
  end
5
5
 
6
6
  def bright_ask message, echo = true
7
- require 'highline'
8
7
  bright_p message, HighLine::GREEN
9
8
  HighLine.new.ask('') {|q| q.echo = echo}
10
9
  end
@@ -23,22 +23,27 @@ module Standup
23
23
 
24
24
  def remote_update file, body, opts = {}
25
25
  tmpfile = Tempfile.new('file')
26
-
27
- download file,
28
- :to => tmpfile.path,
29
- :sudo => opts[:sudo]
26
+
27
+ success = download file,
28
+ :to => tmpfile.path,
29
+ :sudo => opts[:sudo]
30
+ unless success
31
+ bright_p 'error during file upload'
32
+ return
33
+ end
30
34
 
31
35
  opts[:delimiter] ||= '# standup remote_update fragment'
32
36
 
33
37
  initial = File.read(tmpfile.path)
34
38
 
35
- if initial.empty?
36
- bright_p "error during file upload. skipping", Highline::RED
37
- return
38
- end
39
-
40
39
  to_change = "#{opts[:delimiter]}\n#{body}#{opts[:delimiter]}\n"
41
- changed = initial.gsub /#{opts[:delimiter]}.*#{opts[:delimiter]}\n?/m, to_change
40
+ pattern = /#{opts[:delimiter]}.*#{opts[:delimiter]}\n?/m
41
+
42
+ changed = if initial.match pattern
43
+ initial.gsub pattern, to_change
44
+ else
45
+ "#{initial}\n#{to_change}"
46
+ end
42
47
 
43
48
  File.open(tmpfile.path, 'w') {|f| f.write changed}
44
49
 
@@ -77,7 +82,7 @@ module Standup
77
82
 
78
83
  def in_temp_dir &block
79
84
  tmp_dirname = "/tmp/standup_tmp_#{rand 10000}"
80
- exec "mkdir #{tmp_dirname}"
85
+ exec "mkdir -m 777 #{tmp_dirname}"
81
86
  result = in_dir tmp_dirname, &block
82
87
  exec "rm -rf #{tmp_dirname}"
83
88
  result
@@ -103,6 +108,22 @@ module Standup
103
108
  end
104
109
  end
105
110
 
111
+ def update_cron schedule, commands, opts = {}
112
+ raise ArgumentError, ":section option is required" unless opts[:section]
113
+ user = opts[:user] || @node.scripts.ec2.params.ssh_user
114
+ commands = commands.strip.split("\n") if commands.is_a? String
115
+ commands = commands.map(&:strip).join(' && ')
116
+
117
+ in_temp_dir do |dir|
118
+ sudo "crontab -l -u #{user} > crontab.txt"
119
+ remote_update "#{dir}/crontab.txt",
120
+ "#{schedule} #{commands} > /var/log/cron.log 2>&1\n",
121
+ :delimiter => "# standup update_cron: #{opts[:section]}",
122
+ :sudo => true
123
+ sudo "crontab -u #{user} - < crontab.txt"
124
+ end
125
+ end
126
+
106
127
  def close
107
128
  @ssh.close if @ssh
108
129
  @ssh = nil
@@ -128,8 +149,9 @@ module Standup
128
149
 
129
150
  3.times do
130
151
  bright_p command
131
- break if system command
152
+ return true if system command
132
153
  end
154
+ false
133
155
  end
134
156
 
135
157
  def wrap_to_remote files
@@ -11,7 +11,7 @@ module Standup
11
11
  delegate :instance, :open_port, :open_ports, :remoting, :scripts,
12
12
  :to => :@node
13
13
 
14
- delegate :download, :upload, :remote_update, :exec, :sudo, :su_exec, :in_dir, :in_temp_dir, :file_exists?, :install_package, :install_packages, :install_gem,
14
+ delegate :download, :upload, :remote_update, :exec, :sudo, :su_exec, :in_dir, :in_temp_dir, :file_exists?, :install_package, :install_packages, :install_gem, :update_cron,
15
15
  :to => :remoting
16
16
 
17
17
  attr_accessor :node
@@ -0,0 +1,3 @@
1
+ [default]
2
+ access_key = <%= Settings.aws.access_key_id %>
3
+ secret_key = <%= Settings.aws.secret_access_key %>
data/scripts/basics.rb CHANGED
@@ -1,6 +1,11 @@
1
1
  Standup.script :node do
2
2
  def run
3
3
  sudo 'apt-get -qq update'
4
- install_packages 'build-essential libreadline5-dev mc'
4
+ install_packages 'build-essential libreadline5-dev mc s3cmd'
5
+
6
+ with_processed_file script_file('s3cfg') do |file|
7
+ upload file,
8
+ :to => "/home/#{scripts.ec2.params.ssh_user}/.s3cfg"
9
+ end
5
10
  end
6
11
  end
@@ -0,0 +1,25 @@
1
+ Standup.script :node do
2
+ self.description = 'Rails application database periodic backup to S3'
3
+
4
+ def run
5
+ exec "s3cmd mb #{bucket}"
6
+
7
+ update_cron '@hourly', <<-CMD, :section => name
8
+ touch dump.gz
9
+ sudo chmod 666 dump.gz
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
12
+ rm dump.gz
13
+ CMD
14
+ end
15
+
16
+ protected
17
+
18
+ def bucket
19
+ 's3://standup-backup'
20
+ end
21
+
22
+ def path_prefix
23
+ "#{bucket}/db/#{scripts.webapp.db_name}"
24
+ end
25
+ end
@@ -3,7 +3,6 @@ Standup.script :node do
3
3
 
4
4
  def run
5
5
  in_temp_dir do |dir|
6
- exec 'chmod 777 .'
7
6
  su_exec 'postgres', "pg_dump -c #{scripts.webapp.db_name} > dump.sql"
8
7
  local_exec "mkdir -p tmp/db"
9
8
  download "#{dir}/dump.sql",
data/scripts/setup.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  Standup.script :node do
2
2
  self.description = 'Do all setup from scratch and/or incrementally'
3
3
 
4
- self.default_params = 'ec2 basics monit ruby postgresql passenger webapp update'
4
+ self.default_params = 'ec2 basics monit ruby postgresql passenger webapp db_backup update'
5
5
 
6
6
  def run
7
7
  params.strip.split.each do |name|
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"
8
+ s.version = "0.3.9"
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-11-15}
12
+ s.date = %q{2010-11-16}
13
13
  s.default_executable = %q{standup}
14
14
  s.email = %q{ilia@flamefork.ru}
15
15
  s.executables = ["standup"]
@@ -40,7 +40,9 @@ Gem::Specification.new do |s|
40
40
  "scripts/allocate_ip.rb",
41
41
  "scripts/appconsole.rb",
42
42
  "scripts/basics.rb",
43
+ "scripts/basics/s3cfg",
43
44
  "scripts/browse.rb",
45
+ "scripts/db_backup.rb",
44
46
  "scripts/delayed_job.rb",
45
47
  "scripts/delayed_job/delayed_job_monit.conf",
46
48
  "scripts/download_db.rb",
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: 3
4
+ hash: 1
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 8
10
- version: 0.3.8
9
+ - 9
10
+ version: 0.3.9
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-11-15 00:00:00 +03:00
19
+ date: 2010-11-16 00:00:00 +03:00
20
20
  default_executable: standup
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -157,7 +157,9 @@ files:
157
157
  - scripts/allocate_ip.rb
158
158
  - scripts/appconsole.rb
159
159
  - scripts/basics.rb
160
+ - scripts/basics/s3cfg
160
161
  - scripts/browse.rb
162
+ - scripts/db_backup.rb
161
163
  - scripts/delayed_job.rb
162
164
  - scripts/delayed_job/delayed_job_monit.conf
163
165
  - scripts/download_db.rb