diff --git a/.fixtures.yml b/.fixtures.yml index 44226726a..d97c1f14a 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -13,6 +13,7 @@ fixtures: mysql: 'https://github.com/puppetlabs/puppetlabs-mysql' postgresql: 'https://github.com/puppetlabs/puppetlabs-postgresql' puppet: 'https://github.com/theforeman/puppet-puppet' + systemd: 'https://github.com/camptocamp/puppet-systemd' selinux_core: repo: "https://github.com/puppetlabs/puppetlabs-selinux_core" puppet_version: ">= 6.0.0" diff --git a/README.md b/README.md index 5dcc58d5f..1ad40b8b5 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,8 @@ previous stable release. ### Foreman version compatibility notes +Running without passenger is only supported on Foreman 1.22+. + The parameters `locations_enabled`, `organizations_enabled` and `authentication` will only have any affect on Foreman 1.20 or older, in newer versions these settings have been removed. @@ -67,6 +69,15 @@ authentication. For Foreman 1.16 or older, please use the 9.x release series of this module. +## Running without passenger + +To use this module without passenger, the `passenger` parameter must be set to +`false`. This will install the `foreman-service` package and ensure the service +is running. + +This introduces a soft dependency on `camptocamp-systemd`. This feature is only +available on Foreman 1.22+. + ## Types and providers `foreman_config_entry` can be used to manage settings in Foreman's database, as diff --git a/manifests/config.pp b/manifests/config.pp index f21aa18a1..9c3950bf7 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -30,9 +30,11 @@ ensure => absent, } - file { $::foreman::init_config: - ensure => file, - content => template("foreman/${foreman::init_config_tmpl}.erb"), + if $::foreman::use_foreman_service { + systemd::dropin_file { 'installer.conf': + unit => "${::foreman::foreman_service}.service", + content => template('foreman/foreman.service-overrides.erb'), + } } file { $::foreman::app_root: diff --git a/manifests/init.pp b/manifests/init.pp index 9db88168b..1bb49b62f 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -342,6 +342,8 @@ timeout => 0, } + $use_foreman_service = ! $passenger + include ::foreman::repo include ::foreman::install include ::foreman::config diff --git a/manifests/install.pp b/manifests/install.pp index ef96b8b78..26c2fbaa4 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -37,6 +37,12 @@ } } + if $::foreman::use_foreman_service { + package { 'foreman-service': + ensure => installed, + } + } + if $::foreman::ipa_authentication and $::foreman::ipa_manage_sssd { package { 'sssd-dbus': ensure => installed, diff --git a/manifests/params.pp b/manifests/params.pp index f4bafba2b..c8b47e345 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -88,6 +88,13 @@ # Configure how many workers should Dynflow use $dynflow_pool_size = 5 + # Define foreman service + $foreman_service = 'foreman' + $foreman_service_ensure = 'running' + $foreman_service_enable = true + $foreman_service_port = 3000 + $foreman_service_bind = undef + # Define job processing service properties $jobs_service = 'dynflowd' $jobs_service_ensure = 'running' @@ -98,9 +105,6 @@ # OS specific paths case $::osfamily { 'RedHat': { - $init_config = '/etc/sysconfig/foreman' - $init_config_tmpl = 'foreman.sysconfig' - case $::operatingsystem { 'fedora': { $passenger_ruby = undef @@ -119,8 +123,6 @@ $passenger_ruby = '/usr/bin/foreman-ruby' $passenger_ruby_package = undef $plugin_prefix = 'ruby-foreman-' - $init_config = '/etc/default/foreman' - $init_config_tmpl = 'foreman.default' } 'Linux': { case $::operatingsystem { @@ -129,8 +131,6 @@ $passenger_ruby = '/usr/bin/tfm-ruby' $passenger_ruby_package = 'tfm-rubygem-passenger-native' $plugin_prefix = 'tfm-rubygem-foreman_' - $init_config = '/etc/sysconfig/foreman' - $init_config_tmpl = 'foreman.sysconfig' } default: { fail("${::hostname}: This module does not support operatingsystem ${::operatingsystem}") diff --git a/manifests/service.pp b/manifests/service.pp index 46714135b..7296baa67 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -3,6 +3,10 @@ Boolean $passenger = $::foreman::passenger, Stdlib::Absolutepath $app_root = $::foreman::app_root, Boolean $ssl = $::foreman::ssl, + Boolean $use_foreman_service = $::foreman::use_foreman_service, + String $foreman_service = $::foreman::foreman_service, + Stdlib::Ensure::Service $foreman_service_ensure = $::foreman::foreman_service_ensure, + Boolean $foreman_service_enable = $::foreman::foreman_service_enable, String $jobs_service = $::foreman::jobs_service, Stdlib::Ensure::Service $jobs_service_ensure = $::foreman::jobs_service_ensure, Boolean $jobs_service_enable = $::foreman::jobs_service_enable, @@ -27,17 +31,12 @@ if $ssl and defined(Class['puppet::server::config']) { Class['puppet::server::config'] -> Class['foreman::service'] } - - $service_ensure = 'stopped' - $service_enabled = false - } else { - $service_ensure = 'running' - $service_enabled = true } - service {'foreman': - ensure => $service_ensure, - enable => $service_enabled, - hasstatus => true, + if $use_foreman_service { + service { $foreman_service: + ensure => $foreman_service_ensure, + enable => $foreman_service_enable, + } } } diff --git a/spec/classes/foreman_service_spec.rb b/spec/classes/foreman_service_spec.rb index 5bdea0057..45ff5572b 100644 --- a/spec/classes/foreman_service_spec.rb +++ b/spec/classes/foreman_service_spec.rb @@ -10,6 +10,10 @@ passenger: true, app_root: '/usr/share/foreman', ssl: true, + use_foreman_service: false, + foreman_service: 'foreman', + foreman_service_ensure: 'running', + foreman_service_enable: true, jobs_service: 'dynflower', jobs_service_ensure: 'stopped', jobs_service_enable: false @@ -35,13 +39,7 @@ it { should contain_service('httpd').that_comes_before('Class[foreman::service]') } it { should contain_class('apache::service').that_comes_before('Class[foreman::service]') } - - it do - should contain_service('foreman') - .with_ensure('stopped') - .with_enable(false) - .with_hasstatus(true) - end + it { should_not contain_service('foreman') } end context 'without ssl' do @@ -51,14 +49,13 @@ end context 'without passenger' do - let(:params) { super().merge(passenger: false) } + let(:params) { super().merge(passenger: false, use_foreman_service: true) } it { is_expected.to compile.with_all_deps } it { should_not contain_exec('restart_foreman') } it do should contain_service('foreman') .with_ensure('running') .with_enable(true) - .with_hasstatus(true) end end end diff --git a/spec/classes/foreman_spec.rb b/spec/classes/foreman_spec.rb index b91dab73c..2cf2e5f15 100644 --- a/spec/classes/foreman_spec.rb +++ b/spec/classes/foreman_spec.rb @@ -36,6 +36,7 @@ it { should contain_class('foreman::install') } it { should contain_package('foreman-postgresql').with_ensure('present') } it { should_not contain_package('foreman-journald') } + it { should_not contain_package('foreman-service') } # config it do @@ -75,26 +76,7 @@ .with_content(/adapter: postgresql/) end - case facts[:osfamily] - when 'RedHat' - it 'should set the defaults file' do - should contain_file('/etc/sysconfig/foreman') - .with_content(%r{^FOREMAN_HOME=/usr/share/foreman$}) - .with_content(/^FOREMAN_USER=foreman$/) - .with_content(/^FOREMAN_ENV=production/) - .with_content(/^FOREMAN_USE_PASSENGER=1$/) - .with_ensure('file') - end - when 'Debian' - it 'should set the defaults file' do - should contain_file('/etc/default/foreman') - .with_content(/^START=no$/) - .with_content(%r{^FOREMAN_HOME=/usr/share/foreman$}) - .with_content(/^FOREMAN_USER=foreman$/) - .with_content(/^FOREMAN_ENV=production/) - .with_ensure('file') - end - end + it { should_not contain_systemd__dropin_file('installer.conf') } it { should contain_file('/usr/share/foreman').with_ensure('directory') } @@ -149,6 +131,7 @@ # service it { should contain_class('foreman::service') } + it { should_not contain_service('foreman') } it { is_expected.to contain_service('dynflowd').with_ensure('running').with_enable(true) } it 'should restart passenger' do @@ -159,13 +142,6 @@ .with_path('/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin') end - it do - should contain_service('foreman') - .with_ensure('stopped') - .with_enable(false) - .with_hasstatus(true) - end - # settings it { should contain_class('foreman::settings').that_requires('Class[foreman::database]') } end @@ -175,6 +151,10 @@ it { should compile.with_all_deps } it { should_not contain_class('foreman::config::apache') } + it { should contain_package('foreman-service').with_ensure('installed') } + it { should contain_systemd__dropin_file('installer.conf').with_unit('foreman.service') } + it { should contain_service('foreman').with_ensure('running') } + it { should_not contain_exec('restart_foreman') } end describe 'with passenger interface' do diff --git a/templates/foreman.default.erb b/templates/foreman.default.erb deleted file mode 100644 index 41424eb72..000000000 --- a/templates/foreman.default.erb +++ /dev/null @@ -1,21 +0,0 @@ -<%= ERB.new(File.read(File.expand_path("_header.erb",File.dirname(file)))).result(binding) -%> - -# Start foreman on boot? -START=<%= scope.lookupvar('::foreman::passenger') ? 'no' : 'yes' %> - -# the location where foreman is installed -FOREMAN_HOME=<%= scope.lookupvar('::foreman::app_root') %> - -# the network interface which foreman web server is running at -#FOREMAN_IFACE=0.0.0.0 - -# the port which foreman web server is running at -# note that if the foreman user is not root, it has to be a > 1024 -# For non-root port 80, consider using Apache+Passenger -#FOREMAN_PORT=3000 - -# the user which runs the web interface -FOREMAN_USER=<%= scope.lookupvar('::foreman::user') %> - -# the rails environment in which foreman runs -FOREMAN_ENV=<%= scope.lookupvar('::foreman::rails_env') %> diff --git a/templates/foreman.service-overrides.erb b/templates/foreman.service-overrides.erb new file mode 100644 index 000000000..56634a0cf --- /dev/null +++ b/templates/foreman.service-overrides.erb @@ -0,0 +1,8 @@ +[Service] +User=<%= scope['foreman::user'] %> +Environment=FOREMAN_ENV=<%= scope['foreman::rails_env'] %> +Environment=FOREMAN_HOME=<%= scope['foreman::app_root'] %> +<% if scope['foreman::foreman_service_bind'] -%> +Environment=FOREMAN_BIND=<%= scope['foreman::foreman_service_bind'] %> +<% end -%> +Environment=FOREMAN_PORT=<%= scope['foreman::foreman_service_port'] %> diff --git a/templates/foreman.sysconfig.erb b/templates/foreman.sysconfig.erb deleted file mode 100644 index 093f48289..000000000 --- a/templates/foreman.sysconfig.erb +++ /dev/null @@ -1,22 +0,0 @@ -<%= ERB.new(File.read(File.expand_path("_header.erb",File.dirname(file)))).result(binding) -%> -# the location where foreman is installed -FOREMAN_HOME=<%= scope.lookupvar('::foreman::app_root') %> - -# the port which foreman web server is running at -# note that if the foreman user is not root, it has to be a > 1024 -#FOREMAN_PORT=3000 - -# the user which runs the web interface -FOREMAN_USER=<%= scope.lookupvar('::foreman::user') %> - -# the rails environment in which foreman runs -FOREMAN_ENV=<%= scope.lookupvar('::foreman::rails_env') %> - -# if we're using passenger or not -# if set to 1, init script will do a railsrestart on 'restart' and will refuse -# 'start' and 'stop' completely and remind the operator that passenger is in -# use. -FOREMAN_USE_PASSENGER=<%= scope.lookupvar('::foreman::passenger') ? '1' : '0' %> - -# set to 1 if you're using thin as a server -#FOREMAN_USE_THIN=0