standup 0.3.7 → 0.3.8

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/README.md CHANGED
@@ -35,10 +35,12 @@ You can override this behavior by specifying `keypair_file` param.
35
35
  instance_type: m1.small
36
36
  ssh_user: ubuntu
37
37
  webapp:
38
+ name: superproject
38
39
  github_user: supercoder
39
40
  github_repo: superproject
40
41
 
41
42
  Major part of script params can be set here.
43
+ In `webapp` script `name` param is used for database name and application path.
42
44
 
43
45
  ### Nodes and their script params
44
46
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.7
1
+ 0.3.8
@@ -8,4 +8,9 @@ module Kernel
8
8
  bright_p message, HighLine::GREEN
9
9
  HighLine.new.ask('') {|q| q.echo = echo}
10
10
  end
11
+
12
+ def local_exec command
13
+ bright_p command
14
+ `#{command}`
15
+ end
11
16
  end
@@ -51,7 +51,7 @@ module Standup
51
51
  raise ArgumentError, 'Only absolute paths allowed' unless path[0,1] == '/'
52
52
  old_path = @path
53
53
  @path = path
54
- result = yield
54
+ result = yield path
55
55
  @path = old_path
56
56
  result
57
57
  end
@@ -71,6 +71,10 @@ module Standup
71
71
  exec "sudo #{command}"
72
72
  end
73
73
 
74
+ def su_exec user, command
75
+ sudo "su -c \"#{command.gsub /"/, '\"'}\" #{user}"
76
+ end
77
+
74
78
  def in_temp_dir &block
75
79
  tmp_dirname = "/tmp/standup_tmp_#{rand 10000}"
76
80
  exec "mkdir #{tmp_dirname}"
@@ -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, :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,
15
15
  :to => :remoting
16
16
 
17
17
  attr_accessor :node
@@ -2,6 +2,6 @@ Standup.script :node do
2
2
  self.description = 'Run remote Rails application console'
3
3
 
4
4
  def run
5
- scripts.shell.make_shell "cd /opt/webapp && rails console #{scripts.webapp.params.rails_env}"
5
+ scripts.shell.make_shell "cd #{scripts.webapp.app_path} && rails console #{scripts.webapp.params.rails_env}"
6
6
  end
7
7
  end
@@ -1,6 +1,8 @@
1
1
  Standup.script :node do
2
2
  def run
3
- scripts.monit.add_watch script_file('delayed_job_monit.conf')
3
+ with_processed_file script_file('delayed_job_monit.conf') do |file|
4
+ scripts.monit.add_watch file
5
+ end
4
6
  end
5
7
 
6
8
  def restart
@@ -1,4 +1,5 @@
1
+ <% env = "/usr/bin/env PATH=$PATH:/usr/local/bin RAILS_ENV=production" %>
1
2
  check process delayed_job
2
- with pidfile /opt/webapp/tmp/pids/delayed_job.pid
3
- start program = "/usr/bin/env PATH=$PATH:/usr/local/bin RAILS_ENV=production /opt/webapp/script/delayed_job start"
4
- stop program = "/usr/bin/env PATH=$PATH:/usr/local/bin RAILS_ENV=production /opt/webapp/script/delayed_job stop"
3
+ with pidfile <%= scripts.webapp.app_path %>/tmp/pids/delayed_job.pid
4
+ start program = "<%= env %> <%= scripts.webapp.app_path %>/script/delayed_job start"
5
+ stop program = "<%= env %> <%= scripts.webapp.app_path %>/script/delayed_job stop"
@@ -0,0 +1,32 @@
1
+ Standup.script :node do
2
+ self.description = 'Download Rails application database from node to local server'
3
+
4
+ def run
5
+ in_temp_dir do |dir|
6
+ exec 'chmod 777 .'
7
+ su_exec 'postgres', "pg_dump -c #{scripts.webapp.db_name} > dump.sql"
8
+ local_exec "mkdir -p tmp/db"
9
+ download "#{dir}/dump.sql",
10
+ :to => 'tmp/db/dump.sql',
11
+ :sudo => true
12
+ end
13
+
14
+ bootstrap_db
15
+
16
+ local_exec "psql #{scripts.webapp.db_name} < tmp/db/dump.sql"
17
+ end
18
+
19
+ def bootstrap_db
20
+ unless exec_sql("select * from pg_user where usename = 'webapp'") =~ /1 row/
21
+ exec_sql "create user webapp with password 'webapp'"
22
+ end
23
+
24
+ unless exec_sql("select * from pg_database where datname = '#{scripts.webapp.db_name}'") =~ /1 row/
25
+ exec_sql "create database #{scripts.webapp.db_name} with owner webapp"
26
+ end
27
+ end
28
+
29
+ def exec_sql sql, db_name = 'postgres'
30
+ local_exec "psql #{db_name} -c \"#{sql}\""
31
+ end
32
+ end
@@ -12,6 +12,7 @@ ec2:
12
12
  instance_type: m1.small
13
13
  ssh_user: ubuntu
14
14
  webapp:
15
+ name:
15
16
  github_user:
16
17
  github_repo:
17
18
 
@@ -11,6 +11,12 @@ Standup.script :node do
11
11
  sudo 'service postgresql-8.4 restart'
12
12
  end
13
13
 
14
+ def exec_sql command
15
+ su_exec 'postgres', "psql -c \"#{command}\""
16
+ end
17
+
18
+ protected
19
+
14
20
  def tune_kernel
15
21
  sysctl_params = ['kernel.shmmax=134217728', 'kernel.shmall=2097152']
16
22
 
data/scripts/update.rb CHANGED
@@ -2,13 +2,13 @@ Standup.script :node do
2
2
  self.description = 'Update working application'
3
3
 
4
4
  def run
5
- in_dir '/opt/webapp' do
6
- sudo 'chown -R ubuntu:ubuntu /opt/webapp'
5
+ in_dir scripts.webapp.app_path do
6
+ sudo 'chown -R ubuntu:ubuntu .'
7
7
  exec 'git pull'
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 nobody:nogroup /opt/webapp'
11
+ sudo 'chown -R nobody:nogroup .'
12
12
  sudo 'touch tmp/restart.txt'
13
13
  scripts.delayed_job.restart if scripts.setup.has_script? 'delayed_job'
14
14
  end
@@ -0,0 +1,16 @@
1
+ Standup.script :node do
2
+ self.description = 'Upload Rails application database from local server to node'
3
+
4
+ def run
5
+ local_exec "mkdir -p tmp/db"
6
+ local_exec "pg_dump -c #{scripts.webapp.db_name} > tmp/db/dump.sql"
7
+
8
+ in_temp_dir do |dir|
9
+ upload 'tmp/db/dump.sql',
10
+ :to => "#{dir}/dump.sql"
11
+ exec "chmod 777 #{dir}/dump.sql"
12
+
13
+ su_exec 'postgres', "psql #{scripts.webapp.db_name} < #{dir}/dump.sql"
14
+ end
15
+ end
16
+ end
data/scripts/watchlog.rb CHANGED
@@ -2,6 +2,6 @@ Standup.script :node do
2
2
  self.description = 'Watch remote Rails application log'
3
3
 
4
4
  def run
5
- scripts.shell.make_shell "tail -n 1000 -f /opt/webapp/log/#{scripts.webapp.params.rails_env}.log"
5
+ scripts.shell.make_shell "tail -n 1000 -f #{scripts.webapp.app_path}/log/#{scripts.webapp.params.rails_env}.log"
6
6
  end
7
7
  end
data/scripts/webapp.rb CHANGED
@@ -1,34 +1,43 @@
1
1
  Standup.script :node do
2
2
  self.default_params = {
3
- :rails_env => 'production'
3
+ :rails_env => 'production',
4
+ :name => 'webapp'
4
5
  }
5
6
 
6
7
  def run
7
8
  install_package 'git-core'
8
9
  install_gem 'bundler'
9
10
 
10
- unless file_exists? '/opt/webapp'
11
- sudo 'mkdir -p /opt/webapp'
11
+ unless file_exists? scripts.webapp.app_path
12
+ sudo "mkdir -p #{scripts.webapp.app_path}"
12
13
  end
13
14
 
14
- sudo 'chown -R ubuntu:ubuntu /opt/webapp'
15
+ sudo "chown -R ubuntu:ubuntu #{scripts.webapp.app_path}"
15
16
 
16
17
  ensure_github_access
17
18
 
18
- unless file_exists? '/opt/webapp/.git'
19
- exec 'rm -rf /opt/webapp/*'
20
- exec "git clone git@github.com:#{params.github_user}/#{params.github_repo}.git /opt/webapp"
19
+ unless file_exists? "#{scripts.webapp.app_path}/.git"
20
+ exec "rm -rf #{scripts.webapp.app_path}/*"
21
+ exec "git clone git@github.com:#{params.github_user}/#{params.github_repo}.git #{scripts.webapp.app_path}"
21
22
  end
22
23
 
23
24
  bootstrap_db
24
25
 
25
- sudo 'chown -R nobody:nogroup /opt/webapp'
26
+ sudo "chown -R nobody:nogroup #{scripts.webapp.app_path}"
26
27
 
27
28
  with_processed_file script_file('webapp.conf') do |file|
28
- scripts.passenger.add_server_conf file
29
+ scripts.passenger.add_server_conf file, "#{params.name}.conf"
29
30
  end
30
31
  end
31
32
 
33
+ def app_path
34
+ "/opt/#{params.name}"
35
+ end
36
+
37
+ def db_name
38
+ "#{params.name}_#{params.rails_env}"
39
+ end
40
+
32
41
  protected
33
42
 
34
43
  def ensure_github_access
@@ -48,14 +57,14 @@ Standup.script :node do
48
57
  end
49
58
 
50
59
  def bootstrap_db
51
- unless run_pg_command("select * from pg_user where usename = 'webapp'") =~ /1 row/
52
- run_pg_command "create user webapp with password 'webapp'"
60
+ unless scripts.postgresql.exec_sql("select * from pg_user where usename = 'webapp'") =~ /1 row/
61
+ scripts.postgresql.exec_sql "create user webapp with password 'webapp'"
53
62
  end
54
63
 
55
- unless run_pg_command("select * from pg_database where datname = 'webapp'") =~ /1 row/
56
- run_pg_command "create database webapp with owner webapp"
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"
57
66
 
58
- in_dir '/opt/webapp' do
67
+ in_dir scripts.webapp.app_path do
59
68
  sudo 'bundle install'
60
69
  exec "RAILS_ENV=#{params.rails_env} rake db:schema:load"
61
70
  exec "RAILS_ENV=#{params.rails_env} rake db:seed"
@@ -63,10 +72,6 @@ Standup.script :node do
63
72
  end
64
73
  end
65
74
 
66
- def run_pg_command cmd
67
- sudo("su -c \"psql -c \\\"#{cmd}\\\"\" postgres")
68
- end
69
-
70
75
  def github_add_deploy_key user, password, repo, title, key
71
76
  require 'net/http'
72
77
  Net::HTTP.start 'github.com' do |http|
@@ -2,7 +2,7 @@ server {
2
2
  server_name _;
3
3
  listen 80;
4
4
 
5
- root /opt/webapp/public;
5
+ root <%= app_path %>/public;
6
6
 
7
7
  rails_env <%= params.rails_env %>;
8
8
 
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.7"
8
+ s.version = "0.3.8"
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-13}
12
+ s.date = %q{2010-11-15}
13
13
  s.default_executable = %q{standup}
14
14
  s.email = %q{ilia@flamefork.ru}
15
15
  s.executables = ["standup"]
@@ -43,6 +43,7 @@ Gem::Specification.new do |s|
43
43
  "scripts/browse.rb",
44
44
  "scripts/delayed_job.rb",
45
45
  "scripts/delayed_job/delayed_job_monit.conf",
46
+ "scripts/download_db.rb",
46
47
  "scripts/ec2.rb",
47
48
  "scripts/generate.rb",
48
49
  "scripts/generate/script.rb",
@@ -65,6 +66,7 @@ Gem::Specification.new do |s|
65
66
  "scripts/status.rb",
66
67
  "scripts/terminate.rb",
67
68
  "scripts/update.rb",
69
+ "scripts/upload_db.rb",
68
70
  "scripts/watchlog.rb",
69
71
  "scripts/webapp.rb",
70
72
  "scripts/webapp/webapp.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: 29
4
+ hash: 3
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 7
10
- version: 0.3.7
9
+ - 8
10
+ version: 0.3.8
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-13 00:00:00 +03:00
19
+ date: 2010-11-15 00:00:00 +03:00
20
20
  default_executable: standup
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -160,6 +160,7 @@ files:
160
160
  - scripts/browse.rb
161
161
  - scripts/delayed_job.rb
162
162
  - scripts/delayed_job/delayed_job_monit.conf
163
+ - scripts/download_db.rb
163
164
  - scripts/ec2.rb
164
165
  - scripts/generate.rb
165
166
  - scripts/generate/script.rb
@@ -182,6 +183,7 @@ files:
182
183
  - scripts/status.rb
183
184
  - scripts/terminate.rb
184
185
  - scripts/update.rb
186
+ - scripts/upload_db.rb
185
187
  - scripts/watchlog.rb
186
188
  - scripts/webapp.rb
187
189
  - scripts/webapp/webapp.conf