From d1b3bacc6d0fd0d74fa8c9433cc65d824daf5460 Mon Sep 17 00:00:00 2001 From: Yanis Guenane Date: Tue, 13 Oct 2015 10:26:00 +0200 Subject: [PATCH] Support LodgeIt installation on EL7 derivatives This commit aims to make this module work on EL7 derivatives. It : * Creates a /etc/sysconfig/lodgeit-MYINSTANCE configuration file * Creates a systemd unit file to manage lodgeit instances * Install the proper packages for the platform Change-Id: Ifdc874e5f4c66c336d8e3dc1c731ca28d6415a46 Depends-On: I82241038d687316f91f18209fe8323c12422e2f8 Depends-On: If58c09095a530fcb54e2a42948183aabf6805e41 --- files/lodgeit.service | 11 +++++++++++ manifests/init.pp | 44 +++++++++++++++++++++++++++---------------- manifests/params.pp | 27 ++++++++++++++++++++++++++ manifests/site.pp | 38 +++++++++++++++++++++++++++---------- 4 files changed, 94 insertions(+), 26 deletions(-) create mode 100644 files/lodgeit.service create mode 100644 manifests/params.pp diff --git a/files/lodgeit.service b/files/lodgeit.service new file mode 100644 index 0000000..8fcae67 --- /dev/null +++ b/files/lodgeit.service @@ -0,0 +1,11 @@ +[Unit] +Description=The %i LodgeIt Application +After=network.target basic.target + +[Service] +EnvironmentFile=-/etc/sysconfig/lodgeit-%i +ExecStart=/bin/python /srv/lodgeit/%i/manage.py runserver -h ${LISTEN} -p ${PORT} +ExecStop=/bin/kill -WINCH ${MAINPID} + +[Install] +WantedBy=multi-user.target diff --git a/manifests/init.pp b/manifests/init.pp index f566f57..f52251d 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -1,29 +1,27 @@ # == Class: lodgeit # class lodgeit { - $packages = [ 'python-imaging', - 'python-jinja2', - 'python-pybabel', - 'python-werkzeug', - 'python-simplejson', - 'python-pygments'] + + include ::lodgeit::params include ::httpd - include ::pip - httpd_mod { 'proxy': - ensure => present, + + # The httpd module supports only Debian/Ubuntu (requires a2enmod) + # On EL7 derivative both of those modules are part of the httpd package + # Hence there is no need for extra action + if $::osfamily == 'Debian' { + httpd_mod { ['proxy', 'proxy_http'] : + ensure => present, + } } - httpd_mod { 'proxy_http': + + package { $::lodgeit::params::system_packages: ensure => present, } - package { $packages: - ensure => present, - } - - if ! defined(Package['python-mysqldb']) { - package { 'python-mysqldb': + if ! defined(Package[$::lodgeit::params::mysql_python_package]) { + package { $::lodgeit::params::mysql_python_package: ensure => present, } } @@ -44,4 +42,18 @@ class lodgeit { source => 'https://git.openstack.org/openstack-infra/lodgeit', } + if $::osfamily == 'RedHat' { + + file { '/etc/systemd/system/lodgeit@.service': + ensure => present, + owner => 'root', + group => 'root', + mode => '0644', + source => 'puppet:///modules/lodgeit/lodgeit.service', + } ~> + exec { '/bin/systemctl daemon-reload' : } + + } + + } diff --git a/manifests/params.pp b/manifests/params.pp new file mode 100644 index 0000000..8cff3b1 --- /dev/null +++ b/manifests/params.pp @@ -0,0 +1,27 @@ +# === Class : lodgeit::params +class lodgeit::params { + + $common_packages = ['python-jinja2', + 'python-babel', + 'python-werkzeug', + 'python-simplejson', + 'python-pygments'] + + case $::osfamily { + 'RedHat' : { + $system_packages = concat($common_packages, 'python-pillow') + $mysql_python_package = 'MySQL-python' + $lodgeit_service_provider = undef + + } + 'Debian' : { + $system_packages = concat($common_packages, 'python-imaging') + $mysql_python_package = 'python-mysqldb' + $lodgeit_service_provider = 'upstart' + } + default : { + fail("LodgeIt: The Operating System ${::osfamily} is not supported") + } + } + +} diff --git a/manifests/site.pp b/manifests/site.pp index c19ff5f..ca1502f 100644 --- a/manifests/site.pp +++ b/manifests/site.pp @@ -12,21 +12,38 @@ define lodgeit::site( ) { include ::httpd + include ::lodgeit::params ::httpd::vhost::proxy { $vhost_name: port => 80, - dest => "http://localhost:${port}", + dest => "http://127.0.0.1:${port}", require => [File["/srv/lodgeit/${name}"], File["/srv/www/${name}"]], proxyexclusions => ['/robots.txt'], docroot => "/srv/www/${name}/" } - file { "/etc/init/${name}-paste.conf": - ensure => present, - content => template('lodgeit/upstart.erb'), - replace => true, - require => Class['httpd'], - notify => Service["${name}-paste"], + if $::osfamily == 'RedHat' { + + Exec['/bin/systemctl daemon-reload'] -> Service["lodgeit@${name}"] + + $service_name = "lodgeit@${name}" + + file { "/etc/sysconfig/lodgeit-${name}": + ensure => present, + content => "PORT=${port}\nLISTEN=127.0.0.1", + notify => Service[$service_name], + } + + } else { + + $service_name = "${name}-paste" + + file { "/etc/init/${name}-paste.conf": + ensure => present, + content => template('lodgeit/upstart.erb'), + replace => true, + notify => Service[$service_name], + } } file { "/srv/lodgeit/${name}": @@ -47,7 +64,7 @@ define lodgeit::site( mode => '0755', replace => true, content => template('lodgeit/manage.py.erb'), - notify => Service["${name}-paste"], + notify => Service[$service_name], } file { "/srv/lodgeit/${name}/lodgeit/views/layout.html": @@ -81,9 +98,10 @@ define lodgeit::site( database_password => $db_password, } - service { "${name}-paste": + service { $service_name: ensure => running, - provider => upstart, + provider => $::lodgeit::params::service_provider, require => Class['httpd'], } + }