tele 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/README +10 -24
  2. data/bin/tele +21 -51
  3. data/tele.gemspec +1 -1
  4. data/test/tele.rb +14 -20
  5. metadata +3 -5
data/README CHANGED
@@ -4,7 +4,7 @@ NAME
4
4
  tele -- Provisioning at a distance.
5
5
 
6
6
  SYNOPSIS
7
- tele [-h] [-d path] (init|status|install)
7
+ tele [-h] [-d path] (init|deploy)
8
8
 
9
9
  DESCRIPTION
10
10
  Tele is a small provisioning framework that allows you to run bash
@@ -16,10 +16,8 @@ DESCRIPTION
16
16
 
17
17
  .tele/layout.json
18
18
  .tele/ssh_config
19
- .tele/recipes/redis/status.sh
20
- .tele/recipes/redis/install.sh
21
- .tele/recipes/unicorn/status.sh
22
- .tele/recipes/unicorn/install.sh
19
+ .tele/recipes/redis.sh
20
+ .tele/recipes/unicorn.sh
23
21
 
24
22
  In the example, there are recipes for Redis and Unicorn. Please note that you are in
25
23
  charge of creating them.
@@ -67,16 +65,9 @@ DESCRIPTION
67
65
  init
68
66
  Copies a .tele template to the current directory.
69
67
 
70
- status
71
- Runs every status.sh script on the servers declared in layout.json,
72
- and prints the responses. The status.sh script must return 0 if
73
- everything is correct, and a value different form zero otherwise.
74
- What to check in the script is up to the user.
75
-
76
- install
77
- Runs every install.sh script on the servers declared in layout.json,
78
- but only if the status.sh returns an error. The exit code must be 0
79
- if the installation was successful.
68
+ deploy
69
+ Runs every recipe script on the servers declared in layout.json. The
70
+ exit code must be 0 if the command was successful.
80
71
 
81
72
  USAGE
82
73
  To provision two servers called `server1` and `server2` with Redis,
@@ -85,13 +76,8 @@ USAGE
85
76
  # Create the .tele directory.
86
77
  $ tele init
87
78
 
88
- # Create directories for the recipes.
89
- $ mkdir -p .tele/recipes/redis
90
-
91
- # Create status.sh script.
92
- $ echo "which redis-server" > ./tele/recipes/redis/status.sh
93
-
94
- # Create install.sh script (ommited).
79
+ # Create the Redis recipe.
80
+ $ echo "which redis-server || sudo apt-get install redis" > .tele/recipes/redis.sh
95
81
 
96
82
  # Edit .tele/layout.json as follows:
97
83
 
@@ -114,8 +100,8 @@ USAGE
114
100
  Host server2
115
101
  Hostname 10.0.0.2
116
102
 
117
- # Run tele install
118
- $ tele install
103
+ # Run tele deploy
104
+ $ tele deploy
119
105
 
120
106
  INSTALLATION
121
107
  $ gem install tele
data/bin/tele CHANGED
@@ -27,9 +27,8 @@ def path(*parts)
27
27
  File.expand_path(File.join(*parts), ENV["TELE_HOME"])
28
28
  end
29
29
 
30
- def ssh(server, script)
31
- %x{bash -c "ssh -T -F #{path("ssh_config")} #{server} < #{script} > >(logger -t 'tele/#{server}') 2>&1"}
32
- $?.exitstatus
30
+ def ssh(server, options = [])
31
+ "ssh #{options.join(" ")} #{server}"
33
32
  end
34
33
 
35
34
  def layout
@@ -44,15 +43,12 @@ def roles
44
43
  layout["roles"]
45
44
  end
46
45
 
47
- def recipe_script(recipe, command)
48
- path("recipes", recipe, "#{command}.sh")
49
- end
50
-
51
- def run(server, recipe, command)
52
- script = recipe_script(recipe, command)
46
+ def run(server, recipe)
47
+ script = path("recipes", "#{recipe}.sh")
53
48
 
54
49
  if File.exist?(script)
55
- ssh(server, script)
50
+ %x{bash -c "#{ssh(server, SSH_OPTIONS)} < #{script} > >(logger -t 'tele/#{server}/#{recipe}') 2>&1"}
51
+ $?.exitstatus
56
52
  end
57
53
  end
58
54
 
@@ -69,14 +65,6 @@ out = Module.new do
69
65
  puts "\033[01;32mOK\033[00m"
70
66
  end
71
67
 
72
- def self.missing
73
- puts "\033[01;33mMISSING\033[00m"
74
- end
75
-
76
- def self.done
77
- puts "\033[01;32mDONE\033[00m"
78
- end
79
-
80
68
  def self.unknown
81
69
  puts "?"
82
70
  end
@@ -100,7 +88,8 @@ Clap.run commands,
100
88
  target = File.expand_path(Dir.pwd)
101
89
 
102
90
  %x{cp -r #{source} #{target}}
103
- out.done
91
+
92
+ %x{find #{target} -name .empty -print0 | xargs rm}
104
93
  }
105
94
 
106
95
  unless File.directory?(path)
@@ -108,50 +97,31 @@ unless File.directory?(path)
108
97
  exit 1
109
98
  end
110
99
 
100
+ SSH_OPTIONS = [
101
+ "-T",
102
+ "-F", path("ssh_config"),
103
+ "-S", "/tmp/ssh-%r@%h:%p",
104
+ ]
105
+
111
106
  Clap.run commands,
112
- "status" => lambda {
107
+ "deploy" => lambda {
108
+ servers.each do |server, _|
109
+ IO.popen(ssh(server, SSH_OPTIONS + %w[-Mq]), "w")
110
+ end
111
+
113
112
  servers.each do |server, assigned_roles|
114
113
  out.server(server)
115
114
 
116
115
  recipes_for(assigned_roles).each do |recipe|
117
116
  print " #{recipe}: "
118
117
 
119
- case run(server, recipe, :status)
118
+ case run(server, recipe)
120
119
  when nil
121
120
  out.unknown
122
121
  when 0
123
122
  out.ok
124
123
  else
125
- out.missing
126
- end
127
- end
128
-
129
- puts
130
- end
131
- },
132
-
133
- "install" => lambda {
134
- servers.each do |server, assigned_roles|
135
- out.server(server)
136
-
137
- recipes_for(assigned_roles).each do |recipe|
138
- print " #{recipe}: "
139
-
140
- if run(server, recipe, :status) == 0
141
- out.ok
142
- else
143
- case run(server, recipe, :install)
144
- when nil
145
- out.unknown
146
- when 0
147
- if run(server, recipe, :status) == 0
148
- out.done
149
- else
150
- out.missing
151
- end
152
- else
153
- out.error
154
- end
124
+ out.error
155
125
  end
156
126
  end
157
127
 
data/tele.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "tele"
3
- s.version = "0.0.2"
3
+ s.version = "0.1.0"
4
4
  s.summary = "Provisioning at a distance"
5
5
  s.description = "Tele is a small provisioning framework that allows you to run bash scripts on remote servers over SSH."
6
6
  s.authors = ["Damian Janowski", "Michel Martens"]
data/test/tele.rb CHANGED
@@ -20,30 +20,22 @@ prepare do
20
20
  `mkdir /tmp/tele`
21
21
  end
22
22
 
23
- test "`tele status` without a config" do
24
- out, err, status = tele("status")
23
+ test "`tele deploy` fails without a config" do
24
+ out, err, status = tele("deploy")
25
25
 
26
26
  assert err =~ /Couldn't find/
27
27
  assert_equal 1, status.exitstatus
28
28
  end
29
29
 
30
- test "`tele status` with missing recipes" do
31
- out, err = tele("status", "-d", "test/.tele.missing-recipes")
30
+ test "`tele deploy` displays missing recipes" do
31
+ out, err = tele("deploy", "-d", "test/.tele.missing-recipes")
32
32
 
33
33
  assert out =~ /db-1/
34
34
  assert out =~ /redis: .*\?/
35
35
  end
36
36
 
37
- test "`tele status`" do
38
- out, err = tele("status", "-d", "test/.tele.simple")
39
-
40
- assert out =~ /db-1/
41
- assert out =~ /redis: .*OK/
42
- assert out =~ /cassandra: .*MISSING/
43
- end
44
-
45
- test "`tele status`" do
46
- out, err = tele("status", "-d", "test/.tele")
37
+ test "`tele deploy` displays layout" do
38
+ out, err = tele("deploy", "-d", "test/.tele")
47
39
 
48
40
  assert err.empty?
49
41
 
@@ -63,14 +55,12 @@ test "`tele status`" do
63
55
  assert parts[2] =~ /unicorn/
64
56
  end
65
57
 
66
- test "`tele install`" do
67
- out, err = tele("install", "-d", "test/.tele.simple")
58
+ test "`tele deploy` runs recipes" do
59
+ out, err = tele("deploy", "-d", "test/.tele.simple")
68
60
 
69
61
  assert out =~ /db-1/
70
62
  assert out =~ /cassandra: .*ERROR/
71
- assert out =~ /cdb: .*DONE/
72
63
  assert out =~ /redis: .*OK/
73
- assert out =~ /tokyo: .*MISSING/
74
64
  end
75
65
 
76
66
  test "`tele init`" do
@@ -82,9 +72,13 @@ test "`tele init`" do
82
72
  Dir.chdir("test/tmp") do
83
73
  out, err = tele("init")
84
74
 
75
+ assert err.empty?
76
+
85
77
  assert File.exists?(".tele")
78
+ assert File.exists?(".tele/recipes")
79
+ assert !File.exists?(".tele/recipes/.empty")
86
80
 
87
- out, err, status = tele("status")
81
+ out, err, status = tele("deploy")
88
82
  assert status.exitstatus == 0
89
83
  end
90
84
  end
@@ -92,5 +86,5 @@ end
92
86
  test "Logging to syslog" do
93
87
  out, err = tele("status", "-d", "test/.tele.simple")
94
88
 
95
- assert `tail -n 20 /var/log/syslog /var/log/system.log 2>/dev/null`["Can't find Cassandra"]
89
+ assert `tail -n 20 /var/log/syslog /var/log/system.log 2>/dev/null`[%r{tele/db-1/cassandra.*Can't find Cassandra}]
96
90
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: tele
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.2
5
+ version: 0.1.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Damian Janowski
@@ -11,8 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2011-04-07 00:00:00 -03:00
15
- default_executable:
14
+ date: 2011-04-28 00:00:00 Z
16
15
  dependencies:
17
16
  - !ruby/object:Gem::Dependency
18
17
  name: clap
@@ -44,7 +43,6 @@ files:
44
43
  - templates/.tele/ssh_config
45
44
  - tele.gemspec
46
45
  - test/tele.rb
47
- has_rdoc: true
48
46
  homepage: http://github.com/djanowski/tele
49
47
  licenses: []
50
48
 
@@ -68,7 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
68
66
  requirements: []
69
67
 
70
68
  rubyforge_project:
71
- rubygems_version: 1.6.2
69
+ rubygems_version: 1.7.2
72
70
  signing_key:
73
71
  specification_version: 3
74
72
  summary: Provisioning at a distance