necktie 1.0.0 → 1.0.1
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 +6 -0
- data/README.rdoc +16 -10
- data/lib/necktie/files.rb +39 -35
- data/lib/necktie/gems.rb +18 -14
- data/lib/necktie/rush.rb +1 -1
- data/lib/necktie/services.rb +43 -41
- data/lib/necktie.rb +8 -0
- data/necktie.gemspec +6 -1
- metadata +12 -5
data/CHANGELOG
ADDED
data/README.rdoc
CHANGED
@@ -34,7 +34,7 @@ At the base of your Necktie project there's a file called Necktie (or necktie,
|
|
34
34
|
or necktie.rb), with a list of tasks. For example:
|
35
35
|
|
36
36
|
file "/var/myapp" do
|
37
|
-
append "/etc/fstab", "
|
37
|
+
append "/etc/fstab", "/mnt/myapp /var/myapp none bind\n" unless read("/etc/fstab")["/mnt/myapp"]
|
38
38
|
mkdir_p "/var/myapp/"
|
39
39
|
sh "mount /var/myapp"
|
40
40
|
end
|
@@ -55,7 +55,7 @@ or necktie.rb), with a list of tasks. For example:
|
|
55
55
|
end
|
56
56
|
|
57
57
|
desc "Setup and start Unicorn"
|
58
|
-
task :unicorn=>[:rubygems] do
|
58
|
+
task :unicorn=>[:rubygems, "/var/myapp"] do
|
59
59
|
cp "etc/init.d/unicorn", "/etc/init.d/"
|
60
60
|
chmod 0750, "/etc/init.d/unicorn"
|
61
61
|
end
|
@@ -100,9 +100,11 @@ Upgrading running instances with new configuration:
|
|
100
100
|
|
101
101
|
Necktie includes Rush, so you can write tasks like this:
|
102
102
|
|
103
|
-
|
104
|
-
|
105
|
-
|
103
|
+
task :memcached do
|
104
|
+
unless processes.find { |p| p.cmdline[/memcached\s.*-l\s0.0.0.0/] }
|
105
|
+
box["/etc/memcached.conf"].replace_contents! /^-l 127.0.0.1/, "-l 0.0.0.0"
|
106
|
+
services.start "memcached"
|
107
|
+
end
|
106
108
|
end
|
107
109
|
|
108
110
|
You can learn more about Rush here: http://rush.heroku.com
|
@@ -110,9 +112,11 @@ You can learn more about Rush here: http://rush.heroku.com
|
|
110
112
|
Of course, there's also FileUtils, system and sh (courtesy of Rake), so you can
|
111
113
|
also:
|
112
114
|
|
113
|
-
|
114
|
-
|
115
|
-
|
115
|
+
# Update whenever we have a newer config file.
|
116
|
+
file "/etc/nginx/nginx.conf"=>"etc/nginx.conf" do
|
117
|
+
cp "etc/nginx.conf", "/etc/nginx/nginx.conf"
|
118
|
+
sh "service nginx restart"
|
119
|
+
end
|
116
120
|
|
117
121
|
The current directory (Dir.pwd and launch_dir) is the root directory of your
|
118
122
|
Necktie repository. You can depend on relative paths when accessing files in
|
@@ -165,8 +169,10 @@ to upgrade.
|
|
165
169
|
Since install_gem will only install the same gem/version once, a run-always
|
166
170
|
rubygems.rb task is all you need:
|
167
171
|
|
168
|
-
|
169
|
-
|
172
|
+
task :rubygems do
|
173
|
+
Dir["gems/*.gem"].each do |gem|
|
174
|
+
install_gem gem
|
175
|
+
end
|
170
176
|
end
|
171
177
|
|
172
178
|
|
data/lib/necktie/files.rb
CHANGED
@@ -1,42 +1,46 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
# Writes contents to a new file, or overwrites existing file.
|
7
|
-
# Takes string as second argument, or yields to block. For example:
|
8
|
-
# write "/etc/mailname", "example.com"
|
9
|
-
# write("/var/run/bowtie.pid") { Process.pid }
|
10
|
-
def write(name, contents = nil)
|
11
|
-
contents ||= yield
|
12
|
-
File.open name, "w" do |f|
|
13
|
-
f.write contents
|
1
|
+
module Necktie::Files
|
2
|
+
# Return the contents of the file (same as File.read).
|
3
|
+
def read(name)
|
4
|
+
File.read(name)
|
14
5
|
end
|
15
|
-
end
|
16
6
|
|
17
|
-
#
|
18
|
-
# Takes string as second argument, or yields to block. For example:
|
19
|
-
#
|
20
|
-
|
21
|
-
contents
|
22
|
-
|
23
|
-
|
7
|
+
# Writes contents to a new file, or overwrites existing file.
|
8
|
+
# Takes string as second argument, or yields to block. For example:
|
9
|
+
# write "/etc/mailname", "example.com"
|
10
|
+
# write("/var/run/bowtie.pid") { Process.pid }
|
11
|
+
def write(name, contents = nil)
|
12
|
+
contents ||= yield
|
13
|
+
File.open name, "w" do |f|
|
14
|
+
f.write contents
|
15
|
+
end
|
24
16
|
end
|
25
|
-
end
|
26
17
|
|
27
|
-
#
|
28
|
-
# Takes
|
29
|
-
#
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
contents = contents.sub(from, to)
|
36
|
-
else
|
37
|
-
contents = yield(contents)
|
18
|
+
# Append contents to a file, creating it if necessary.
|
19
|
+
# Takes string as second argument, or yields to block. For example:
|
20
|
+
# append "/etc/fstab", "/dev/sdh /vol xfs\n" unless read("/etc/fstab")["/dev/sdh "]
|
21
|
+
def append(name, contents = nil)
|
22
|
+
contents ||= yield
|
23
|
+
File.open name, "a" do |f|
|
24
|
+
f.write contents
|
25
|
+
end
|
38
26
|
end
|
39
|
-
|
40
|
-
|
27
|
+
|
28
|
+
# Updates a file: read contents, substitue and write it back.
|
29
|
+
# Takes two arguments for substitution, or yields to block.
|
30
|
+
# These two are equivalent:
|
31
|
+
# update "/etc/memcached.conf", /^-l 127.0.0.1/, "-l 0.0.0.0"
|
32
|
+
# update("/etc/memcached.conf") { |s| s.sub(/^-l 127.0.0.1/, "-l 0.0.0.0") }
|
33
|
+
def update(name, from = nil, to = nil)
|
34
|
+
contents = File.read(name)
|
35
|
+
if from && to
|
36
|
+
contents = contents.sub(from, to)
|
37
|
+
else
|
38
|
+
contents = yield(contents)
|
39
|
+
end
|
40
|
+
File.open name, "w" do |f|
|
41
|
+
f.write contents
|
42
|
+
end
|
41
43
|
end
|
42
44
|
end
|
45
|
+
|
46
|
+
include Necktie::Files
|
data/lib/necktie/gems.rb
CHANGED
@@ -1,18 +1,22 @@
|
|
1
1
|
require "rubygems/dependency_installer"
|
2
2
|
|
3
|
-
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
3
|
+
module Necktie::Gems
|
4
|
+
# Installs the specified gem, if not already installed. First argument is the
|
5
|
+
# name of the gem, or file containing the gem. Second argument is version requirement.
|
6
|
+
# For example:
|
7
|
+
# install_gem "unicorn", "~>0.93"
|
8
|
+
#
|
9
|
+
# Dir["gems/*.gem"].each do |gem|
|
10
|
+
# install_gem gem
|
11
|
+
# end
|
12
|
+
def install_gem(name, version = nil)
|
13
|
+
installer = Gem::DependencyInstaller.new
|
14
|
+
spec = installer.find_spec_by_name_and_version(name, version).first.first
|
15
|
+
if Gem::SourceIndex.from_installed_gems.find_name(spec.name, spec.version).empty?
|
16
|
+
puts " ** Installing the gem #{spec.name} #{spec.version}"
|
17
|
+
installer.install name, version
|
18
|
+
end
|
17
19
|
end
|
18
20
|
end
|
21
|
+
|
22
|
+
include Necktie::Gems
|
data/lib/necktie/rush.rb
CHANGED
data/lib/necktie/services.rb
CHANGED
@@ -1,54 +1,56 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
system "
|
9
|
-
|
10
|
-
|
1
|
+
module Necktie
|
2
|
+
class Services
|
3
|
+
# Enables service to run after boot and starts it. Same as:
|
4
|
+
# update_rc.d <name> defaults
|
5
|
+
# service <name> start
|
6
|
+
def start(name)
|
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}"
|
11
|
+
end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
# Enables service to run after boot.
|
14
|
+
def enable(name)
|
15
|
+
system "update-rc.d #{name} defaults" or "cannot enable #{name}"
|
16
|
+
end
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
18
|
+
# Disables service and stops it. Same as:
|
19
|
+
# service <name> stop
|
20
|
+
# update_rc.d <name> remove
|
21
|
+
def stop(name)
|
22
|
+
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}"
|
26
|
+
end
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
# Disables service from running after boot.
|
29
|
+
def disable(name)
|
30
|
+
system "update-rc.d -f #{name} remove" or fail "cannot disable #{name}"
|
31
|
+
end
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
33
|
+
# Restart service. Same as:
|
34
|
+
# service <name> restart
|
35
|
+
def restart(name)
|
36
|
+
puts " ** Restarting service #{name}"
|
37
|
+
system "service #{name} restart" or fail "failed to restart #{name}"
|
38
|
+
end
|
38
39
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
40
|
+
# Checks if service is running. Returns true or false based on the outcome
|
41
|
+
# of service <name> status, and nil if service doesn't have a status command.
|
42
|
+
# (Note: Not all services report their running state, or do so reliably)
|
43
|
+
def running?(name)
|
44
|
+
status = File.read("|service --status-all 2>&1")[/^ \[ (.) \] #{Regexp.escape name}$/,1]
|
45
|
+
status == "+" ? true : status == "-" ? false : nil
|
46
|
+
end
|
45
47
|
end
|
46
48
|
end
|
47
49
|
|
48
|
-
# Returns Services object. Examples:
|
50
|
+
# Returns Necktie::Services object. Examples:
|
49
51
|
# services.restart "nginx"
|
50
52
|
# services.start "mysql" unless services.running?("mysql")
|
51
53
|
# services.enable "memcached" # but don't start yet
|
52
54
|
def services
|
53
|
-
@services ||= Services.new
|
55
|
+
@services ||= Necktie::Services.new
|
54
56
|
end
|
data/lib/necktie.rb
CHANGED
@@ -3,3 +3,11 @@ require "necktie/files"
|
|
3
3
|
require "necktie/gems"
|
4
4
|
require "necktie/services"
|
5
5
|
require "necktie/rush"
|
6
|
+
|
7
|
+
# Includes all methods from Necktie::Files and Necktie::Gems methods.
|
8
|
+
#
|
9
|
+
# Includes Rake DSL, see http://rake.rubyforge.org for more details.
|
10
|
+
#
|
11
|
+
# Includes Rush, see http://rush.heroku.com for more details.
|
12
|
+
class Object
|
13
|
+
end
|
data/necktie.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = "necktie"
|
3
|
-
spec.version = "1.0.
|
3
|
+
spec.version = "1.0.1"
|
4
4
|
spec.author = "Assaf Arkin"
|
5
5
|
spec.email = "assaf@labnotes.org"
|
6
6
|
spec.homepage = "http://github.com/assaf/necktie"
|
@@ -9,4 +9,9 @@ Gem::Specification.new do |spec|
|
|
9
9
|
|
10
10
|
spec.files = Dir["{bin,lib,vendor,example}/**/*", "*.{gemspec,rdoc}"]
|
11
11
|
spec.executable = "necktie"
|
12
|
+
|
13
|
+
spec.has_rdoc = true
|
14
|
+
spec.extra_rdoc_files = 'README.rdoc', 'CHANGELOG'
|
15
|
+
spec.rdoc_options = '--title', 'Necktie', '--main', 'README.rdoc',
|
16
|
+
'--webcvs', 'http://github.com/assaf/necktie'
|
12
17
|
end
|
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.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Assaf Arkin
|
@@ -19,8 +19,9 @@ executables:
|
|
19
19
|
- necktie
|
20
20
|
extensions: []
|
21
21
|
|
22
|
-
extra_rdoc_files:
|
23
|
-
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.rdoc
|
24
|
+
- CHANGELOG
|
24
25
|
files:
|
25
26
|
- bin/necktie
|
26
27
|
- lib/necktie/application.rb
|
@@ -246,13 +247,19 @@ files:
|
|
246
247
|
- example/tasks/db.rb
|
247
248
|
- necktie.gemspec
|
248
249
|
- README.rdoc
|
250
|
+
- CHANGELOG
|
249
251
|
has_rdoc: true
|
250
252
|
homepage: http://github.com/assaf/necktie
|
251
253
|
licenses: []
|
252
254
|
|
253
255
|
post_install_message:
|
254
|
-
rdoc_options:
|
255
|
-
|
256
|
+
rdoc_options:
|
257
|
+
- --title
|
258
|
+
- Necktie
|
259
|
+
- --main
|
260
|
+
- README.rdoc
|
261
|
+
- --webcvs
|
262
|
+
- http://github.com/assaf/necktie
|
256
263
|
require_paths:
|
257
264
|
- lib
|
258
265
|
required_ruby_version: !ruby/object:Gem::Requirement
|