vanagon 0.19.1 → 0.20.0

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
  SHA256:
3
- metadata.gz: e5dc9e0c896685503aafc10ec2bae7531dd36299289a7b07850db2ec5547f32c
4
- data.tar.gz: 8ec86222166a7d4ecd99026c3ca0e46793f2da2b3f284eafe024236bc2449d56
3
+ metadata.gz: 6fb1135d000a2b468d3a998b6ef1e7547d26f835d06b67f2ba502fb710d1f06b
4
+ data.tar.gz: ffac33c290bc103a851d8bc9f468ec8a838465ac0e12125446c86a2b22cbde9e
5
5
  SHA512:
6
- metadata.gz: 54be38ffc28ceb63f22de1dd5912c823881f7d5c0188733960ddfa2c170c959174b181491db92007f8319a762f22cef0ed417ecf44bf3ad7f1305c18e7b89e56
7
- data.tar.gz: ea4ff7c8f3ed9ebafc4e9fefbb689464431ff22299fb7c4bc9d1582451c249dba8628c28426b2d9cd9c46526a4e9be9ded30c060bbe70acb5b2d6cb3021174b0
6
+ metadata.gz: 388e8520c4231c89b4170d3f99ac590caea60e98ebe5ccd2a0b5cee159c595b80b897d45c91dfda3b063da2c636420ae1c8e96a52eb87b17fef1d99d8848ba15
7
+ data.tar.gz: 1ca438d9b68285bfcf8b269d1fe8217736bad75d868ecb7452fac4a499dab15d3eae8200ab9a4860763c0a5217335f17b4f7561ce58c0984f331356be594607a
data/README.md CHANGED
@@ -197,8 +197,8 @@ Port of the system where redis is running. Defaults to *6379*.
197
197
  ##### `VANAGON_USE_MIRRORS`
198
198
  Controls whether component sources are downloaded directly from upstream URLs
199
199
  or from configured mirrors. Most Puppet projects using Vanagon default to
200
- fetching components from internal mirrors. Set this variable to `n` when
201
- building outside of the Puppet private network to download directly from
200
+ fetching components from internal mirrors. Set this variable to `n` or `false`
201
+ when building outside of the Puppet private network to download directly from
202
202
  upstream sources.
203
203
 
204
204
  ##### `VANAGON_RETRY_COUNT`
@@ -180,6 +180,7 @@ class Vanagon
180
180
  @preremove_actions = []
181
181
  @postremove_actions = []
182
182
  @install_only = false
183
+ @service = []
183
184
  end
184
185
 
185
186
  # Adds the given file to the list of files and returns @files.
@@ -305,7 +306,7 @@ class Vanagon
305
306
  def get_source(workdir) # rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity
306
307
  opts = options.merge({ workdir: workdir })
307
308
  if url || !mirrors.empty?
308
- if ENV['VANAGON_USE_MIRRORS'] == 'n'
309
+ if ENV['VANAGON_USE_MIRRORS'] == 'n' or ENV['VANAGON_USE_MIRRORS'] == 'false'
309
310
  fetch_url(opts)
310
311
  else
311
312
  fetch_mirrors(opts) || fetch_url(opts)
@@ -168,37 +168,42 @@ class Vanagon
168
168
  # @param service_file [String] path to the service file relative to the source
169
169
  # @param default_file [String] path to the default file relative to the source
170
170
  # @param service_name [String] name of the service
171
- # @param service_type [String] type of the service (network, application, system, etc)
172
- # @param link_target [String] executable service file should be linked to
173
- def install_service(service_file, default_file = nil, service_name = @component.name, service_type: nil, link_target: nil) # rubocop:disable Metrics/AbcSize
174
- case @component.platform.servicetype
171
+ # @param options optional extra parameters
172
+ # service_type [String] type of the service (network, application, system, etc)
173
+ # init_system [String] the init system on which to install service (sysv, systemd)
174
+ # link_target [String] executable service file should be linked to
175
+ def install_service(service_file, default_file = nil, service_name = @component.name, **options) # rubocop:disable Metrics/AbcSize
176
+ init_system = options[:init_system] || @component.platform.servicetype
177
+ servicedir = @component.platform.get_service_dir(init_system)
178
+
179
+ case init_system
175
180
  when "sysv"
176
- target_service_file = File.join(@component.platform.servicedir, service_name)
181
+ target_service_file = File.join(servicedir, service_name)
177
182
  target_default_file = File.join(@component.platform.defaultdir, service_name)
178
183
  target_mode = '0755'
179
184
  default_mode = '0644'
180
185
  when "systemd"
181
- target_service_file = File.join(@component.platform.servicedir, "#{service_name}.service")
186
+ target_service_file = File.join(servicedir, "#{service_name}.service")
182
187
  target_default_file = File.join(@component.platform.defaultdir, service_name)
183
188
  target_mode = '0644'
184
189
  default_mode = '0644'
185
190
  when "launchd"
186
- target_service_file = File.join(@component.platform.servicedir, "#{service_name}.plist")
191
+ target_service_file = File.join(servicedir, "#{service_name}.plist")
187
192
  target_mode = '0644'
188
193
  default_mode = '0644'
189
194
  when "smf"
190
195
  # modify version in smf manifest so service gets restarted after package upgrade
191
196
  @component.install << %{#{@component.platform.sed} -ri 's/(<service.*version=)(".*")/\\1"#{Time.now.to_i}"/' #{service_file}}
192
- target_service_file = File.join(@component.platform.servicedir, service_type.to_s, "#{service_name}.xml")
197
+ target_service_file = File.join(servicedir, options[:service_type].to_s, "#{service_name}.xml")
193
198
  target_default_file = File.join(@component.platform.defaultdir, service_name)
194
199
  target_mode = '0644'
195
200
  default_mode = '0755'
196
201
  when "aix"
197
- @component.service = OpenStruct.new(:name => service_name, :service_command => File.read(service_file).chomp)
202
+ @component.service << OpenStruct.new(:name => service_name, :service_command => File.read(service_file).chomp)
198
203
  # Return here because there is no file to install, just a string read in
199
204
  return
200
205
  when "windows"
201
- @component.service = OpenStruct.new(\
206
+ @component.service << OpenStruct.new(\
202
207
  :bindir_id => "#{service_name.gsub(/[^A-Za-z0-9]/, '').upcase}BINDIR", \
203
208
  :service_file => service_file, \
204
209
  :component_group_id => "#{service_name.gsub(/[^A-Za-z0-9]/, '')}Component"\
@@ -206,13 +211,13 @@ class Vanagon
206
211
  # return here as we are just collecting the name of the service file to put into the harvest filter list.
207
212
  return
208
213
  else
209
- fail "Don't know how to install the #{@component.platform.servicetype}. Please teach #install_service how to do this."
214
+ fail "Don't know how to install the #{init_system}. Please teach #install_service how to do this."
210
215
  end
211
216
 
212
217
  # Install the service and default files
213
- if link_target
214
- install_file(service_file, link_target, mode: target_mode)
215
- link link_target, target_service_file
218
+ if options[:link_target]
219
+ install_file(service_file, options[:link_target], mode: target_mode)
220
+ link options[:link_target], target_service_file
216
221
  else
217
222
  install_file(service_file, target_service_file, mode: target_mode)
218
223
  end
@@ -223,7 +228,8 @@ class Vanagon
223
228
  end
224
229
 
225
230
  # Register the service for use in packaging
226
- @component.service = OpenStruct.new(:name => service_name, :service_file => target_service_file, :type => service_type)
231
+ @component.service << OpenStruct.new(:name => service_name, :service_file => target_service_file,
232
+ :type => options[:service_type], :init_system => init_system)
227
233
  end
228
234
 
229
235
  # Copies a file from source to target during the install phase of the component
@@ -26,14 +26,38 @@ class Vanagon
26
26
  # git command has failed. Useful in instances where a URL
27
27
  # prompts for credentials despite not being a git remote
28
28
  # @return [Boolean] whether #url is a valid Git repo or not
29
+
30
+ # [RE-13837] This ought to be the way to do this. Unfortunately,
31
+ # there's a bug in Git.ls_remote that when ssh prints something like
32
+ # Warning: Permanently added 'github.com,192.30.255.113' (RSA)
33
+ # Git.ls_remote attempts to parse it as actual git output and fails
34
+ # with: NoMethodError: undefined method `split' for nil:NilClass
35
+ #
36
+ # We'll work around that case by calling 'git ls-remote' directly ourselves.
37
+ #
38
+ # I'm leaving in the broken version here for a time when the ruby-git library
39
+ # is fixed.
40
+
41
+ #def valid_remote?(url, timeout = 0)
42
+ # Timeout.timeout(timeout) do
43
+ # !!::Git.ls_remote(url)
44
+ # end
45
+ #rescue ::Git::GitExecuteError
46
+ # false
47
+ #rescue Timeout::Error
48
+ # false
49
+ #end
50
+
29
51
  def valid_remote?(url, timeout = 0)
30
52
  Timeout.timeout(timeout) do
31
- !!::Git.ls_remote(url)
53
+ Vanagon::Utilities.local_command("git ls-remote #{url} > /dev/null 2>&1")
54
+ return false unless $?.exitstatus.zero?
55
+ return true
32
56
  end
33
- rescue ::Git::GitExecuteError
34
- false
35
57
  rescue Timeout::Error
36
- false
58
+ return false
59
+ rescue RuntimeError
60
+ return false
37
61
  end
38
62
  end
39
63
 
@@ -33,6 +33,9 @@ class Vanagon
33
33
  # Where does a given platform expect to find init scripts/service files?
34
34
  # e.g. /etc/init.d, /usr/lib/systemd/system
35
35
  attr_accessor :servicedir
36
+ # Array of OpenStructs containing the servicetype and the corresponding
37
+ # servicedir
38
+ attr_accessor :servicetypes
36
39
  # Where does a given platform's init system expect to find
37
40
  # something resembling 'defaults' files. Most likely to apply
38
41
  # to Linux systems that use SysV-ish, upstart, or systemd init systems.
@@ -245,6 +248,7 @@ class Vanagon
245
248
  # Our first attempt at defining metadata about a platform
246
249
  @cross_compiled ||= false
247
250
  @valid_operators ||= ['<', '>', '<=', '>=', '=']
251
+ @servicetypes = []
248
252
  end
249
253
 
250
254
  def shell # rubocop:disable Lint/DuplicateMethods
@@ -553,5 +557,33 @@ class Vanagon
553
557
  def validate_operator(operator_string)
554
558
  valid_operators.include?(operator_string)
555
559
  end
560
+
561
+ # Get all configured service types (added through plat.servicetype)
562
+ # @return array of service types, empty array if none have been configured
563
+ def get_service_types
564
+ if @servicetypes.any?
565
+ @servicetypes.flat_map(&:servicetype).compact
566
+ elsif @servicetype
567
+ [@servicetype]
568
+ else
569
+ []
570
+ end
571
+ end
572
+
573
+ # Get configured service dir (added through plat.servicedir, or plat.servicetype 'foo', servicedir: 'bar')
574
+ # @param servicetype the service type you want the service dir for (optional)
575
+ # @raises VanagonError if more than one service dir is found
576
+ def get_service_dir(servicetype = '')
577
+ if @servicetypes.empty?
578
+ return @servicedir
579
+ end
580
+ servicedir = @servicetypes.select { |s| s.servicetype.include?(servicetype) }.flat_map(&:servicedir).compact
581
+
582
+ if servicedir.size > 1
583
+ raise Vanagon::Error, "You can only have one service dir for each service type. Found '#{servicedir.join(',')}' for service type #{servicetype}"
584
+ end
585
+
586
+ servicedir.first
587
+ end
556
588
  end
557
589
  end
@@ -10,6 +10,7 @@ require 'vanagon/platform/solaris_11'
10
10
  require 'vanagon/platform/windows'
11
11
  require 'vanagon/logger'
12
12
  require 'securerandom'
13
+ require 'ostruct'
13
14
  require 'uri'
14
15
 
15
16
  class Vanagon
@@ -219,6 +220,11 @@ class Vanagon
219
220
  # @param dir [String] Directory where service files live on the platform
220
221
  def servicedir(dir)
221
222
  @platform.servicedir = dir
223
+
224
+ # Add to the servicetypes array if we haven't already
225
+ if @platform.servicetype && @platform.servicedir && @platform.servicetypes.select { |s| s.servicetype == @platform.servicetype }.empty?
226
+ @platform.servicetypes << OpenStruct.new(:servicetype => @platform.servicetype, :servicedir => @platform.servicedir)
227
+ end
222
228
  end
223
229
 
224
230
  # Set the directory where default or sysconfig files live for the platform
@@ -231,8 +237,18 @@ class Vanagon
231
237
  # Set the servicetype for the platform so that services can be installed correctly.
232
238
  #
233
239
  # @param type [String] service type for the platform ('sysv' for example)
234
- def servicetype(type)
235
- @platform.servicetype = type
240
+ # @param servicedir [String] service dir for this platform and service type ('/etc/init.d' for example). Optional.
241
+ def servicetype(type, servicedir: nil) # rubocop:disable Metrics/AbcSize
242
+ if servicedir
243
+ @platform.servicetypes << OpenStruct.new(:servicetype => type, :servicedir => servicedir)
244
+ else
245
+ @platform.servicetype = type
246
+ end
247
+
248
+ # Add to the servicetypes array if we haven't already
249
+ if @platform.servicetype && @platform.servicedir && @platform.servicetypes.select { |s| s.servicetype == @platform.servicetype }.empty?
250
+ @platform.servicetypes << OpenStruct.new(:servicetype => @platform.servicetype, :servicedir => @platform.servicedir)
251
+ end
236
252
  end
237
253
 
238
254
  # Set the list of possible host to perform a build on (when not using
@@ -351,10 +351,14 @@ class Vanagon
351
351
  # will return nil
352
352
  #
353
353
  # @param [string] name of service to grab
354
- # @return [@component.service obj] specific service
354
+ # @return [@component.service obj] specific service, or array of services
355
+ # if there's more than one
355
356
  def get_service(name)
356
357
  components.each do |component|
357
358
  if component.name == name
359
+ if component.service.size == 1
360
+ return component.service.first
361
+ end
358
362
  return component.service
359
363
  end
360
364
  end
@@ -2,18 +2,29 @@
2
2
  <%- get_services.each do |service| -%>
3
3
  # switch based on systemd vs systemv
4
4
  #
5
- <%- if @platform.servicetype == "systemd" -%>
6
- if [ -z "$2" ]; then
7
- systemctl enable <%= service.name %>.service >/dev/null || :
8
- else
9
- systemctl try-restart <%= service.name %>.service >/dev/null || :
5
+ <%- if service.init_system.nil? || service.init_system.eql?('systemd') -%>
6
+ if [ -f '/proc/1/comm' ]; then
7
+ init_comm=`cat /proc/1/comm`
8
+ if [ "$init_comm" = "systemd" ]; then
9
+ if [ -z "$2" ]; then
10
+ systemctl enable <%= service.name %>.service >/dev/null || :
11
+ else
12
+ systemctl try-restart <%= service.name %>.service >/dev/null || :
13
+ fi
14
+ fi
10
15
  fi
11
- <%- elsif @platform.servicetype == "sysv" -%>
12
- if [ -x "<%= service.service_file %>" ]; then
13
- update-rc.d <%= service.name %> defaults > /dev/null
16
+ <%- end -%>
17
+ <%- if service.init_system.nil? || service.init_system.eql?('sysv') -%>
18
+ if [ -f '/proc/1/comm' ]; then
19
+ init_comm=`cat /proc/1/comm`
20
+ if [ "$init_comm" = "init" ]; then
21
+ if [ -x "<%= service.service_file %>" ]; then
22
+ update-rc.d <%= service.name %> defaults > /dev/null
14
23
 
15
- if [ -n "$2" ]; then
16
- invoke-rc.d <%= service.name %> condrestart || true
24
+ if [ -n "$2" ]; then
25
+ invoke-rc.d <%= service.name %> condrestart || true
26
+ fi
27
+ fi
17
28
  fi
18
29
  fi
19
30
  <%- end -%>
@@ -27,17 +38,17 @@ fi
27
38
 
28
39
  # Set up any specific permissions needed...
29
40
  <%- (get_directories + get_configfiles + get_files).select { |pathname| pathname.has_overrides? }.uniq.each do |file_or_directory| -%>
30
- <%= "chmod '#{file_or_directory.mode}' '#{file_or_directory.path}'" if file_or_directory.mode %>
41
+ <%= "chmod '#{file_or_directory.mode}' '#{file_or_directory.path}' &>/dev/null ||:" if file_or_directory.mode %>
31
42
  <%- if file_or_directory.owner -%>
32
43
  if getent passwd '<%= file_or_directory.owner %>' &> /dev/null; then
33
- chown '<%= file_or_directory.owner %>' '<%= file_or_directory.path %>'
44
+ chown '<%= file_or_directory.owner %>' '<%= file_or_directory.path %>' &>/dev/null ||:
34
45
  else
35
46
  echo "Error updating '<%= file_or_directory.path %>': user '<%= file_or_directory.owner %>' does not exist."
36
47
  fi
37
48
  <%- end -%>
38
49
  <%- if file_or_directory.group -%>
39
50
  if getent group '<%= file_or_directory.group %>' &> /dev/null; then
40
- chgrp '<%= file_or_directory.group %>' '<%= file_or_directory.path %>'
51
+ chgrp '<%= file_or_directory.group %>' '<%= file_or_directory.path %>' &>/dev/null ||:
41
52
  else
42
53
  echo "Error updating '<%= file_or_directory.path %>': group '<%= file_or_directory.group %>' does not exist."
43
54
  fi
@@ -13,11 +13,14 @@ fi
13
13
  <%- get_services.each do |service| -%>
14
14
  # switch based on systemd vs systemv
15
15
  #
16
- <%- if @platform.servicetype == "systemd" -%>
17
- systemctl daemon-reload >/dev/null 2>&1 || :
18
- <%- elsif @platform.servicetype == "sysv" -%>
19
- if [ "$1" = "purge" ] ; then
20
- update-rc.d <%= service.name %> remove > /dev/null
16
+ if [ -f '/proc/1/comm' ]; then
17
+ init_comm=`cat /proc/1/comm`
18
+ if [ "$init_comm" = "systemd" ]; then
19
+ systemctl daemon-reload >/dev/null 2>&1 || :
20
+ else
21
+ if [ "$1" = "purge" ] ; then
22
+ update-rc.d <%= service.name %> remove > /dev/null
23
+ fi
24
+ fi
21
25
  fi
22
- <%- end -%>
23
26
  <%- end -%>
@@ -13,15 +13,25 @@ fi
13
13
  <%- get_services.each do |service| -%>
14
14
  # switch based on systemd vs systemv
15
15
  #
16
- <%- if @platform.servicetype == "systemd" -%>
17
- if [ "$1" = remove ]; then
18
- systemctl --no-reload disable <%= service.name %>.service > /dev/null 2>&1 || :
19
- systemctl stop <%= service.name %>.service > /dev/null 2>&1 || :
16
+ <%- if service.init_system.nil? || service.init_system.eql?('systemd') -%>
17
+ if [ -f '/proc/1/comm' ]; then
18
+ init_comm=`cat /proc/1/comm`
19
+ if [ "$init_comm" = "systemd" ]; then
20
+ if [ "$1" = remove ]; then
21
+ systemctl --no-reload disable <%= service.name %>.service > /dev/null 2>&1 || :
22
+ systemctl stop <%= service.name %>.service > /dev/null 2>&1 || :
23
+ fi
24
+ fi
20
25
  fi
21
-
22
- <%- elsif @platform.servicetype == "sysv" -%>
23
- if [ -x "<%= service.service_file %>" ] && [ "$1" = remove ]; then
24
- invoke-rc.d <%= service.name %> stop || true
26
+ <%- end -%>
27
+ <%- if service.init_system.nil? || service.init_system.eql?('sysv') -%>
28
+ if [ -f '/proc/1/comm' ]; then
29
+ init_comm=`cat /proc/1/comm`
30
+ if [ "$init_comm" = "init" ]; then
31
+ if [ -x "<%= service.service_file %>" ] && [ "$1" = remove ]; then
32
+ invoke-rc.d <%= service.name %> stop || true
33
+ fi
34
+ fi
25
35
  fi
26
36
  <%- end -%>
27
37
  <%- end -%>
@@ -98,7 +98,7 @@ Requires(post): /bin/touch
98
98
  <%- end -%>
99
99
 
100
100
  <%- if has_services? -%>
101
- <%- if @platform.servicetype == "systemd" -%>
101
+ <%- if @platform.get_service_types.include?("systemd") -%>
102
102
  <%- if @platform.is_sles? -%>
103
103
  BuildRequires: systemd
104
104
  %{?systemd_requires}
@@ -108,7 +108,7 @@ Requires(post): systemd
108
108
  Requires(preun): systemd
109
109
  Requires(postun): systemd
110
110
  <%- end -%>
111
- <%- elsif @platform.servicetype == "sysv" -%>
111
+ <%- elsif @platform.get_service_types.include?("sysv") -%>
112
112
  <%- if @platform.is_sles? -%>
113
113
  Requires: aaa_base
114
114
  <%- elsif @platform.is_linux? -%>
@@ -256,15 +256,15 @@ fi
256
256
  <%- get_services.each do |service| -%>
257
257
  # switch based on systemd vs systemv vs smf vs aix
258
258
  #
259
- <%- if @platform.servicetype == "systemd" -%>
259
+ <%- if @platform.get_service_types.include?("systemd") -%>
260
260
  <%- if @platform.is_sles? -%>
261
261
  %service_add_post <%= service.name %>.service
262
262
  <%- else -%>
263
263
  %systemd_post <%= service.name %>.service
264
264
  <%- end -%>
265
- <%- elsif @platform.servicetype == "sysv" -%>
265
+ <%- elsif @platform.get_service_types.include?("sysv") -%>
266
266
  chkconfig --add <%= service.name %> >/dev/null 2>&1 || :
267
- <%- elsif @platform.servicetype == "aix" -%>
267
+ <%- elsif @platform.get_service_types.include?("aix") -%>
268
268
  if /usr/bin/lssrc -s <%= service.name -%> > /dev/null 2>&1; then
269
269
  /usr/bin/chssys -s <%= service.name -%> -p <%= service.service_command -%> -w 7 -S -n 15 -f 9 > /dev/null 2>&1 || :
270
270
  else
@@ -305,17 +305,17 @@ fi
305
305
  <%- get_services.each do |service| -%>
306
306
  # switch based on systemd vs systemv vs smf vs aix
307
307
  #
308
- <%- if @platform.servicetype == "systemd" -%>
308
+ <%- if @platform.get_service_types.include?("systemd") -%>
309
309
  <%- if @platform.is_sles? -%>
310
310
  %service_del_postun <%= service.name %>.service
311
311
  <%- else -%>
312
312
  %systemd_postun_with_restart <%= service.name %>.service
313
313
  <%- end -%>
314
- <%- elsif @platform.servicetype == "sysv" -%>
314
+ <%- elsif @platform.get_service_types.include?("sysv") -%>
315
315
  if [ "$1" -eq 1 ]; then
316
316
  /sbin/service <%= service.name %> condrestart || :
317
317
  fi
318
- <%- elsif @platform.servicetype == "aix" -%>
318
+ <%- elsif @platform.get_service_types.include?("aix") -%>
319
319
  if [ "$1" -eq 0 ]; then
320
320
  /usr/bin/rmssys -s <%= service.name -%> > /dev/null 2>&1 || :
321
321
  /usr/sbin/rmitab <%= service.name -%> > /dev/null 2>&1 || :
@@ -336,18 +336,18 @@ if [ "$1" -eq 0 ] ; then
336
336
  fi
337
337
 
338
338
  <%- get_services.each do |service| -%>
339
- <%- if @platform.servicetype == "systemd" -%>
339
+ <%- if @platform.get_service_types.include?("systemd") -%>
340
340
  <%- if @platform.is_sles? -%>
341
341
  %service_del_preun <%= service.name %>.service
342
342
  <%- else -%>
343
343
  %systemd_preun <%= service.name %>.service
344
344
  <%- end -%>
345
- <%- elsif @platform.servicetype == "sysv" -%>
345
+ <%- elsif @platform.get_service_types.include?("sysv") -%>
346
346
  if [ "$1" -eq 0 ]; then
347
347
  /sbin/service <%= service.name %> stop >/dev/null 2>&1 || :
348
348
  chkconfig --del <%= service.name %> || :
349
349
  fi
350
- <%- elsif @platform.servicetype == "aix" -%>
350
+ <%- elsif @platform.get_service_types.include?("aix") -%>
351
351
  # stop the service only on a real uninstall, not on upgrades
352
352
  if [ "$1" -eq 0 ] ; then
353
353
  /usr/bin/stopsrc -s <%= service.name -%> > /dev/null 2>&1 || :
@@ -34,6 +34,16 @@ end" }
34
34
  plat._platform
35
35
  }
36
36
 
37
+ let (:dummy_platform_sysv_or_systemd) {
38
+ plat = Vanagon::Platform::DSL.new('debian-8-x86_64')
39
+ plat.instance_eval("platform 'debian-8-x86_64' do |plat|
40
+ plat.servicetype 'sysv', servicedir: '/etc/init.d'
41
+ plat.servicetype 'systemd', servicedir: '/usr/lib/systemd/system'
42
+ plat.defaultdir '/etc/default'
43
+ end")
44
+ plat._platform
45
+ }
46
+
37
47
  let (:dummy_platform_smf) {
38
48
  plat = Vanagon::Platform::DSL.new('debian-11-i386')
39
49
  plat.instance_eval("platform 'debian-11-i386' do |plat|
@@ -575,15 +585,15 @@ end" }
575
585
  expect(comp._component.files).to include(Vanagon::Common::Pathname.file('/etc/init.d/service-test', mode: '0755'))
576
586
 
577
587
  # The component should now have a service registered
578
- expect(comp._component.service.name).to eq('service-test')
588
+ expect(comp._component.service.flat_map(&:name).compact).to include('service-test')
579
589
  end
580
590
 
581
591
  it 'reads from a file when the OS is AIX for services' do
582
592
  comp = Vanagon::Component::DSL.new('service-test', {}, dummy_platform_aix)
583
593
  comp.install_service('spec/fixtures/component/mcollective.service', nil, 'mcollective')
584
- expect(comp._component.service.name).to eq('mcollective')
585
- expect(comp._component.service.service_command).to include('/opt/puppetlabs/puppet/bin/ruby')
586
- expect(comp._component.service.service_command).not_to include("\n")
594
+ expect(comp._component.service.flat_map(&:name).compact).to include('mcollective')
595
+ expect(comp._component.service.flat_map(&:service_command).compact.first).to include('/opt/puppetlabs/puppet/bin/ruby')
596
+ expect(comp._component.service.flat_map(&:service_command).compact.first).not_to include("\n")
587
597
  end
588
598
 
589
599
  it 'adds the correct command to the install for the component for systemd platforms' do
@@ -602,7 +612,34 @@ end" }
602
612
  expect(comp._component.files).to include(Vanagon::Common::Pathname.file('/usr/lib/systemd/system/service-test.service', mode: '0644'))
603
613
 
604
614
  # The component should now have a service registered
605
- expect(comp._component.service.name).to eq('service-test')
615
+ expect(comp._component.service.flat_map(&:name).compact).to include('service-test')
616
+ end
617
+
618
+ it 'adds the correct command when installing both systemd and sysv' do
619
+ comp = Vanagon::Component::DSL.new('service-test', {}, dummy_platform_sysv_or_systemd)
620
+ comp.install_service('component-client.init', 'component-client.sysconfig', init_system: 'sysv')
621
+ comp.install_service('component-client.service', 'component-client.sysconfig', init_system: 'systemd')
622
+ # Look for servicedir creation and copy - sysv
623
+ expect(comp._component.install).to include("install -d '/etc/init.d'")
624
+ expect(comp._component.install).to include("cp -p 'component-client.init' '/etc/init.d/service-test'")
625
+
626
+ # Look for servicedir creation and copy - systemd
627
+ expect(comp._component.install).to include("install -d '/usr/lib/systemd/system'")
628
+ expect(comp._component.install).to include("cp -p 'component-client.service' '/usr/lib/systemd/system/service-test.service'")
629
+
630
+ # Look for defaultdir creation and copy
631
+ expect(comp._component.install).to include("install -d '/etc/default'")
632
+ expect(comp._component.install).to include("cp -p 'component-client.sysconfig' '/etc/default/service-test'")
633
+
634
+ # Look for files and configfiles - sysv
635
+ expect(comp._component.configfiles).to include(Vanagon::Common::Pathname.configfile('/etc/default/service-test'))
636
+ expect(comp._component.files).to include(Vanagon::Common::Pathname.file('/etc/init.d/service-test', mode: '0755'))
637
+
638
+ # Look for files and configfiles - systemd
639
+ expect(comp._component.files).to include(Vanagon::Common::Pathname.file('/usr/lib/systemd/system/service-test.service', mode: '0644'))
640
+
641
+ # The component should now have a service registered
642
+ expect(comp._component.service.flat_map(&:name).compact).to include('service-test')
606
643
  end
607
644
 
608
645
  it 'adds the correct command to the install for smf services using a service_type' do
@@ -621,7 +658,7 @@ end" }
621
658
  expect(comp._component.files).to include(Vanagon::Common::Pathname.file('/var/svc/manifest/network/service-test.xml', mode: '0644'))
622
659
 
623
660
  # The component should now have a service registered
624
- expect(comp._component.service.name).to eq('service-test')
661
+ expect(comp._component.service.flat_map(&:name).compact).to include('service-test')
625
662
  end
626
663
 
627
664
  it 'adds the correct command to the install for smf services' do
@@ -640,7 +677,7 @@ end" }
640
677
  expect(comp._component.files).to include(Vanagon::Common::Pathname.file('/var/svc/manifest/service-test.xml', mode: '0644'))
641
678
 
642
679
  # The component should now have a service registered
643
- expect(comp._component.service.name).to eq('service-test')
680
+ expect(comp._component.service.flat_map(&:name).compact).to include('service-test')
644
681
  end
645
682
 
646
683
  it 'installs the file as a link when link_target is specified' do
@@ -661,7 +698,7 @@ end" }
661
698
  expect(comp._component.files).to include(Vanagon::Common::Pathname.file('/etc/init.d/service-test'))
662
699
 
663
700
  # The component should now have a service registered
664
- expect(comp._component.service.name).to eq('service-test')
701
+ expect(comp._component.service.flat_map(&:name).compact).to include('service-test')
665
702
  end
666
703
  end
667
704
 
@@ -14,8 +14,8 @@ describe "Vanagon::Component::Source::Git" do
14
14
 
15
15
  # before(:each) blocks are run before each example
16
16
  before :each do
17
- allow(Git)
18
- .to receive(:ls_remote)
17
+ allow(Vanagon::Component::Source::Git)
18
+ .to receive(:valid_remote?)
19
19
  .and_return(true)
20
20
 
21
21
  allow(File).to receive(:realpath).and_return(@workdir)
@@ -24,8 +24,8 @@ describe "Vanagon::Component::Source::Git" do
24
24
  describe "#initialize" do
25
25
  it "raises error on initialization with an invalid repo" do
26
26
  # Ensure initializing a repo fails without calling over the network
27
- allow(Git)
28
- .to receive(:ls_remote)
27
+ allow(Vanagon::Component::Source::Git)
28
+ .to receive(:valid_remote?)
29
29
  .and_return(false)
30
30
 
31
31
  expect { @klass.new(@url, ref: @ref_tag, workdir: @workdir) }
@@ -108,6 +108,18 @@ describe "Vanagon::Component" do
108
108
  expect(subject).to receive(:fetch_url)
109
109
  subject.get_source(@workdir)
110
110
  end
111
+
112
+ it 'retrieves from a canonical URI if VANAGON_USE_MIRRORS is set to "false"' do
113
+ allow(ENV).to receive(:[]).with('VANAGON_USE_MIRRORS').and_return('false')
114
+ allow(subject)
115
+ .to receive(:fetch_url)
116
+ .and_return(true)
117
+
118
+ # We expect #get_source to skip mirrors
119
+ expect(subject).not_to receive(:fetch_mirrors)
120
+ expect(subject).to receive(:fetch_url)
121
+ subject.get_source(@workdir)
122
+ end
111
123
  end
112
124
 
113
125
  describe "#get_sources" do
@@ -1,6 +1,33 @@
1
1
  require 'vanagon/platform'
2
2
 
3
3
  describe "Vanagon::Platform" do
4
+ let(:deb_platform_just_servicedir) { "platform 'debian-test-fixture' do |plat|
5
+ plat.servicedir '/etc/init.d'
6
+ end
7
+ "}
8
+ let(:deb_platform_just_servicetype) { "platform 'debian-test-fixture' do |plat|
9
+ plat.servicetype 'sysv'
10
+ end
11
+ "}
12
+ let(:deb_platform_multi_servicetypes) { "platform 'debian-test-fixture' do |plat|
13
+ plat.servicetype 'sysv', servicedir: '/etc/init.d'
14
+ plat.servicetype 'systemd', servicedir: '/lib/systemd/system'
15
+ end
16
+ "}
17
+ let(:deb_platform_no_service) { "platform 'debian-test-fixture' do |plat|
18
+ end
19
+ "}
20
+ let(:deb_platform_servicetype) { "platform 'debian-test-fixture' do |plat|
21
+ plat.servicetype 'sysv'
22
+ plat.servicedir '/etc/init.d'
23
+ end
24
+ "}
25
+ let(:deb_platform_bad_servicedir_block) { "platform 'debian-test-fixture' do |plat|
26
+ plat.servicetype 'sysv', servicedir: '/etc/init.d'
27
+ plat.servicetype 'sysv', servicedir: '/etc/rc.d'
28
+ end
29
+ "}
30
+
4
31
  let(:platforms) do
5
32
  [
6
33
  {
@@ -172,4 +199,57 @@ describe "Vanagon::Platform" do
172
199
  end
173
200
  end
174
201
  end
202
+
203
+ describe "#get_service_type" do
204
+ it "returns plat.servicetype if that's the only thing set" do
205
+ plat = Vanagon::Platform::DSL.new('debian-8-x86_64')
206
+ plat.instance_eval(deb_platform_just_servicetype)
207
+ expect(plat._platform.get_service_types).to include('sysv')
208
+ end
209
+
210
+ it "returns from servicetypes if that's set" do
211
+ plat = Vanagon::Platform::DSL.new('debian-8-x86_64')
212
+ plat.instance_eval(deb_platform_servicetype)
213
+ expect(plat._platform.get_service_types).to include('sysv')
214
+ end
215
+
216
+ it "returns multiples if there's more than one" do
217
+ plat = Vanagon::Platform::DSL.new('debian-8-x86_64')
218
+ plat.instance_eval(deb_platform_multi_servicetypes)
219
+ expect(plat._platform.get_service_types).to include('sysv')
220
+ expect(plat._platform.get_service_types).to include('systemd')
221
+ end
222
+
223
+ it "returns an empty array if nothing is set" do
224
+ plat = Vanagon::Platform::DSL.new('debian-8-x86_64')
225
+ plat.instance_eval(deb_platform_no_service)
226
+ expect(plat._platform.get_service_types.size).to eq(0)
227
+ end
228
+ end
229
+
230
+ describe "#get_service_dir" do
231
+ it "returns plat.servicedir if that's the only thing set" do
232
+ plat = Vanagon::Platform::DSL.new('debian-8-x86_64')
233
+ plat.instance_eval(deb_platform_just_servicedir)
234
+ expect(plat._platform.get_service_dir).to eq('/etc/init.d')
235
+ end
236
+
237
+ it "returns servicedirs set via servicetype" do
238
+ plat = Vanagon::Platform::DSL.new('debian-8-x86_64')
239
+ plat.instance_eval(deb_platform_servicetype)
240
+ expect(plat._platform.get_service_dir).to eq('/etc/init.d')
241
+ end
242
+
243
+ it "returns the servicedir based on servicetype" do
244
+ plat = Vanagon::Platform::DSL.new('debian-8-x86_64')
245
+ plat.instance_eval(deb_platform_multi_servicetypes)
246
+ expect(plat._platform.get_service_dir('systemd')).to eq('/lib/systemd/system')
247
+ end
248
+
249
+ it "fails if there are >1 servicedir for a service type" do
250
+ plat = Vanagon::Platform::DSL.new('debian-8-x86_64')
251
+ plat.instance_eval(deb_platform_bad_servicedir_block)
252
+ expect { plat._platform.get_service_dir('sysv') }.to raise_error(Vanagon::Error)
253
+ end
254
+ end
175
255
  end
@@ -72,12 +72,15 @@ describe "Vanagon::Utilities" do
72
72
  describe '#local_command' do
73
73
  it 'runs commands in an unpolluted environment' do
74
74
  cmd = lambda { |arg| %(echo 'if [ "$#{arg}" = "" ]; then exit 0; else exit 1; fi' | /bin/sh) }
75
- vars = %w(BUNDLE_BIN_PATH BUNDLE_GEMFILE)
75
+ vars = %w[BUNDLE_BIN_PATH BUNDLE_GEMFILE]
76
76
  vars.each do |var|
77
77
  Vanagon::Utilities.local_command(cmd.call(var))
78
78
  expect($?.exitstatus).to eq(0)
79
79
  end
80
80
  end
81
+ it 'raises a RuntimeError when given a bad thing' do
82
+ expect { Vanagon::Utilities.local_command('__bogus__comand__') }.to raise_error(RuntimeError)
83
+ end
81
84
  end
82
85
 
83
86
  describe '#ssh_command' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vanagon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.19.1
4
+ version: 0.20.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet Labs
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-13 00:00:00.000000000 Z
11
+ date: 2021-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: docopt
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 1.3.0
33
+ version: 1.8.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 1.3.0
40
+ version: 1.8.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: fustigit
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -293,41 +293,41 @@ signing_key:
293
293
  specification_version: 3
294
294
  summary: All of your packages will fit into this van with this one simple trick.
295
295
  test_files:
296
- - spec/lib/vanagon/component/dsl_spec.rb
297
- - spec/lib/vanagon/component/source/local_spec.rb
298
- - spec/lib/vanagon/component/source/rewrite_spec.rb
299
- - spec/lib/vanagon/component/source/http_spec.rb
300
- - spec/lib/vanagon/component/source/git_spec.rb
301
- - spec/lib/vanagon/component/rules_spec.rb
302
- - spec/lib/vanagon/component/source_spec.rb
303
- - spec/lib/vanagon/extensions/set/json_spec.rb
304
- - spec/lib/vanagon/extensions/string_spec.rb
305
- - spec/lib/vanagon/extensions/ostruct/json_spec.rb
306
- - spec/lib/vanagon/platform/dsl_spec.rb
307
- - spec/lib/vanagon/platform/windows_spec.rb
308
- - spec/lib/vanagon/platform/solaris_11_spec.rb
309
- - spec/lib/vanagon/platform/rpm/aix_spec.rb
310
- - spec/lib/vanagon/platform/solaris_10_spec.rb
311
- - spec/lib/vanagon/platform/deb_spec.rb
312
- - spec/lib/vanagon/platform/osx_spec.rb
313
- - spec/lib/vanagon/platform/rpm_spec.rb
314
- - spec/lib/vanagon/common/pathname_spec.rb
315
- - spec/lib/vanagon/common/user_spec.rb
316
- - spec/lib/vanagon/utilities_spec.rb
317
- - spec/lib/vanagon/project_spec.rb
318
- - spec/lib/vanagon/project/dsl_spec.rb
296
+ - spec/lib/makefile_spec.rb
319
297
  - spec/lib/vanagon/component_spec.rb
320
- - spec/lib/vanagon/utilities/shell_utilities_spec.rb
321
- - spec/lib/vanagon/environment_spec.rb
322
- - spec/lib/vanagon/driver_spec.rb
323
298
  - spec/lib/vanagon/cli_spec.rb
324
- - spec/lib/vanagon/platform_spec.rb
325
- - spec/lib/vanagon/engine/local_spec.rb
326
- - spec/lib/vanagon/engine/ec2_spec.rb
327
- - spec/lib/vanagon/engine/always_be_scheduling_spec.rb
328
299
  - spec/lib/vanagon/engine/base_spec.rb
300
+ - spec/lib/vanagon/engine/ec2_spec.rb
329
301
  - spec/lib/vanagon/engine/docker_spec.rb
330
302
  - spec/lib/vanagon/engine/hardware_spec.rb
331
303
  - spec/lib/vanagon/engine/pooler_spec.rb
332
- - spec/lib/makefile_spec.rb
304
+ - spec/lib/vanagon/engine/always_be_scheduling_spec.rb
305
+ - spec/lib/vanagon/engine/local_spec.rb
306
+ - spec/lib/vanagon/common/user_spec.rb
307
+ - spec/lib/vanagon/common/pathname_spec.rb
308
+ - spec/lib/vanagon/platform/osx_spec.rb
309
+ - spec/lib/vanagon/platform/rpm_spec.rb
310
+ - spec/lib/vanagon/platform/solaris_11_spec.rb
311
+ - spec/lib/vanagon/platform/deb_spec.rb
312
+ - spec/lib/vanagon/platform/windows_spec.rb
313
+ - spec/lib/vanagon/platform/solaris_10_spec.rb
314
+ - spec/lib/vanagon/platform/rpm/aix_spec.rb
315
+ - spec/lib/vanagon/platform/dsl_spec.rb
316
+ - spec/lib/vanagon/project/dsl_spec.rb
317
+ - spec/lib/vanagon/extensions/set/json_spec.rb
318
+ - spec/lib/vanagon/extensions/ostruct/json_spec.rb
319
+ - spec/lib/vanagon/extensions/string_spec.rb
320
+ - spec/lib/vanagon/environment_spec.rb
321
+ - spec/lib/vanagon/project_spec.rb
322
+ - spec/lib/vanagon/driver_spec.rb
323
+ - spec/lib/vanagon/component/rules_spec.rb
324
+ - spec/lib/vanagon/component/source_spec.rb
325
+ - spec/lib/vanagon/component/source/git_spec.rb
326
+ - spec/lib/vanagon/component/source/rewrite_spec.rb
327
+ - spec/lib/vanagon/component/source/http_spec.rb
328
+ - spec/lib/vanagon/component/source/local_spec.rb
329
+ - spec/lib/vanagon/component/dsl_spec.rb
330
+ - spec/lib/vanagon/platform_spec.rb
331
+ - spec/lib/vanagon/utilities_spec.rb
332
+ - spec/lib/vanagon/utilities/shell_utilities_spec.rb
333
333
  - spec/lib/git/rev_list_spec.rb