necktie 1.0.1 → 1.0.2

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/CHANGELOG CHANGED
@@ -1,3 +1,10 @@
1
+ 1.0.2
2
+ * Added services.reload and improved read time for services.running?
3
+ * Example now uses more file tasks for conditional updates.
4
+ * Command line option --env becomes --environment.
5
+ * Fix to cap necktie task, and using --trace by default.
6
+ * Updated examples based on tasks we're using in production.
7
+
1
8
  1.0.1 (2009-10-16)
2
9
  * Improvements to RDoc.
3
10
  * Necktie module helps with documentation and usage.
data/README.rdoc CHANGED
@@ -147,6 +147,9 @@ the default task instead of setting ROLES each time. In your Necktie file add:
147
147
  You may also want to take advantage of different environments, customizing your
148
148
  setup differently between production, staging, etc.
149
149
 
150
+ Check the example directory for ideas on how to split large configurations into
151
+ smaller files and tasks.
152
+
150
153
  Note: As with Rake, command line arguments are either options (see necktie -H),
151
154
  task names (executed in order), or name=value pairs that set environment
152
155
  variables (e.g. RAILS_ENV=production).
@@ -210,3 +213,5 @@ http://rush.heroku.com http://github.com/adamwiggins/rush
210
213
  Includes Session, created by Ara T. Howard and released under the Ruby License
211
214
  http://raa.ruby-lang.org/project/session
212
215
  http://www.codeforpeople.com/lib/ruby/session
216
+
217
+ Developed for managing EC2 instances for http://apartly.com
data/example/tasks/app.rb CHANGED
@@ -20,30 +20,30 @@ task :memcached do
20
20
  end
21
21
  end
22
22
 
23
- task :unicorn=>[:rubygems, "#{@deploy_to}/current"] do
24
- # Install init.d script to manage Unicorn, before we can start it.
23
+ file "/etc/init.d/unicorn"=>"etc/init.d/unicorn" do
25
24
  cp "etc/init.d/unicorn", "/etc/init.d/"
25
+ update "/etc/init.d/unicorn", /^ENV=.*$/, "ENV=#{Necktie.env}"
26
26
  chmod 0755, "/etc/init.d/unicorn"
27
- services.start "unicorn"
27
+ services.restart "unicorn"
28
28
  end
29
+ task :unicorn=>[:rubygems, "#{@deploy_to}/current", "/etc/initd.unicorn"]
29
30
 
30
- task :nginx=>:unicorn do
31
+ file "/etc/nginx/sites-available/unicorn.conf"=>"etc/nginx/unicorn.conf" do
31
32
  # We only care about one Nginx configuration, so enable it and disable all others.
32
- unless services.running?("nginx")
33
- rm_rf Dir["/etc/nginx/sites-enabled/*"]
34
- cp "etc/nginx/unicorn.conf", "/etc/nginx/sites-available/"
35
- ln_sf "/etc/nginx/sites-available/unicorn.conf", "/etc/nginx/sites-enabled/"
36
- services.start "nginx"
37
- end
33
+ rm_rf Dir["/etc/nginx/sites-enabled/*"]
34
+ cp "etc/nginx/unicorn.conf", "/etc/nginx/sites-available/"
35
+ ln_sf "/etc/nginx/sites-available/unicorn.conf", "/etc/nginx/sites-enabled/"
36
+ sh "service nginx reload"
38
37
  end
38
+ task :nginx=>[:unicorn, "/etc/nginx/sites-available/unicorn.conf"
39
39
 
40
- task :email do
40
+ task :postfix do
41
41
  # Have postfix send emails on behalf of our host, and start it.
42
- unless services.running?("postfix")
42
+ unless read("/etc/postfix/main.cf")[@hostname]
43
43
  update "/etc/postfix/main.cf", /^myhostname\s*=.*$/, "myhostname = #{@hostname}"
44
44
  write "/etc/mailname", @hostname
45
- services.start "postfix"
45
+ services.restart "postfix"
46
46
  end
47
47
  end
48
48
 
49
- task :app=>[:environment, :memcached, :nginx, :email]
49
+ task :app=>[:environment, :memcached, :unicorn, :nginx, :postfix]
@@ -1,16 +1,11 @@
1
1
  user, group = "nginx", "nginx"
2
-
3
2
  shared_path = "#{@deploy_to}/shared"
4
3
  cached_copy = "#{shared_path}/cached-copy"
5
4
  releases_path = "#{@deploy_to}/releases"
6
- release = Time.now.utc.strftime("%Y%m%d%H%M%S")
7
- release_path = "#{releases_path}/#{release}"
8
5
  current_path = "#{@deploy_to}/current"
9
6
 
10
7
  file @deploy_to do
11
8
  mkdir_p @deploy_to
12
- chown user, group, @deploy_to
13
- chmod 0770, @deploy_to
14
9
  end
15
10
 
16
11
  file shared_path=>@deploy_to do
@@ -19,31 +14,41 @@ file shared_path=>@deploy_to do
19
14
  chmod_R 0770, shared_path
20
15
  end
21
16
 
17
+ file cached_copy=>shared_path do
18
+ sh "git clone #{@git_url} #{cached_copy}"
19
+ chown_R user, group, cached_copy
20
+ end
21
+
22
22
  file releases_path=>@deploy_to do
23
23
  mkdir_p releases_path
24
24
  chown user, group, releases_path
25
25
  chmod 0770, releases_path
26
26
  end
27
27
 
28
- file cached_copy=>shared_path do
29
- sh "git clone #{@git_url} #{cached_copy}"
30
- chown_R user, group, cached_copy
31
- end
28
+ task :release=>[releases_path, cached_copy] do
29
+ sha = bash("git --git-dir=#{cached_copy}/.git rev-parse --verify HEAD")
30
+ latest = Dir["#{releases_path}/*/REVISION"].find { |f| File.read(f)[sha] }
31
+ if latest
32
+ @release_path = File.dirname(latest)
33
+ else
34
+ @release_path = "#{releases_path}/#{Time.now.utc.strftime("%Y%m%d%H%M%S")}"
35
+ cp_r cached_copy, @release_path
36
+ write "#{@release_path}/REVISION", sha
37
+
38
+ rm_rf ["#{@release_path}/log", "#{@release_path}/public/system", "#{@release_path}/tmp/pids"]
39
+ mkdir_p ["#{@release_path}/public", "#{@release_path}/tmp", "#{@release_path}/tmp/cache",
40
+ "#{@release_path}/tmp/sockets", "#{@release_path}/tmp/sessions"]
41
+ ln_s "#{shared_path}/log", "#{@release_path}/log"
42
+ ln_s "#{shared_path}/system", "#{@release_path}/public/system"
43
+ ln_s "#{shared_path}/pids", "#{@release_path}/tmp/pids"
32
44
 
33
- file release_path=>[releases_path, cached_copy] do
34
- cp_r cached_copy, release_path
35
- revision = bash("git --git-dir=#{cached_copy}/.git rev-parse --verify HEAD")
36
- write "#{release_path}/REVISION", revision
37
- touch release_path
38
- sh "chmod -R g+w #{release_path}"
39
- rm_rf ["#{release_path}/log", "#{release_path}/public/system", "#{release_path}/tmp/pids"]
40
- mkdir_p ["#{release_path}/public", "#{release_path}/tmp"]
41
- ln_s "#{shared_path}/log", "#{release_path}/log"
42
- ln_s "#{shared_path}/system", "#{release_path}/public/system"
43
- ln_s "#{shared_path}/pids", "#{release_path}/tmp/pids"
45
+ chown_R user, group, @release_path
46
+ sh "chmod -R g+w #{@release_path}"
47
+ end
44
48
  end
45
49
 
46
- file current_path=>[release_path, shared_path] do
50
+ file current_path=>[:release, shared_path] do
47
51
  rm_f current_path
48
- ln_s release_path, current_path
52
+ ln_s @release_path, current_path
53
+ chown user, group, current_path
49
54
  end
data/example/tasks/db.rb CHANGED
@@ -1,6 +1,6 @@
1
- task "/etc/cron/snapshot" do
1
+ file "/etc/cron.hourly/snapshot"=>"etc/cron/snapshot" do
2
2
  cp "etc/cron/snapshot", "/etc/cron.hourly/"
3
- chmod 0755, "/etc/cron/snapshot"
3
+ chmod 0755, "/etc/cron.hourly/snapshot"
4
4
  end
5
5
 
6
6
  task "/vol" do
@@ -35,7 +35,7 @@ module Necktie
35
35
 
36
36
  def necktie_options
37
37
  [
38
- ['--env', '-e NAME', "Sets the environment (defaults to 'production').",
38
+ ['--environment', '-e NAME', "Sets the environment (defaults to 'production').",
39
39
  lambda { |value|
40
40
  options.env = value
41
41
  }
@@ -8,6 +8,6 @@ Capistrano::Configuration.instance.load do
8
8
  upload gem_file, File.basename(gem_file), :via=>:scp
9
9
  sudo "gem install #{File.basename(gem_file)}"
10
10
  tasks = ENV["ROLES"].to_s.split(",") # ROLES => task names
11
- sudo "necktie --source #{necktie_url} --update --environment #{fetch(:rails_env, "production")} #{task.join(" ")}"
11
+ sudo "necktie --source #{necktie_url} --update --environment #{fetch(:rails_env, "production")} #{tasks.join(" ")} --trace"
12
12
  end
13
13
  end
@@ -5,9 +5,8 @@ module Necktie
5
5
  # service <name> start
6
6
  def start(name)
7
7
  puts " ** Starting service #{name}"
8
- system "update-rc.d #{name} defaults" and
9
- system "service #{name} start" or
10
- fail "failed to start #{name}"
8
+ sh "update-rc.d #{name} defaults"
9
+ sh "service #{name} start"
11
10
  end
12
11
 
13
12
  # Enables service to run after boot.
@@ -20,29 +19,34 @@ module Necktie
20
19
  # update_rc.d <name> remove
21
20
  def stop(name)
22
21
  puts " ** Stopping service #{name}"
23
- system "service #{name} stop" and
24
- system "update-rc.d -f #{name} remove" or
25
- fail "failed to stop #{name}"
22
+ sh "service #{name} stop"
23
+ sh "update-rc.d -f #{name} remove"
26
24
  end
27
25
 
28
26
  # Disables service from running after boot.
29
27
  def disable(name)
30
- system "update-rc.d -f #{name} remove" or fail "cannot disable #{name}"
28
+ sh "update-rc.d -f #{name} remove"
31
29
  end
32
30
 
33
31
  # Restart service. Same as:
34
32
  # service <name> restart
35
33
  def restart(name)
36
34
  puts " ** Restarting service #{name}"
37
- system "service #{name} restart" or fail "failed to restart #{name}"
35
+ sh "service #{name} restart"
36
+ end
37
+
38
+ # Reload configuration. Same as:
39
+ # service <name> reload
40
+ def reload(name)
41
+ sh "service #{name} reload"
38
42
  end
39
43
 
40
44
  # Checks if service is running. Returns true or false based on the outcome
41
45
  # of service <name> status, and nil if service doesn't have a status command.
42
46
  # (Note: Not all services report their running state, or do so reliably)
43
47
  def running?(name)
44
- status = File.read("|service --status-all 2>&1")[/^ \[ (.) \] #{Regexp.escape name}$/,1]
45
- status == "+" ? true : status == "-" ? false : nil
48
+ status = File.read("|service #{name} status 2>&1")
49
+ status[/is running/] ? true : status[/is not running/] ? false : status.empty? ? false : nil;
46
50
  end
47
51
  end
48
52
  end
data/necktie.gemspec CHANGED
@@ -1,13 +1,13 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "necktie"
3
- spec.version = "1.0.1"
3
+ spec.version = "1.0.2"
4
4
  spec.author = "Assaf Arkin"
5
5
  spec.email = "assaf@labnotes.org"
6
6
  spec.homepage = "http://github.com/assaf/necktie"
7
7
  spec.summary = "Dress to impress"
8
8
  spec.description = "Configure your servers remotely using Ruby and Git"
9
9
 
10
- spec.files = Dir["{bin,lib,vendor,example}/**/*", "*.{gemspec,rdoc}"]
10
+ spec.files = Dir["{bin,lib,vendor,example}/**/*", "CHANGELOG", "README.rdoc", "necktie.gemspec"]
11
11
  spec.executable = "necktie"
12
12
 
13
13
  spec.has_rdoc = true
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: necktie
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Assaf Arkin
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-16 00:00:00 -07:00
12
+ date: 2009-10-20 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -245,9 +245,9 @@ files:
245
245
  - example/tasks/app.rb
246
246
  - example/tasks/current.rb
247
247
  - example/tasks/db.rb
248
- - necktie.gemspec
249
- - README.rdoc
250
248
  - CHANGELOG
249
+ - README.rdoc
250
+ - necktie.gemspec
251
251
  has_rdoc: true
252
252
  homepage: http://github.com/assaf/necktie
253
253
  licenses: []