diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..8f39d5e --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "cSpell.words": [ + "cidfile" + ] +} \ No newline at end of file diff --git a/data/Linux.yaml b/data/Linux.yaml new file mode 100644 index 0000000..4cb0211 --- /dev/null +++ b/data/Linux.yaml @@ -0,0 +1,3 @@ +--- +tp::tp_owner: 'root' +tp::tp_group: 'root' \ No newline at end of file diff --git a/data/windows.yaml b/data/windows.yaml index dbd3dc0..24747f0 100644 --- a/data/windows.yaml +++ b/data/windows.yaml @@ -1,59 +1,41 @@ --- -tp::tp_owner: 'Administrator' -tp::tp_group: 'Administrators' -tp::info_script_path: 'C:/ProgramData/PuppetLabs/bin/run_info.ps1' -tp::debug_script_path: 'C:/ProgramData/PuppetLabs/bin/run_debug.ps1' - +tp::tp_owner: ~ +tp::tp_group: ~ +#tp::tp_owner: 'Administrator' +#tp::tp_group: 'Administrators' +tp::info_script_path: 'C:/ProgramData/PuppetLabs/tp/bin/run_info.ps1' +tp::debug_script_path: 'C:/ProgramData/PuppetLabs/tp/bin/run_debug.ps1' +#tp::cli::ensure: 'absent' +#tp::ensure: 'absent' # tp 4 new entrypoints ## tp cli configurations tp::tp_params: global: + owner: ~ + group: ~ + mode: '0775' tp: path: 'C:/ProgramData/PuppetLabs/tp/bin/tp' - args: - owner: 'Administrator' - group: 'Administrators' conf: path: 'C:/ProgramData/PuppetLabs/tp' - args: - ensure: 'directory' - owner: 'Administrator' - group: 'Administrators' data: path: 'C:/ProgramData/PuppetLabs/tp/lib' - args: - ensure: 'directory' - owner: 'Administrator' - group: 'Administrators' bin: path: 'C:/ProgramData/PuppetLabs/tp/bin' args: - ensure: 'directory' - owner: 'Administrator' - group: 'Administrators' - source: 'puppet:///modules/tp/bin' + source: 'puppet:///modules/tp/bin_windows' destination: path: 'C:/ProgramData/PuppetLabs/tp' user: tp: path: '~/.tp/bin/tp' - args: - mode: '0755' conf: path: '~/.tp/etc' - args: - ensure: 'directory' - mode: '0755' data: path: '~/.tp/lib' - args: - ensure: 'directory' - mode: '0755' bin: path: '~/.tp/bin' args: - ensure: 'directory' - mode: '0755' source: 'puppet:///modules/tp/bin' destination: path: '~/.tp/bin' diff --git a/functions/get_version.pp b/functions/get_version.pp index ccc6dee..3d9bccd 100644 --- a/functions/get_version.pp +++ b/functions/get_version.pp @@ -6,8 +6,8 @@ function tp::get_version ( Hash $_settings = {}, Enum['full', 'major'] $_version_type = 'full', ) { - if $_version_type == 'major' { - $real_version = pick_default(getvar('_settings.release.latest_version_major')) + if $_version_type == 'major' and getvar('_settings.release.latest_version_major') { + $real_version = getvar('_settings.release.latest_version_major') } elsif $_version != undef and $_ensure != 'absent' { $real_version = $_version } elsif $_ensure !~ /^present$|^latest$|^absent$/ { diff --git a/manifests/cli.pp b/manifests/cli.pp index ebfede9..e547ddd 100644 --- a/manifests/cli.pp +++ b/manifests/cli.pp @@ -48,7 +48,7 @@ $real_options = $options_defaults + $options $real_ruby_path = $ruby_path ? { - undef => $facts['aio_agent_version'] ? { + undef => getvar('facts.aio_agent_version') ? { undef => '/usr/bin/env ruby', '' => '/usr/bin/env ruby', default => $facts['os']['family'] ? { @@ -61,92 +61,90 @@ File { ensure => $file_ensure, - mode => $real_tp_params['mode'], - owner => $real_tp_params['owner'], - group => $real_tp_params['group'], + mode => $tp::tp_dirs_mode, + owner => $tp::tp_dirs_owner, + group => $tp::tp_dirs_group, } - if $cli_enable { - $dirs = [$tp::tp_dir , "${tp::tp_dir}/app" , "${tp::tp_dir}/shellvars" , "${tp::tp_dir}/test", "${tp::tp_dir}/info", "${tp::tp_dir}/debug"] - $dirs.each | $d | { - file { $d: - ensure => $dir_ensure, - purge => $purge_dirs, - force => $purge_dirs, - recurse => $purge_dirs, - } + $dirs = [$tp::tp_dir , "${tp::tp_dir}/app" , "${tp::tp_dir}/shellvars" , "${tp::tp_dir}/test", "${tp::tp_dir}/info", "${tp::tp_dir}/debug"] + $dirs.each | $d | { + file { $d: + ensure => $dir_ensure, + purge => $purge_dirs, + force => $purge_dirs, + recurse => $purge_dirs, } - $work_dirs = [$tp::data_dir, $tp::download_dir , $tp::extract_dir , $tp::flags_dir] - $work_dirs.each | $d | { - file { $d: - ensure => $dir_ensure, + } + $work_dirs = [$tp::data_dir, $tp::download_dir , $tp::extract_dir , $tp::flags_dir] + $work_dirs.each | $d | { + file { $d: + ensure => $dir_ensure, # purge => $purge_dirs, # force => $purge_dirs, # recurse => $purge_dirs, - } - } - $epp_params = { - 'real_ruby_path' => $real_ruby_path, - 'options' => $real_options, - 'suppress_tp_warnings' => $suppress_tp_warnings, - 'suppress_tp_output' => $suppress_tp_output, - 'tp_dir' => $tp::tp_dir, - } - file { $tp::tp_path: - path => $tp::tp_path, - content => epp('tp/tp.epp', $epp_params), - } - - if $facts['os']['family'] == 'windows' { - file { "${tp::tp_path}.bat": - content => epp('tp/tp.bat.epp'), - } - } else { - file { '/usr/sbin/tp': - ensure => link, - target => $tp::tp_path, - } } + } + $epp_params = { + 'real_ruby_path' => $real_ruby_path, + 'options' => $real_options, + 'suppress_tp_warnings' => $suppress_tp_warnings, + 'suppress_tp_output' => $suppress_tp_output, + 'tp_dir' => $tp::tp_dir, + } + file { $tp::tp_path: + path => $tp::tp_path, + content => epp('tp/tp.epp', $epp_params), + } - file { 'bin dir': - ensure => $dir_ensure, - path => "${tp::tp_dir}/bin", - source => $real_tp_params['bin']['args']['source'], - recurse => true, - } - file { 'info scripts': - ensure => $dir_ensure, - path => "${tp::tp_dir}/bin/run_info", - source => $info_source, - recurse => true, + if $facts['os']['family'] == 'windows' { + file { "${tp::tp_path}.bat": + content => epp('tp/tp.bat.epp'), } - file { 'package_info': - mode => '0755', - path => "${tp::tp_dir}/bin/run_info/package_info", - content => epp('tp/run_info/package_info.epp'), + } else { + file { '/usr/sbin/tp': + ensure => link, + target => $tp::tp_path, } + } - file { $info_script_path: - mode => '0755', - path => $info_script_path, - content => epp($info_script_template, { 'options' => $real_options }), - } + file { 'bin dir': + ensure => $dir_ensure, + path => "${tp::tp_dir}/bin", + source => $real_tp_params['bin']['args']['source'], + recurse => true, + } + file { 'info scripts': + ensure => $dir_ensure, + path => "${tp::tp_dir}/bin/run_info", + source => $info_source, + recurse => true, + } + file { 'package_info': + mode => '0755', + path => "${tp::tp_dir}/bin/run_info/package_info", + content => epp('tp/run_info/package_info.epp'), + } - file { 'debug scripts': - ensure => $dir_ensure, - path => "${tp::tp_dir}/bin/run_debug", - source => $debug_source, - } - file { 'package_debug': - mode => '0755', - path => "${tp::tp_dir}/bin/run_debug/package_debug", - content => epp('tp/run_debug/package_debug.epp'), - } - file { $debug_script_path: - mode => '0755', - path => $debug_script_path, - content => epp($debug_script_template, { 'options' => $real_options }), - } + file { $info_script_path: + mode => '0755', + path => $info_script_path, + content => epp($info_script_template, { 'options' => $real_options }), + } + + file { 'debug scripts': + ensure => $dir_ensure, + path => "${tp::tp_dir}/bin/run_debug", + source => $debug_source, + } + file { 'package_debug': + mode => '0755', + path => "${tp::tp_dir}/bin/run_debug/package_debug", + content => epp('tp/run_debug/package_debug.epp'), + } + file { $debug_script_path: + mode => '0755', + path => $debug_script_path, + content => epp($debug_script_template, { 'options' => $real_options }), } } } diff --git a/manifests/conf.pp b/manifests/conf.pp index 026c83b..025750d 100644 --- a/manifests/conf.pp +++ b/manifests/conf.pp @@ -394,7 +394,7 @@ $default_validate_cmd = $validate_cmd ? { '' => undef, String => $validate_cmd, - Hash => pick_default(getvar("settings.validate_cmd.${base_dir}"), undef), + Hash => getvar("settings.validate_cmd.${base_dir}"), Undef => undef, } $real_validate_cmd = $validate_syntax ? { @@ -402,7 +402,6 @@ true => $default_validate_cmd, false => undef, } - # Resources if $path_parent_create { $path_parent = dirname($real_path) @@ -532,6 +531,7 @@ } $default_validate_cmd = $settings['validate_cmd'] ? { + '' => undef, String => $settings['validate_cmd'], Hash => $settings['validate_cmd'][$base_dir], Undef => undef, diff --git a/manifests/copy_file.pp b/manifests/copy_file.pp index f7e26e2..4aab507 100644 --- a/manifests/copy_file.pp +++ b/manifests/copy_file.pp @@ -25,13 +25,15 @@ if $overwrite { $exec_creates = undef $exec_unless = "diff ${source} ${path} >/dev/null" + $cp_force = '-f' } else { $exec_creates = $path $exec_unless = undef + $cp_force = '' } if $ensure == 'present' { exec { "tp::copy_file ${title}": - command => "cp ${source} ${path}", + command => "cp ${cp_force} ${source} ${path}", path => $facts['path'], creates => $exec_creates, unless => $exec_unless, diff --git a/manifests/create_dir.pp b/manifests/create_dir.pp index 01ed386..8264f44 100644 --- a/manifests/create_dir.pp +++ b/manifests/create_dir.pp @@ -10,7 +10,7 @@ define tp::create_dir ( Optional[String] $owner = undef, Optional[String] $group = undef, - Optional[Stdlib::Filemode] $mode = undef, + Optional[Stdlib::Filemode] $mode = undef, Stdlib::AbsolutePath $path = $title, ) { $mkdir_command = $facts['os']['family'] ? { @@ -23,10 +23,10 @@ } exec { "Create directory ${title}": - command => $mkdir_command, - path => $facts['path'], - creates => $path, - provider => $command_provider, + command => $mkdir_command, + path => $facts['path'], + creates => $path, +# provider => $command_provider, } if $facts['os']['family'] != 'windows' { @@ -45,10 +45,11 @@ } } if $mode { + $short_mode = regsubst($mode, '^0', '') exec { "chmod ${mode} ${title}": command => "chmod '${mode}' '${path}'", path => '/bin:/sbin:/usr/sbin:/usr/bin', - onlyif => "[ 0\$(stat -c '%a' '${path}') != '${mode}' ]", + onlyif => "[ \$(stat -c '%a' '${path}') != '${short_mode}' ]", } } } diff --git a/manifests/init.pp b/manifests/init.pp index 4a77af8..f11777c 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -30,8 +30,8 @@ # Legacy params #Stdlib::Absolutepath $tp_path = '/usr/local/bin/tp', - String $tp_owner = 'root', - String $tp_group = 'root', + Optional[String] $tp_owner = undef, + Optional[String] $tp_group = undef, String $tp_mode = '0755', String $check_service_command = 'puppet resource service', String $check_service_command_post = '', # lint:ignore:params_empty_string_assignment @@ -141,9 +141,13 @@ $tp_dir = $real_tp_params['conf']['path'] $destination_dir = $real_tp_params['destination']['path'] $data_dir = $real_tp_params['data']['path'] + $bin_dir = $real_tp_params['bin']['path'] $download_dir = "${real_tp_params['data']['path']}/download" $extract_dir = "${real_tp_params['data']['path']}/extract" $flags_dir = "${real_tp_params['data']['path']}/flags" + $tp_dirs_mode = $real_tp_params['mode'] + $tp_dirs_owner = $real_tp_params['owner'] + $tp_dirs_group = $real_tp_params['group'] $resources = ['repo', 'install', 'uninstall', 'conf', 'dir', 'test', 'info', 'debug', 'image' , 'source' , 'desktop', 'build'] # tp 4 new entrypoints @@ -253,7 +257,7 @@ $real_cli_enable = $cli_enable } if $real_cli_enable { - file { [$tp_dir , "${tp_dir}/app" , "${tp_dir}/shellvars" , "${tp_dir}/test"]: + file { [$tp_dir , "${tp_dir}/app" , "${tp_dir}/shellvars" , "${tp_dir}/test" , "${tp_dir}/bin"]: ensure => $dir_ensure, mode => $tp_mode, owner => $tp_owner, @@ -294,6 +298,7 @@ mode => $tp_mode, source => $lib_source, recurse => true, + force => true, } file { 'info dir': ensure => $dir_ensure, @@ -301,6 +306,7 @@ owner => $tp_owner, group => $tp_group, mode => $tp_mode, + force => true, } file { 'info scripts': ensure => $dir_ensure, @@ -310,6 +316,7 @@ mode => $tp_mode, source => $info_source, recurse => true, + force => true, } file { 'package_info': ensure => $file_ensure, @@ -334,6 +341,7 @@ owner => $tp_owner, group => $tp_group, mode => $tp_mode, + force => true, } file { 'debug scripts': ensure => $dir_ensure, @@ -343,6 +351,7 @@ mode => $tp_mode, source => $debug_source, recurse => true, + force => true, } file { 'package_debug': ensure => $file_ensure, diff --git a/manifests/install.pp b/manifests/install.pp index ac773ff..1f657e1 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -70,17 +70,74 @@ # @param ensure Manage application status. # Valid values are present, absent or the package version number. # +# @param app The name of the application to install. +# If not specified, it defaults to the title of the resource. +# +# @param use_v4 Boolean to use v4 code +# If true, the tp v4 code is used, otherwise the legacy one. +# +# @param install_method The method to use for the app installation. +# If not specified, it defaults to the one specified in the tinydata. +# Valid values are package, source, release, image. +# +# @param on_missing_data What to do if tinydata is missing +# Common values are notify, fail, ignore. +# Valid values are 'alert','crit','debug','emerg','err','info','notice','warning','notify','ignore' +# +# @param base_package The package to use for the installation. +# If not specified, it defaults to 'main'. Can be different according to +# tinydata settings. (e.g. 'client', 'server', 'common') +# +# @param confs An hash of tp::conf resources to create. +# These resources will refer to the same application specified in the $title. +# Replaces the deprecated conf_hash parameter. +# # @param conf_hash An hash of tp::conf resources to create. # These resources will refer to the same application specified in the $title. +# Deprecated, use confs instead. +# +# @param dirs An hash of tp::dir resources to create. +# These resources will refer to the same application specified in the $title. +# Replaces the deprecated dir_hash parameter. # # @param dir_hash An hash of tp::dir resources to create. # These resources will refer to the same application specified in the $title. +# Deprecated, use dirs instead. +# +# @param options An hash of options to pass to the tp::conf defines set in confs # usable as key/values in custom templates (use the $options var to access them). +# Replaces the deprecated options_hash parameter. +# +# @param options_hash An hash of options to pass to the tp::conf defines set in confs # usable as key/values in custom templates (use the $options var to access them). +# Deprecated, use options instead. +# +# @param my_settings An hash of settings to override the ones coming from tinydata +# This is useful to override the default settings for the application. +# Replaces the deprecated settings_hash parameter. +# +# @param settings_hash An hash of settings to override the ones coming from tinydata +# This is useful to override the default settings for the application. +# Deprecated, use my_settings instead. +# +# @param params An hash of additional parameters to pass to the tp::install::* defines, +# in case it is used. These params are merged with the ones coming from +# the internal logic and are supposed to be used for special cases. +# +# @param version The version of the application to install. +# If not specified, it defaults to the one specified in the ensure parameter, # (if different from 'present', 'absent' or 'latest') or to what's defined +# in the tinydata. +# If the version is not specified, the latest available version is installed. +# +# @param source The source of the application to install. +# Used only when install_method is 'release' or 'source'. # -# @param options_hash Generic hash of configuration parameters specific for the -# app, they are passed to tp::test if test_enable parameter is true +# @param destination The destination path where to install the application. +# Used only when install_method is 'source' or 'release'. # -# @param settings_hash An hash that can override the application settings tp -# returns, according to the underlying OS and the default behaviour +# @param owner The user used to install the application. +# Default: root +# +# @param group The group of the user used to install the application. +# Default: root # # @param upstream_repo Boolean to enable usage of upstream repo for the app and # install packages from it rather than default local OS one @@ -100,7 +157,7 @@ # # @repo_exec_environment Array to use for the environment argument of exec types # used inside tp::repo define. Used if $auto_repo is true. Can be useful when trying -# to use tp::repo from behing a proxy +# to use tp::repo from behind a proxy # # @param tp_repo_params An hash of additional parameters to pass to the tp::repo define, # in case it is used. These params are merged with the ones coming from other @@ -137,6 +194,7 @@ define tp::install ( Variant[Boolean,String] $ensure = present, + String $app = $title, # Temporary flag to use v4 code Boolean $use_v4 = pick(getvar('tp::use_v4'),false), @@ -154,7 +212,6 @@ Hash $my_settings = {}, - Hash $tp_params = {}, Hash $params = {}, Optional[String] $version = undef, @@ -200,29 +257,35 @@ String[1] $data_module = 'tinydata', ) { - $app = $title $sane_app = regsubst($app, '/', '_', 'G') if $conf_hash != {} { deprecation('conf_hash', 'Replace with confs') } + $all_confs = $conf_hash + $confs + if $dir_hash != {} { deprecation('dir_hash', 'Replace with dirs') } + $all_dirs = $dir_hash + $dirs + if $options_hash != {} { deprecation('options_hash', 'Replace with options') } + $all_options = $options_hash + $options + if $settings_hash != {} { deprecation('settings_hash', 'Replace with my_settings') } # Settings evaluation $tp_settings = tp_lookup($app,'settings',$data_module,'deep_merge') + $all_but_local_settings = deep_merge($tp_settings,$settings_hash,$my_settings) - $real_install_method = pick($install_method, getvar('tp_settings.install_method'), 'package') - $real_version = tp::get_version($ensure,$version,$tp_settings) - $real_majversion = tp::get_version($ensure,$version,$tp_settings,'major') - $real_filename = pick(tp::url_replace(pick(getvar("tp_settings.${real_install_method}.file_name"),$app), $real_version, $real_majversion), $app) # lint:ignore:140chars + $real_install_method = pick($install_method, getvar('all_but_local_settings.install_method'), 'package') + $real_version = tp::get_version($ensure,$version,$all_but_local_settings) + $real_majversion = tp::get_version($ensure,$version,$all_but_local_settings,'major') + $real_filename = pick(tp::url_replace(pick(getvar("all_but_local_settings.${real_install_method}.file_name"),$app), $real_version, $real_majversion), $app) # lint:ignore:140chars if $use_v4 { if getvar('tp_settings.release.base_url') { $real_base_url = tp::url_replace(pick(getvar("tp_settings.${real_install_method}.base_url"), $app), $real_version, $real_majversion) @@ -248,7 +311,7 @@ }, destination => $real_install_method ? { 'source' => pick($destination, "${tp::data_dir}/source/${app}"), - 'release' => pick($destination, "${tp::data_dir}/download/${app}"), + 'release' => pick($destination, "${tp::data_dir}/extract/${app}/${extracted_dir}"), default => undef, }, packages => delete_undef_values({ @@ -267,7 +330,7 @@ }), }) - $settings = deep_merge($tp_settings,$settings_hash,$my_settings,$local_settings) + $settings = deep_merge($all_but_local_settings,$local_settings) # v4 code if $use_v4 { @@ -317,8 +380,10 @@ } 'source': { $default_install_source_params = { - owner => $owner, - group => $group, + owner => $owner, + group => $group, + source => $source, + destination => $destination, } tp::install::source { $app: * => $default_install_params + $default_install_source_params + $params, @@ -367,16 +432,16 @@ $conf_defaults = { 'ensure' => tp::ensure2file($ensure), 'settings_hash' => $settings, - 'options_hash' => $options_hash + $options, + 'options_hash' => $all_options, 'data_module' => $data_module, } - $confs.each |$k,$v| { + $all_confs.each |$k,$v| { tp::conf { $k: * => $conf_defaults + $v, } } - if $options_hash != {} and getvar('settings.files.config.format') { + if $all_options != {} and pick_default(getvar('settings.files.config.format'),getvar('settings.config_file_format')) { tp::conf { $app: * => $conf_defaults, } @@ -386,7 +451,7 @@ 'settings_hash' => $settings, 'data_module' => $data_module, } - $dirs.each |$k,$v| { + $all_dirs.each |$k,$v| { tp::dir { $k: * => $dir_defaults + $v, } @@ -615,32 +680,32 @@ $conf_defaults = { 'ensure' => tp::ensure2file($ensure), 'settings_hash' => $settings, - 'options_hash' => $options_hash, + 'options_hash' => $all_options, 'data_module' => $data_module, } - if $conf_hash != {} { - $conf_hash.each |$k,$v| { - tp::conf { $k: - * => $conf_defaults + $v, - } + + $all_confs.each |$k,$v| { + tp::conf { $k: + * => $conf_defaults + $v, } } - if $options_hash != {} and $settings[config_file_format] { + + if $all_options != {} and $settings[config_file_format] { tp::conf { $app: * => $conf_defaults, } } + # Manage additional tp::dir as in dir_hash $dir_defaults = { 'ensure' => tp::ensure2dir($ensure), 'settings_hash' => $settings, 'data_module' => $data_module, } - if $dir_hash != {} { - $dir_hash.each |$k,$v| { - tp::dir { $k: - * => $dir_defaults + $v, - } + + $all_dirs.each |$k,$v| { + tp::dir { $k: + * => $dir_defaults + $v, } } @@ -648,14 +713,14 @@ if $auto_conf and $settings['config_file_template'] { ::tp::conf { $app: template => $settings['config_file_template'], - options_hash => $options_hash, + options_hash => $all_options, data_module => $data_module, } } if $auto_conf and $settings['init_file_template'] { ::tp::conf { "${app}::init": template => $settings['init_file_template'], - options_hash => $options_hash, + options_hash => $all_options, base_file => 'init', data_module => $data_module, } @@ -665,7 +730,7 @@ if $test_enable and $test_template { tp::test { $app: settings_hash => $settings, - options_hash => $options_hash, + options_hash => $all_options, template => $test_template, data_module => $data_module, } diff --git a/manifests/install/package.pp b/manifests/install/package.pp index e12aa2e..22da01d 100644 --- a/manifests/install/package.pp +++ b/manifests/install/package.pp @@ -332,8 +332,16 @@ require => $service_require, } $services.each |$kk,$vv| { - service { $kk: - * => $service_defaults + pick(getvar("settings.services.${kk}.params"), getvar('settings.service_params'), {}), + if $vv['name'] != '' and $vv['manage'] != false { + if $kk == 'main' { + $service_title = $app + } else { + $service_title = $kk + } + $service_params = pick(getvar("settings.services.${kk}.params"), getvar('settings.service_params'), {}) + service { $service_title: + * => $service_defaults + { name => pick($vv['name'],$service_title) } + $service_params, + } } } } diff --git a/manifests/install/source.pp b/manifests/install/source.pp index 3ec13bb..969fd28 100644 --- a/manifests/install/source.pp +++ b/manifests/install/source.pp @@ -56,10 +56,11 @@ String[1] $owner = pick(getvar('identity.user'),'root'), String[1] $group = pick(getvar('identity.group'),'root'), + Stdlib::Absolutepath $destination = getvar('settings.destination'), + ) { $app = $title $sane_app = regsubst($app, '/', '_', 'G') - $destination = getvar('settings.destination') $tp_dir = $tp::real_tp_params['conf']['path'] $real_source = $ensure ? { diff --git a/manifests/service.pp b/manifests/service.pp index d3bafe8..3f05cbc 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -92,7 +92,7 @@ undef: { $mount_mapping = getvar('settings.dirs') ? { undef => '', - default => join(getvar('settings.dirs').map |$k,$v| { "-v ${v['path']}:${v['path']}" }, ' '), + default => join(getvar('settings.dirs').map |$k,$v| { if getvar('v.path') { if getvar('os.selinux.enabled') { "-v ${v['path']}:${v['path']}:Z" } else { "-v ${v['path']}:${v['path']}" } } }, ' '), # lint:ignore:140chars } } String[0]: { @@ -102,10 +102,10 @@ $mount_mapping = "-v ${settings['image']['mounts']}" } Array: { - $mount_mapping = join(getvar('settings.image.mounts').map|$k| { "-v ${k}" }, ' ') + $mount_mapping = join(getvar('settings.image.mounts').map|$k| { if getvar('os.selinux.enabled') { "-v ${k}:${k}:Z" } else { "-v ${k}:${k}" } }, ' ') # lint:ignore:140chars } Hash: { - $mount_mapping = join(getvar('settings.image.mounts').map |$k,$v| { "-v ${k}:${v}" }, ' ') + $mount_mapping = join(getvar('settings.image.mounts').map |$k,$v| { if getvar('v.path') { if getvar('os.selinux.enabled') { "-v ${v['path']}:${v['path']}:Z" } else { "-v ${v['path']}:${v['path']}" } } }, ' ') # lint:ignore:140chars } default: { tp::fail($on_missing_data, "tp::service ${app} - settings.image.mounts is not a valid type") @@ -113,18 +113,33 @@ } $docker_args = pick_default(getvar('settings.docker.args'),'') + $cidfile = '%t/%n.ctr-id' + $docker_command = $facts['os']['family'] ? { + 'RedHat' => '/usr/bin/podman', + default => '/usr/bin/docker', + } + $docker_after = $facts['os']['family'] ? { + 'RedHat' => 'network-online.target', + default => 'docker.service', + } + $docker_requires = $facts['os']['family'] ? { + 'RedHat' => 'network-online.target', + default => 'docker.service', + } $options_defaults = { 'Unit' => { 'Description' => pick(getvar('settings.description'),"${app} service"), - 'Documentation' => pick(getvar('settings.urls.documentation'),getvar('settings.urls.website'),"Search: ${app}"), - 'After' => 'docker.service', - 'Requires' => 'docker.service', + 'Documentation' => pick(getvar('settings.urls.documentation'),getvar('settings.urls.website'), "Search ${app}"), + 'After' => $docker_after, + 'Requires' => $docker_requires, }, 'Service' => { -# 'ExecStartPre' => "/usr/bin/docker stop ${app} ; /usr/bin/docker rm ${app} ; /usr/bin/docker pull ${settings['docker_image']}", - 'ExecStart' => "/usr/bin/docker run --rm --name ${app} ${docker_args} ${port_mapping} ${mount_mapping} ${docker_image}", + 'ExecStartPre' => "/bin/rm -f ${cidfile}", + 'ExecStart' => "${docker_command} run --rm --cidfile=${cidfile} --name ${app} ${docker_args} ${port_mapping} ${mount_mapping} ${docker_image}", 'Restart' => 'always', 'RestartSec' => '10s', + 'ExecStop' => "${docker_command} stop --ignore --cidfile=${cidfile}", + 'ExecStopPost' => "${docker_command} rm -f --ignore --cidfile=${cidfile}", }, 'Install' => { 'WantedBy' => 'multi-user.target', @@ -134,7 +149,7 @@ $options_defaults = { 'Unit' => { 'Description' => pick(getvar('settings.description'),"${app} service"), - 'Documentation' => pick(getvar('settings.urls.documentation'),getvar('settings.urls.website'),"Search: ${app}"), + 'Documentation' => pick(getvar('settings.urls.documentation'),getvar('settings.urls.website'),"Search ${app}"), }, 'Service' => { 'ExecStart' => $real_command_path, diff --git a/manifests/setup.pp b/manifests/setup.pp index 87340a3..7a79fb6 100644 --- a/manifests/setup.pp +++ b/manifests/setup.pp @@ -45,13 +45,14 @@ Hash: { $files.each | $k,$v | { tp::copy_file { $k: - ensure => pick($v['ensure'],$ensure), - path => pick($v['path'], "${destination_dir}/${k}"), - owner => pick($v['owner'], $owner), - group => pick($v['group'], $group), - mode => pick($v['mode'], '0755'), - source => pick($v['source'],"${source_dir}/${k}"), - before => $before_tp_service, + ensure => pick($v['ensure'],$ensure), + path => pick($v['path'], "${destination_dir}/${k}"), + owner => pick($v['owner'], $owner), + group => pick($v['group'], $group), + mode => pick($v['mode'], '0755'), + source => pick($v['source'],"${source_dir}/${k}"), + notify => $before_tp_service, + overwrite => pick($v['overwrite'],false), } } } @@ -64,7 +65,7 @@ group => $group, source => "${source_dir}/${k}", mode => '0755', - before => $before_tp_service, + notify => $before_tp_service, } } } @@ -76,7 +77,7 @@ group => $group, source => "${source_dir}/${files}", mode => '0755', - before => $before_tp_service, + notify => $before_tp_service, } } default: { @@ -90,7 +91,7 @@ file { $k: ensure => link, target => tp::url_replace($v,$real_version,$real_majversion), - before => $before_tp_service, + notify => $before_tp_service, } } diff --git a/metadata.json b/metadata.json index a04eb73..cf3a292 100644 --- a/metadata.json +++ b/metadata.json @@ -7,7 +7,7 @@ "source": "https://github.com/example42/puppet-tp", "project_page": "https://github.com/example42/puppet-tp", "issues_url": "https://github.com/example42/puppet-tp/issues", - "dependencies": [ + "dependencies": [ { "name": "puppetlabs/stdlib", "version_requirement": ">= 3.2.0 < 10.0.0"