diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..7bd34cd --- /dev/null +++ b/Gemfile @@ -0,0 +1,7 @@ +source 'https://rubygems.org' + +puppetversion = ENV.key?('PUPPET_VERSION') ? "= #{ENV['PUPPET_VERSION']}" : ['>= 3.3'] +gem 'puppet', puppetversion +gem 'puppetlabs_spec_helper', '>= 0.1.0' +gem 'puppet-lint', '>= 0.3.2' +gem 'facter', '>= 1.7.0' diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..4b62f2d --- /dev/null +++ b/Rakefile @@ -0,0 +1,20 @@ +require 'rubygems' +require 'puppetlabs_spec_helper/rake_tasks' +require 'puppet-lint/tasks/puppet-lint' +PuppetLint.configuration.send('disable_80chars') +PuppetLint.configuration.send('disable_autoloader_layout') +PuppetLint.configuration.send('disable_variable_scope') +PuppetLint.configuration.ignore_paths = ["spec/**/*.pp", "pkg/**/*.pp"] + +desc "Validate manifests, templates, and ruby files" +task :validate do + Dir['manifests/**/*.pp'].each do |manifest| + sh "puppet parser validate --parser=future --noop #{manifest}" + end + Dir['spec/**/*.rb','lib/**/*.rb'].each do |ruby_file| + sh "ruby -c #{ruby_file}" unless ruby_file =~ /spec\/fixtures/ + end + Dir['templates/**/*.erb'].each do |template| + sh "erb -P -x -T '-' #{template} | ruby -c" + end +end diff --git a/manifests/init.pp b/manifests/init.pp new file mode 100644 index 0000000..a9479a5 --- /dev/null +++ b/manifests/init.pp @@ -0,0 +1,59 @@ +# == Class: uwsgi +# +# Manage uwsgi configurations +# +# === Examples +# +# include ::uwsgi +# +# === Authors +# +# Nicolas Dandrimont +# +# === Copyright +# +# Copyright 2015 The Software Heritage developers +# +class uwsgi { + $uwsgi_packages = ['uwsgi', 'uwsgi-plugin-python3'] + + $systemd_service_dir = '/etc/systemd/system/uwsgi.service.d' + $systemd_service_file = "${systemd_service_dir}/setrlimit.conf" + $uwsgi_filelimit = 65536 + + include ::systemd + + package {$uwsgi_packages: + ensure => installed, + } + + service {'uwsgi': + ensure => running, + enable => true, + require => [ + Package[$uwsgi_packages], + File[$systemd_service_file], + Exec['systemd-daemon-reload'], + ] + } + + file {$systemd_service_dir: + ensure => directory, + owner => 'root', + group => 'root', + mode => '0755', + } + + file {$systemd_service_file: + ensure => file, + owner => 'root', + group => 'root', + mode => '0644', + content => template('uwsgi/systemd-setrlimit.conf.erb'), + require => File[$systemd_service_dir], + notify => [ + Service['uwsgi'], + Exec['systemd-daemon-reload'], + ] + } +} diff --git a/manifests/site.pp b/manifests/site.pp new file mode 100644 index 0000000..f83de61 --- /dev/null +++ b/manifests/site.pp @@ -0,0 +1,87 @@ +# == Defined Type: uwsgi::site +# +# uwsgi::site defines a site for uwsgi. +# +# === Parameters +# +# [*ensure*] +# Whether the site should be enabled, present (but disabled) or absent. +# +# [*settings*] +# a hash of settings for the given site. Keys with dashes in the +# config are added with underscores. +# +# === Examples +# +# uwsgi::site {'foo': +# ensure => enabled, +# settings => { +# plugin => 'python3', +# protocol => $uwsgi_protocol, +# socket => $uwsgi_listen_address, +# workers => $uwsgi_workers, +# max_requests => $uwsgi_max_requests, +# max_requests_delta => $uwsgi_max_requests_delta, +# worker_reload_mercy => $uwsgi_reload_mercy, +# reload_mercy => $uwsgi_reload_mercy, +# uid => $user, +# gid => $user, +# module => 'swh.storage.api.server', +# callable => 'run_from_webserver', +# } +# } +# +# === Authors +# +# Nicolas Dandrimont +# +# === Copyright +# +# Copyright 2015 The Software Heritage developers +# +define uwsgi::site ( + $ensure = 'enabled', + $settings = {} + ){ + + $uwsgi_config = "/etc/uwsgi/apps-available/${name}.ini" + $uwsgi_link = "/etc/uwsgi/apps-enabled/${name}.ini" + + case $ensure { + default: { err("Unknown value ensure => ${ensure}.") } + 'enabled', 'present': { + file {$uwsgi_config: + ensure => present, + owner => 'root', + group => 'root', + mode => '0644', + content => template('uwsgi/uwsgi.ini.erb'), + require => Package['uwsgi'], + } + } + 'absent': { + file {$uwsgi_config: + ensure => absent, + } + } + } + + case $ensure { + default: { err("Unknown value ensure => ${ensure}.") } + 'enabled': { + file {$uwsgi_link: + ensure => link, + target => $uwsgi_config, + require => File[$uwsgi_config], + notify => Service['uwsgi'], + } + File[$uwsgi_config] ~> Service['uwsgi'] + } + 'present', 'absent': { + file {$uwsgi_link: + ensure => absent, + notify => Service['uwsgi'], + } + } + } +} diff --git a/metadata.json b/metadata.json new file mode 100644 index 0000000..6f376ba --- /dev/null +++ b/metadata.json @@ -0,0 +1,14 @@ +{ + "name": "swh-uwsgi", + "version": "0.1.0", + "author": "swh", + "summary": "Manage uWSGI configurations", + "license": "Apache 2.0", + "source": "https://forge.softwareheritage.org/diffusion/SPUWSGI/", + "project_page": null, + "issues_url": null, + "dependencies": [ + {"name":"puppetlabs-stdlib","version_requirement":">= 1.0.0"} + ] +} + diff --git a/templates/systemd-setrlimit.conf.erb b/templates/systemd-setrlimit.conf.erb new file mode 100644 index 0000000..9580e06 --- /dev/null +++ b/templates/systemd-setrlimit.conf.erb @@ -0,0 +1,2 @@ +[Service] +LimitNOFILE=<%= @uwsgi_filelimit %> diff --git a/templates/uwsgi.ini.erb b/templates/uwsgi.ini.erb new file mode 100644 index 0000000..2a90345 --- /dev/null +++ b/templates/uwsgi.ini.erb @@ -0,0 +1,6 @@ +# UWSGI configuration for <%= @name %> +# Managed by puppet - changes will be overwritten +[uwsgi] +<% @settings.each do |key, value| -%> +<%= @key.sub('_', '-') %> = <%= @value %> +<% end -%>