diff --git a/.fixtures.yml b/.fixtures.yml new file mode 100644 index 0000000..a7fcf1c --- /dev/null +++ b/.fixtures.yml @@ -0,0 +1,5 @@ +--- +fixtures: + forge_modules: + stdlib: "puppetlabs/stdlib" + systemd: "camptocamp/systemd" diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..9032a01 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,5 @@ +*.rb eol=lf +*.erb eol=lf +*.pp eol=lf +*.sh eol=lf +*.epp eol=lf diff --git a/.gitignore b/.gitignore index ff69698..2767022 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,27 @@ -.vagrant -*~ -.vagrantuser -*.swp -tags -*.orig -*.rej -Gemfile.lock -log -pkg +.git/ +.*.sw[op] +.metadata +.yardoc +.yardwarns +*.iml +/.bundle/ +/.idea/ +/.vagrant/ +/coverage/ +/bin/ +/doc/ +/Gemfile.local +/Gemfile.lock +/junit/ +/log/ +/pkg/ +/spec/fixtures/manifests/ +/spec/fixtures/modules/ +/tmp/ +/vendor/ +/convert_report.txt +/update_report.txt +.DS_Store +.project +.envrc +/inventory.yaml diff --git a/manifests/process.pp b/manifests/process.pp index 27b110f..0460597 100644 --- a/manifests/process.pp +++ b/manifests/process.pp @@ -20,10 +20,11 @@ # Group of the config file # define lsyncd::process ( - $source = undef, - $content = undef, - $owner = 'root', - $group = 'root', + $source = undef, + $content = undef, + $owner = 'root', + $group = 'root', + $systemd_template = 'lsyncd/systemd_unit.epp', ) { include lsyncd @@ -37,8 +38,6 @@ } $cfgfile = "${lsyncd::confdir}/${name}.lua" - $process = "lsyncd ${cfgfile}" - file { $cfgfile: ensure => file, owner => $owner, @@ -46,14 +45,39 @@ mode => '0644', source => $source, content => $content, - } ~> - - service { "lsyncd-${name}": - ensure => running, - provider => 'debian', - start => "sudo -u ${owner} ${process}", - status => "pgrep -f '^${process}$'", - stop => "pkill --signal KILL -f '^${process}$'", } + if ($facts['systemd']) { + $process = $facts['os']['family'] ? { + 'RedHat' => '/bin/lsyncd', + default => '/usr/local/bin/lsyncd' + } + + $template_hash = { + 'name' => $name, + 'lsyncd_path' => $process, + 'user' => $owner, + 'lua_file' => $cfgfile, + } + systemd::unit_file { "lsyncd-${name}.service": + content => epp($systemd_template, $template_hash) + } + ~> + service { "lsyncd-${name}": + ensure => 'running', + enable => true, + } + } else { + $process = "lsyncd ${cfgfile}" + + service { "lsyncd-${name}": + ensure => running, + provider => 'debian', + start => "sudo -u ${owner} ${process}", + status => "pgrep -f '^${process}$'", + stop => "pkill --signal KILL -f '^${process}$'", + require => File[$cfgfile] + } + + } } diff --git a/metadata.json b/metadata.json index 7dacbd4..aa6ebde 100644 --- a/metadata.json +++ b/metadata.json @@ -2,17 +2,38 @@ "name": "spjmurray-lsyncd", "version": "1.0.1", "author": "Simon Murray", - "license": "GPL-3.0", "summary": "Lsyncd orchestration", + "license": "GPL-3.0", "source": "https://github.com/spjmurray/puppet-lsyncd", "project_page": "https://github.com/spjmurray/puppet-lsyncd", "issues_url": "https://github.com/spjmurray/puppet-lsyncd/issues", - "tags": ["lsyncd"], "operatingsystem_support": [ { "operatingsystem": "Ubuntu", - "operatingsystemrelease": [ "14.04", "14.10", "15.04" ] + "operatingsystemrelease": [ + "14.04", + "14.10", + "15.04", + "16.04" + ] + } + ], + "dependencies": [ + { + "name": "camptocamp/systemd", + "version_requirement": ">= 2.2.0 < 3.0.0" } ], - "dependencies": [] + "requirements": [ + { + "name": "puppet", + "version_requirement": ">= 4.10.0 < 7.0.0" + } + ], + "tags": [ + "lsyncd" + ], + "pdk-version": "1.10.0", + "template-url": "file:///opt/puppetlabs/pdk/share/cache/pdk-templates.git#1.10.0", + "template-ref": "1.10.0-0-gbba9ac3" } diff --git a/spec/classes/lsyncd_spec.rb b/spec/classes/lsyncd_spec.rb new file mode 100644 index 0000000..0fc9d6a --- /dev/null +++ b/spec/classes/lsyncd_spec.rb @@ -0,0 +1,11 @@ +require 'spec_helper' + +describe 'lsyncd' do + on_supported_os.each do |os, os_facts| + context "on #{os}" do + let(:facts) { os_facts } + + it { is_expected.to compile } + end + end +end diff --git a/spec/default_facts.yml b/spec/default_facts.yml new file mode 100644 index 0000000..ea1e480 --- /dev/null +++ b/spec/default_facts.yml @@ -0,0 +1,7 @@ +# Use default_module_facts.yml for module specific facts. +# +# Facts specified here will override the values provided by rspec-puppet-facts. +--- +ipaddress: "172.16.254.254" +is_pe: false +macaddress: "AA:AA:AA:AA:AA:AA" diff --git a/spec/defines/process_spec.rb b/spec/defines/process_spec.rb new file mode 100644 index 0000000..3f8c11e --- /dev/null +++ b/spec/defines/process_spec.rb @@ -0,0 +1,32 @@ +require 'spec_helper' + +describe 'lsyncd::process' do + on_supported_os.each do |os, os_facts| + context "on #{os}" do + let(:title) { 'test' } + let(:params) { {'content' => 'test'} } + let(:facts) { os_facts } + + it { is_expected.to compile } + end + end + + systemd = { + :supported_os => [ + { + 'operatingsystem' => 'Ubuntu', + 'operatingsystemrelease' => ['16.04'], + } + ], + } + on_supported_os(systemd).each do |os, os_facts| + context "on #{os} (testing systemd)" do + let(:title) { 'test' } + let(:params) { {'content' => 'test'} } + let(:facts) { os_facts.merge({'systemd' => true}) } + + it { is_expected.to compile } + it { is_expected.to contain_systemd__unit_file('lsyncd-test.service') } + end + end +end diff --git a/templates/systemd_unit.epp b/templates/systemd_unit.epp new file mode 100644 index 0000000..ed66c75 --- /dev/null +++ b/templates/systemd_unit.epp @@ -0,0 +1,16 @@ +<%- | String $name, + String $lsyncd_path, + String $user, + String $lua_file +| -%> +[Unit] +Description=Live Syncing (Mirror) Daemon - <%= $name %> +After=network.target + +[Service] +Type=simple +User=<%= $user %> +ExecStart=/usr/bin/lsyncd -nodaemon <%= $lua_file %> + +[Install] +WantedBy=multi-user.target