syncwrap 2.1.0 → 2.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5a27d83ab1700ae7818a55ebace8c6c9bb29a99b
4
- data.tar.gz: dfa29eebe123325201c9747dc6386e8f07072672
3
+ metadata.gz: c8747b0974cbb0b64ec21384e0e9f76edce077a6
4
+ data.tar.gz: df3d730eaa4ba91b3fc70ea80a9a74efd0f509e8
5
5
  SHA512:
6
- metadata.gz: b0fe60aaf32e21729609ed41dd05815e1ec09e2718ecaff59e159138dc2e2929f61ebc26f455b52632d64c06bf8f26b9299590a9e0ba257cc87fc86415797b5e
7
- data.tar.gz: a5644f8fd7109d47b9e260236035a612db074383c2c36d6bca1374c30bcb641f054196d4cad9e8821ef7d52126e14b29aed4b79e2874e9f7231546de88f61e97
6
+ metadata.gz: 26144f170e5a161982eec15e0f7b8b901c4b5a3eb2c73a36991aae6eab7a16476a9d0304d6ebf8b72ddd8fab214729563046f259f05b7a00c355a128f00dc1dd
7
+ data.tar.gz: 11f3c42c8f174332aaed9391228c8d97efe19734c67b2023c2a4164e32734a311c42a9b8cac9a5d80c10f0362c435ed7e582f1686624cf1223b42720339065d9
data/History.rdoc CHANGED
@@ -1,3 +1,10 @@
1
+ === 2.1.1 (2014-4-15)
2
+ * Use 'syncwrap-' as tmpdir prefix.
3
+ * Fix Users, RunUser use of useradd, adding -s and -m options, for
4
+ Ubuntu (where bash shell is not default)
5
+ * Add RunUser.run_user_home option; no change in default
6
+ * IyyovDaemon: handle case of non-version related job changes
7
+
1
8
  === 2.1.0 (2014-3-5)
2
9
  * Simplify existing state handling (i.e. Ubuntu.first_apt?, Users
3
10
  :just_created) by introducing SyncWrap::Component#state
data/Manifest.txt CHANGED
@@ -5,6 +5,7 @@ Rakefile
5
5
  bin/syncwrap
6
6
  examples/LAYOUT.rdoc
7
7
  examples/Rakefile
8
+ examples/db_setup.rb
8
9
  examples/ec2.rb
9
10
  examples/hello.rb
10
11
  examples/hello_binding.rb
data/README.rdoc CHANGED
@@ -1,6 +1,7 @@
1
1
  = SyncWrap
2
2
 
3
3
  * http://github.com/dekellum/syncwrap
4
+ * http://rdoc.gravitext.com/syncwrap/
4
5
  * {<img src="https://travis-ci.org/dekellum/syncwrap.png" />}[https://travis-ci.org/dekellum/syncwrap]
5
6
 
6
7
  == Description
data/Rakefile CHANGED
@@ -6,3 +6,21 @@ require 'bundler/setup'
6
6
  require 'rjack-tarpit'
7
7
 
8
8
  RJack::TarPit.new( 'syncwrap' ).define_tasks
9
+
10
+ desc "Upload RDOC to Amazon S3 (rdoc.gravitext.com/syncwrap, Oregon)"
11
+ task :publish_rdoc => [ :clean, :rerdoc ] do
12
+ mime_types = {
13
+ '*.html' => 'text/html; charset=utf-8',
14
+ '*.css' => 'text/css',
15
+ '*.js' => 'text/javascript',
16
+ '*.png' => 'image/png',
17
+ '*.gif' => 'image/gif',
18
+ }
19
+ mime_types.each do |pat, mime_type|
20
+ sh <<-SH
21
+ s3cmd sync -P --exclude '*.*' --include '#{pat}' \
22
+ -m '#{mime_type}' \
23
+ doc/ s3://rdoc.gravitext.com/syncwrap/
24
+ SH
25
+ end
26
+ end
data/examples/LAYOUT.rdoc CHANGED
@@ -16,6 +16,7 @@ by multiple examples.
16
16
  Here is what a complete end-user project setup might look like:
17
17
 
18
18
  deploy/
19
+ ├── Gemfile
19
20
  ├── lib/
20
21
  │ └── my_component.rb
21
22
  ├── .gitignore
@@ -24,23 +25,33 @@ Here is what a complete end-user project setup might look like:
24
25
  │ └── sec.pem
25
26
  ├── sync.rb
26
27
  └── sync/
27
- ├── home
28
- │ └── bob
29
- │ └── .ssh
28
+ ├── home/
29
+ │ └── bob/
30
+ │ └── .ssh/
30
31
  │ └── authorized_keys
31
- └── my/
32
- └── config.rb.erb
32
+ └── var/
33
+ └── my_server/
34
+ └── config.rb.erb
33
35
 
34
36
  sync.rb:: The aforementioned default named sync-file, containing
35
37
  roles, components, hosts, and possibly profiles.
36
38
 
37
39
  sync/:: The default named sync root containing a tree of static files
38
- and templates for pushing to hosts. See the rput.rb example
39
- for usage. The local sync root can contain overrides to the
40
- syncwrap gem provided files/directories as well as new
41
- files. Home directories and in particular
42
- .ssh/authorized_keys is commonly used with the
43
- SyncWrap::Users component.
40
+ and templates for pushing to hosts via
41
+ SyncWrap::Component#rput. The sub-directory structure
42
+ generally mimics the rput remote locations. See the rput.rb
43
+ example for usage. The local sync root can contain overrides
44
+ to the syncwrap gem provided files/directories as well as new
45
+ files.
46
+
47
+ sync/home/:: Default location for SyncWrap::Users provisioned
48
+ developer home directories (for ssh authorized_keys at
49
+ minimum).
50
+
51
+ sync/var/:: Conventional location for daemon-component configuration
52
+ or other deployed files and templates (*.erb). Note that
53
+ with SyncWrap::RunUser at least, this maps by default to
54
+ the remote /var/local/runr directory.
44
55
 
45
56
  lib/:: Place project-specific components here. Once these are
46
57
  non-trivial its nicer to `require_relative` them into the
@@ -63,8 +74,9 @@ private/:: This directory is for sensitive files like credentials that
63
74
  ...which ignores and avoids check-in by mistake of any so
64
75
  named sub-directory and its contents.
65
76
 
77
+ Gemfile:: Include a bundler Gemfile for precise version control of all
78
+ gems involved, including syncwrap.
79
+
66
80
  Without the private/ directories and sync.rb file, and adjusting lib/
67
81
  accordingly, you could also package this as a gem. This makes it easy
68
- to reuse components and files/templates across projects. Include a
69
- bundler Gemfile in each deploy directory for precise version control
70
- of all gems involved, including syncwrap.
82
+ to reuse components and files/templates across projects.
@@ -0,0 +1,16 @@
1
+ class MyDatabase < SyncWrap::Component
2
+ def install
3
+ %w[ bob joanne ].each { |u| pg_create_user( u ) }
4
+ end
5
+
6
+ def pg_create_user( user, flags=[] )
7
+ sql_test = "SELECT count(*) FROM pg_user WHERE usename = '#{user}'"
8
+ sh( <<-SH, user: 'postgres' )
9
+ if [[ $(psql -tA -c "#{sql_test}") == "0" ]]; then
10
+ createuser #{flags.join ' '} #{user}
11
+ fi
12
+ SH
13
+ end
14
+ end
15
+
16
+ host 'localhost', MyDatabase.new
@@ -286,7 +286,7 @@ module SyncWrap
286
286
  echo 'Defaults:#{user} !requiretty' >> /etc/sudoers.d/#{user}
287
287
  chmod 440 /etc/sudoers.d/#{user}
288
288
  SH
289
- script.split( "\n" ).map { |l| l.strip }.join( "\n" )
289
+ script.split( "\n" ).map( &:strip ).join( "\n" )
290
290
  end
291
291
 
292
292
  end
@@ -333,7 +333,7 @@ module SyncWrap
333
333
  end
334
334
 
335
335
  def decode_roles( roles )
336
- ( roles || "" ).split( /\s+/ ).map { |r| r.to_sym }
336
+ ( roles || "" ).split( /\s+/ ).map( &:to_sym )
337
337
  end
338
338
 
339
339
  # Wait until block returns truthy, sleeping for freq seconds
data/lib/syncwrap/base.rb CHANGED
@@ -15,7 +15,7 @@
15
15
  #++
16
16
 
17
17
  module SyncWrap
18
- VERSION='2.1.0'
18
+ VERSION='2.1.1'
19
19
 
20
20
  GEM_ROOT = File.dirname(File.dirname(File.dirname(__FILE__))) # :nodoc:
21
21
  end
data/lib/syncwrap/cli.rb CHANGED
@@ -282,10 +282,10 @@ TEXT
282
282
 
283
283
  def list_roles( hosts, multi )
284
284
  puts "Included Roles:" if multi
285
- roles = hosts.map { |h| h.roles }.inject([],:|)
285
+ roles = hosts.map( &:roles ).inject([],:|)
286
286
  table = roles.map do |role|
287
287
  row = [ ':' + role.to_s ]
288
- classes = space.role( role ).map { |c| c.class }
288
+ classes = space.role( role ).map( &:class )
289
289
  row << short_class_names( classes ).join(' ')
290
290
  end
291
291
  print_table( table )
@@ -309,7 +309,7 @@ TEXT
309
309
  end
310
310
 
311
311
  def print_table( table )
312
- max_columns = table.map { |r| r.count }.max || 0
312
+ max_columns = table.map( &:count ).max || 0
313
313
  col_widths = max_columns.times.map do |i|
314
314
  table.map { |row| row[i] && row[i].length }.compact.max
315
315
  end
@@ -70,24 +70,26 @@ module SyncWrap
70
70
  def standard_install
71
71
 
72
72
  create_service_dir( name, instance )
73
- changes = rput_service_config
73
+ conf_changes = rput_service_config
74
74
 
75
- # Shorten if the desired versioned process is already running.
76
75
  pid, ver = capture_running_version( name, instance )
77
- if ver != version
78
- gem_install( gem_name, version: version )
79
- changes += rput( job_source,
80
- "#{iyyov_run_dir}/jobs.d/#{name_instance}.rb",
81
- user: run_user )
82
- changes += iyyov_install_jobs
83
- end
76
+
77
+ gem_install( gem_name, version: version ) if ver != version
78
+
79
+ # The job_source may contain more than just this daemon
80
+ # (i.e. additional tasks, etc.) Even if this is the
81
+ # default/daemon.rb.erb, it might have just been changed to
82
+ # that. So go ahead an rput in any case.
83
+ job_changes = rput( job_source,
84
+ "#{iyyov_run_dir}/jobs.d/#{name_instance}.rb",
85
+ user: run_user )
86
+ job_changes += iyyov_install_jobs
84
87
 
85
88
  # If we found a daemon pid then kill if either:
86
89
  #
87
- # (1) the version is the same (i.e no other signal via updates
88
- # above for Iyyov) but there was a config change or hashdot
89
- # was updated (i.e. new jruby version). In this case Iyyov
90
- # should be up to restart the daemon.
90
+ # (1) the version is the same but there was a config change or
91
+ # hashdot was updated (i.e. new jruby version). In this case
92
+ # Iyyov should be up to restart the daemon.
91
93
  #
92
94
  # (2) We are :imaging, in which case we want a graceful
93
95
  # shutdown. In this case Iyyov should have already been kill
@@ -97,13 +99,13 @@ module SyncWrap
97
99
  # already stopped (i.e. crashed, etc) between above pid capture
98
100
  # and the kill. Ignore kill failures.
99
101
  if pid &&
100
- ( ( ver == version && ( !changes.empty? ||
102
+ ( ( ver == version && ( !conf_changes.empty? ||
101
103
  state[ :hashdot_updated ] ) ) ||
102
104
  state[ :imaging ] )
103
105
  rudo( "kill #{pid} || true" )
104
106
  end
105
107
 
106
- changes
108
+ conf_changes + job_changes
107
109
  end
108
110
 
109
111
  def rput_service_config
@@ -109,7 +109,7 @@ module SyncWrap
109
109
  alias :jruby_gem_install :gem_install
110
110
 
111
111
  def min_deps_supported?
112
- varray = jruby_version.split('.').map { |n| n.to_i }
112
+ varray = jruby_version.split('.').map( &:to_i )
113
113
  ( varray <=> [1, 7, 5] ) >= 0
114
114
  end
115
115
 
@@ -58,10 +58,11 @@ module SyncWrap
58
58
  attr_accessor :raid_chunk
59
59
 
60
60
  # A table of [ slice, path (,name) ] rows where; slice is a
61
- # floating point ratio in range (0.0,1.0], path is the mount
62
- # point, and name is the lvm name, defaulting if omitted to the
63
- # last path element. The sum of all slice values in the table
64
- # should be 1.0. Default: [ [ 1.0, '/data' ] ]
61
+ # Numeric in range (0.0..1.0), path is the mount point, and name
62
+ # is the lvm name, defaulting if omitted to the last path
63
+ # element. The sum of all slice values in the table should be 1.0,
64
+ # unless unallocated space is desired.
65
+ # Default: [ [ 1.0, '/data' ] ]
65
66
  attr_accessor :lvm_volumes
66
67
 
67
68
  # File System Type. Default: 'ext4'
@@ -154,7 +155,6 @@ module SyncWrap
154
155
 
155
156
  def create_raid( md )
156
157
  rlevel = raid_level || default_raid_level
157
-
158
158
  sudo <<-SH
159
159
  mdadm --create #{md} --level=#{rlevel} --chunk=#{raid_chunk} \
160
160
  --raid-devices=#{raw_devices.count} #{raw_devices.join ' '}
@@ -25,7 +25,7 @@ module SyncWrap
25
25
  # A user for running deployed daemons, jobs (default: 'runr')
26
26
  attr_accessor :run_user
27
27
 
28
- # A group for running (default: nil -> same as run_user)
28
+ # A group for running (default: nil -> same as #run_user)
29
29
  attr_accessor :run_group
30
30
 
31
31
  # Root directory for persistent data and logs
@@ -36,11 +36,19 @@ module SyncWrap
36
36
  @run_dir || "/var/local/#{run_user}"
37
37
  end
38
38
 
39
+ # Home directory for the #run_user
40
+ # (default: nil -> unspecified)
41
+ attr_writer :run_user_home
42
+
43
+ def run_user_home
44
+ @run_user_home
45
+ end
46
+
39
47
  def initialize( opts = {} )
40
48
  @run_user = 'runr'
41
49
  @run_group = nil
42
50
  @run_dir = nil
43
-
51
+ @run_user_home = nil
44
52
  super
45
53
  end
46
54
 
@@ -52,14 +60,13 @@ module SyncWrap
52
60
  # Create run_user if not already present
53
61
  def create_run_user
54
62
  sudo( "if ! id #{run_user} >/dev/null 2>&1; then", close: "fi" ) do
63
+ user_opts = "-c 'Run User' -s /bin/bash"
64
+ user_opts += " -d #{run_user_home}" if run_user_home
55
65
  if run_group && run_group != run_user
56
- sudo <<-SH
57
- groupadd -f #{run_group}
58
- useradd -g #{run_group} #{run_user}
59
- SH
60
- else
61
- sudo "useradd #{run_user}"
66
+ sudo "groupadd -f #{run_group}"
67
+ user_opts += " -g #{run_group}"
62
68
  end
69
+ sudo "useradd #{user_opts} #{run_user}"
63
70
  end
64
71
  end
65
72
 
@@ -135,7 +135,7 @@ module SyncWrap
135
135
  def create_user( user )
136
136
  sudo <<-SH
137
137
  if ! id #{user} >/dev/null 2>&1; then
138
- useradd #{user}
138
+ useradd -s /bin/bash -m #{user}
139
139
  fi
140
140
  SH
141
141
  end
@@ -273,7 +273,11 @@ module SyncWrap
273
273
  end
274
274
 
275
275
  def []( key )
276
- @props[ key ] || @host[ key ]
276
+ if @props.has_key?( key )
277
+ @props[ key ]
278
+ else
279
+ @host[ key ]
280
+ end
277
281
  end
278
282
 
279
283
  def []=( key, val )
@@ -159,7 +159,7 @@ module SyncWrap
159
159
  def process_templates( srcs, opts ) # :doc:
160
160
  bnd = opts[ :erb_binding ] or raise "required :erb_binding param missing"
161
161
  erb_mode = opts[ :erb_mode ] || '<>' #Trim new line on "<% ... %>\n"
162
- mktmpdir( 'syncwrap' ) do |tmp_dir|
162
+ mktmpdir( 'syncwrap-' ) do |tmp_dir|
163
163
  processed_sources = []
164
164
  out_dir = File.join( tmp_dir, 'd' ) #for default perms
165
165
  srcs.each do |src|
@@ -197,7 +197,7 @@ module SyncWrap
197
197
  FileUtils.mkdir_p( newdir, mode: 0700 )
198
198
  ENV['TMPDIR'] = newdir
199
199
  end
200
- Dir.mktmpdir( 'syncwrap' ) do |tmp_dir|
200
+ Dir.mktmpdir( prefix ) do |tmp_dir|
201
201
  yield tmp_dir
202
202
  end
203
203
  ensure
data/lib/syncwrap.rb CHANGED
@@ -188,9 +188,9 @@ module SyncWrap
188
188
  # roles, currently contained by the specified hosts or all hosts.
189
189
  def component_classes( hs = hosts )
190
190
  hs.
191
- map { |h| h.components }.
191
+ map( &:components ).
192
192
  flatten.
193
- map { |comp| comp.class }.
193
+ map( &:class ).
194
194
  uniq
195
195
  end
196
196
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: syncwrap
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Kellum
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-05 00:00:00.000000000 Z
11
+ date: 2014-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: term-ansicolor
@@ -170,6 +170,7 @@ files:
170
170
  - bin/syncwrap
171
171
  - examples/LAYOUT.rdoc
172
172
  - examples/Rakefile
173
+ - examples/db_setup.rb
173
174
  - examples/ec2.rb
174
175
  - examples/hello.rb
175
176
  - examples/hello_binding.rb