sshkit 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/.gitignore +2 -0
  2. data/.travis.yml +5 -0
  3. data/.yardoc/checksums +13 -0
  4. data/.yardoc/object_types +0 -0
  5. data/.yardoc/objects/root.dat +0 -0
  6. data/.yardoc/proxy_types +0 -0
  7. data/.yardopts +1 -0
  8. data/CHANGELOG.md +0 -0
  9. data/EXAMPLES.md +167 -0
  10. data/FAQ.md +17 -0
  11. data/Gemfile +2 -0
  12. data/Gemfile.lock +69 -0
  13. data/LICENSE.md +674 -0
  14. data/README.md +181 -0
  15. data/Rakefile +37 -0
  16. data/Vagrantfile +18 -0
  17. data/assets/images/logo.png +0 -0
  18. data/example.rb +70 -0
  19. data/lib/core_ext/array.rb +5 -0
  20. data/lib/core_ext/hash.rb +11 -0
  21. data/lib/sshkit/all.rb +13 -0
  22. data/lib/sshkit/backends/abstract.rb +83 -0
  23. data/lib/sshkit/backends/netssh.rb +82 -0
  24. data/lib/sshkit/backends/printer.rb +28 -0
  25. data/lib/sshkit/command.rb +153 -0
  26. data/lib/sshkit/configuration.rb +29 -0
  27. data/lib/sshkit/connection_manager.rb +93 -0
  28. data/lib/sshkit/dsl.rb +15 -0
  29. data/lib/sshkit/host.rb +151 -0
  30. data/lib/sshkit/version.rb +3 -0
  31. data/lib/sshkit.rb +27 -0
  32. data/sshkit.gemspec +34 -0
  33. data/test/functional/test_connection_manager.rb +17 -0
  34. data/test/functional/test_ssh_server_comes_up_for_functional_tests.rb +23 -0
  35. data/test/helper.rb +125 -0
  36. data/test/integration/backends/test_netssh.rb +99 -0
  37. data/test/unit/backends/test_netssh.rb +14 -0
  38. data/test/unit/backends/test_printer.rb +62 -0
  39. data/test/unit/core_ext/test_string.rb +12 -0
  40. data/test/unit/test_command.rb +113 -0
  41. data/test/unit/test_configuration.rb +47 -0
  42. data/test/unit/test_connection_manager.rb +78 -0
  43. data/test/unit/test_host.rb +65 -0
  44. metadata +301 -0
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ .vagrant
2
+ test/tmp
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - jruby-19mode
5
+ - rbx-19mode
data/.yardoc/checksums ADDED
@@ -0,0 +1,13 @@
1
+ lib/deploy.rb 8f584561b611345114f38176ec53bf00f9d5550f
2
+ lib/deploy/all.rb 9fc0b15f0968612fbd2ffaf0bba9dff6f788e3d1
3
+ lib/deploy/host.rb 777a8deedcdd5b41dceab8773c992bafa5ee9f92
4
+ lib/core_ext/hash.rb b7a0f0d1ab3b83f6b251e2f865ad6fa3766124a0
5
+ lib/deploy/command.rb 1a04acc7d5abd1b288bbea3676c287434849ef05
6
+ lib/core_ext/array.rb 3d495a96a0d1566877bf2ebb70ab9ea10a7d32e1
7
+ lib/deploy/version.rb 30e41688e07f7ee74377aaef147250340df4a3f0
8
+ lib/deploy/configuration.rb 3e9f042e0e9e9860d3950a1406a988586434de16
9
+ lib/deploy/backends/netssh.rb c931441edd28ba7e134b0d3ae2fbf40efb347b81
10
+ lib/deploy/backends/printer.rb db41b51e9624105efd7cb7f1fef426b506ebadaa
11
+ lib/deploy/backends/abstract.rb 74260020d3a6c4913f7a3d9294968e1b2a1304a9
12
+ lib/deploy/connection_manager.rb 28c8ef12a8a5923aeaa497ed02fd22869f57186b
13
+ lib/deploy/dsl.rb a487b4e65ab52955b12a5fe55bda99dec61e16b9
Binary file
Binary file
Binary file
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ --no-private - README.md CHANGELOG.md FAQ.md LICENSE.md EXAMPLES.md
data/CHANGELOG.md ADDED
File without changes
data/EXAMPLES.md ADDED
@@ -0,0 +1,167 @@
1
+ # Usage Examples
2
+
3
+ ## Run a command as a different user
4
+
5
+ on hosts do |host|
6
+ as 'www-data' do
7
+ puts capture(:whoami)
8
+ end
9
+ end
10
+
11
+ ## Run a command in a different directory
12
+
13
+ on hosts do |host|
14
+ within '/var/log' do
15
+ puts capture(:head, '-n5', 'messages')
16
+ end
17
+ end
18
+
19
+ ## Run a command with specific environmental variables
20
+
21
+ on hosts do |host|
22
+ with rack_env: :test do
23
+ puts capture("env | grep RACK_ENV")
24
+ end
25
+ end
26
+
27
+ ## Run a command in a different directory as a different user
28
+
29
+ on hosts do |host|
30
+ as 'www-data' do
31
+ in '/var/log' do
32
+ puts capture(:whoami)
33
+ puts capture(:pwd)
34
+ end
35
+ end
36
+ end
37
+
38
+ This will output:
39
+
40
+ www-data
41
+ /var/log
42
+
43
+ **Note:** This example is a bit misleading, as the `www-data` user doesn't
44
+ have a shell defined, one cannot switch to that user.
45
+
46
+ ## Stack directory nestings:
47
+
48
+ on hosts do
49
+ in "/var" do
50
+ puts capture(:pwd)
51
+ in :log do
52
+ puts capture(:pwd)
53
+ end
54
+ end
55
+ end
56
+
57
+ This will output:
58
+
59
+ /var/
60
+ /var/log
61
+
62
+ The directory paths are joined using `File.join()`, which should correctly
63
+ join parts without forcing the user of the code to care about trailing or
64
+ leading slashes. It may be misleading as the `File.join()` is performed on the
65
+ machine running the code, if that's a Windows box, the paths may be incorrectly
66
+ joined according to the expectations of the machine receiving the commands.
67
+
68
+ ## Do not care about the host block:
69
+
70
+ on hosts do
71
+ # The |host| argument is optional, it will
72
+ # be nil in the block if not passed
73
+ end
74
+
75
+ ## Redirect all output to `/dev/null`
76
+
77
+ SSHKit.config.output = File.open('/dev/null')
78
+
79
+ ## Implement a dirt-simple formatter class:
80
+
81
+ class MyFormatter < SSHKit::Formatter::Abstract
82
+ def write(obj)
83
+ case obj.is_a? SSHKit::Command
84
+ # Do something here, see the SSHKit::Command documentation
85
+ end
86
+ end
87
+ end
88
+
89
+ SSHKit.config.output = MyFormatter.new($stdout)
90
+ SSHKit.config.output = MyFormatter.new(SSHKit.config.output)
91
+ SSHKit.config.output = MyFormatter.new(File.open('log/deploy.log', 'wb'))
92
+
93
+ ## Set a password for a host.
94
+
95
+ host = SSHKit::Host.new('user@example.com')
96
+ host.password = "hackme"
97
+
98
+ on host do |host|
99
+ puts capture(:echo, "I don't care about security!")
100
+ end
101
+
102
+ ## Execute and raise an error if something goes wrong:
103
+
104
+ on hosts do |host|
105
+ execute!(:echo, '"Example Message!" 1>&2; false')
106
+ end
107
+
108
+ This will raise `SSHKit::CommandUncleanExit.new("Example Message!")` which
109
+ will cause the command to abort.
110
+
111
+ ## Do something different on one host, or another depending on a host property:
112
+
113
+ host1 = SSHKit::Host.new 'user@example.com'
114
+ host2 = SSHKit::Host.new 'user@example.org'
115
+
116
+ on hosts do |host|
117
+ target = "/var/www/sites/"
118
+ if host.hostname =~ /org/
119
+ target += "dotorg"
120
+ else
121
+ target += "dotcom"
122
+ end
123
+ execute! :git, :clone, "git@git.#{host.hostname}", target
124
+ end
125
+
126
+ ## Connect to a host in the easiest possible way:
127
+
128
+ on 'example.com' do |host|
129
+ execute :uptime
130
+ end
131
+
132
+ This will resolve the `example.com` hostname into a `SSHKit::Host` object, and
133
+ try to pull up the correct configuration for it.
134
+
135
+
136
+ ## Run a command without it being command-mapped:
137
+
138
+ If the command you attempt to call contains a space character it won't be
139
+ mapped:
140
+
141
+ Command.new(:git, :push, :origin, :master).to_s
142
+ # => /usr/bin/env git push origin master
143
+ # (also: execute(:git, :push, :origin, :master)
144
+
145
+ Command.new("git push origin master").to_s
146
+ # => git push origin master
147
+ # (also: execute("git push origin master"))
148
+
149
+ This can be used to access shell builtins (such as `if` and `test`)
150
+
151
+
152
+ ## Run a command with a heredoc
153
+
154
+ An extension of the behaviour above, if you write a command like this:
155
+
156
+ c = Command.new <<-EOCOMMAND
157
+ if test -d /var/log
158
+ then echo "Directory Exists"
159
+ fi
160
+ EOCOMMAND
161
+ c.to_s
162
+ # => if test -d /var/log; then echo "Directory Exists; fi
163
+ # (also: execute <<- EOCOMMAND........))
164
+
165
+ **Note:** The logic which reformats the script into a oneliner may be naïve, but in all
166
+ known test cases, it works. The key thing is that `if` is not mapped to
167
+ `/usr/bin/env if`, which would break with a syntax error.
data/FAQ.md ADDED
@@ -0,0 +1,17 @@
1
+ ## Is it better than Capistrano?
2
+
3
+ *SSHKit* is designed to solve a different problem than Capistrano. *SSHKit* is
4
+ a toolkit for performing structured commands on groups of servers in a
5
+ repeatable way.
6
+
7
+ It provides concurrency handling, sane error checking and control flow that
8
+ would otherwise be difficult to achive with pure *Net::SSH*.
9
+
10
+ Since *Capistrano v3.0*, *SSHKit* is used by *Capistrano* to communicate with
11
+ backend servers. Whilst Capistrano provides the structure for repeatable
12
+ deployments.
13
+
14
+ ## Production Ready?
15
+
16
+ It's in private Beta use, and the documentation could use more work, but this
17
+ is open source, that's more or less how it works.
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source :rubygems
2
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,69 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ deploy (0.0.1)
5
+ net-ssh
6
+ term-ansicolor
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ ZenTest (4.6.2)
12
+ ansi (1.4.2)
13
+ archive-tar-minitar (0.5.2)
14
+ autotest (4.4.6)
15
+ ZenTest (>= 4.4.1)
16
+ childprocess (0.3.6)
17
+ ffi (~> 1.0, >= 1.0.6)
18
+ columnize (0.3.6)
19
+ debugger (1.2.2)
20
+ columnize (>= 0.3.1)
21
+ debugger-linecache (~> 1.1.1)
22
+ debugger-ruby_core_source (~> 1.1.5)
23
+ debugger-linecache (1.1.2)
24
+ debugger-ruby_core_source (>= 1.1.1)
25
+ debugger-ruby_core_source (1.1.5)
26
+ erubis (2.7.0)
27
+ ffi (1.2.0)
28
+ i18n (0.6.1)
29
+ json (1.5.4)
30
+ log4r (1.1.10)
31
+ metaclass (0.0.1)
32
+ minitest (2.11.3)
33
+ mocha (0.10.5)
34
+ metaclass (~> 0.0.1)
35
+ net-scp (1.0.4)
36
+ net-ssh (>= 1.99.1)
37
+ net-ssh (2.2.2)
38
+ rake (10.0.3)
39
+ redcarpet (2.2.2)
40
+ term-ansicolor (1.0.7)
41
+ turn (0.9.3)
42
+ ansi
43
+ unindent (1.0)
44
+ vagrant (1.0.5)
45
+ archive-tar-minitar (= 0.5.2)
46
+ childprocess (~> 0.3.1)
47
+ erubis (~> 2.7.0)
48
+ i18n (~> 0.6.0)
49
+ json (~> 1.5.1)
50
+ log4r (~> 1.1.9)
51
+ net-scp (~> 1.0.4)
52
+ net-ssh (~> 2.2.2)
53
+ yard (0.8.3)
54
+
55
+ PLATFORMS
56
+ ruby
57
+
58
+ DEPENDENCIES
59
+ autotest
60
+ debugger
61
+ deploy!
62
+ minitest (>= 2.11.3, < 2.12.0)
63
+ mocha
64
+ rake
65
+ redcarpet
66
+ turn
67
+ unindent
68
+ vagrant
69
+ yard