From c5bf8e9321f2fc84275cb1aee231a23442b94128 Mon Sep 17 00:00:00 2001 From: Walter Huf Date: Fri, 4 Apr 2014 15:02:13 -0500 Subject: [PATCH] Adds a restapi recipe --- attributes/restapi.rb | 26 ++++++++++++++++ recipes/restapi.rb | 43 ++++++++++++++++++++++++++ recipes/restapi_apache2.rb | 49 ++++++++++++++++++++++++++++++ templates/default/restapi.conf.erb | 21 +++++++++++++ templates/default/restapi.wsgi.erb | 23 ++++++++++++++ 5 files changed, 162 insertions(+) create mode 100644 attributes/restapi.rb create mode 100644 recipes/restapi.rb create mode 100644 recipes/restapi_apache2.rb create mode 100644 templates/default/restapi.conf.erb create mode 100644 templates/default/restapi.wsgi.erb diff --git a/attributes/restapi.rb b/attributes/restapi.rb new file mode 100644 index 0000000..b186d8b --- /dev/null +++ b/attributes/restapi.rb @@ -0,0 +1,26 @@ +# +# Cookbook Name:: ceph +# Attributes:: restapi +# +# Copyright 2011, DreamHost Web Hosting +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +default['ceph']['restapi']['admin_email'] = 'admin@example.com' +default['ceph']['restapi']['addr'] = '127.0.0.1:5000' # vhost port +default['ceph']['restapi']['name'] = nil # don't add a servername line +default['ceph']['restapi']['port'] = 5000 # add this port to the listening ports +default['ceph']['restapi']['user'] = 'www-data' # owner of keyring and logfile +default['ceph']['restapi']['group'] = 'www-data' # owner of keyring and logfile +default['ceph']['restapi']['webserver_companion'] = 'apache2' # can be false diff --git a/recipes/restapi.rb b/recipes/restapi.rb new file mode 100644 index 0000000..dae7201 --- /dev/null +++ b/recipes/restapi.rb @@ -0,0 +1,43 @@ +# +# Author:: Kyle Bader +# Cookbook Name:: ceph +# Recipe:: restapi +# +# Copyright 2011, DreamHost Web Hosting +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +node.default['ceph']['is_restapi'] = true + +include_recipe 'ceph::conf' + +if node['ceph']['restapi']['webserver_companion'] + # updates the webserver owner + include_recipe "ceph::restapi_#{node["ceph"]["restapi"]["webserver_companion"]}" +end + +config_section_name = 'client.restapi.' + node['hostname'] +config_section = { 'log_file' => '/var/log/ceph/restapi/restapi.log' } +node.default['ceph']['config-sections'][config_section_name] = config_section + +directory '/var/log/ceph/restapi' do + owner node['ceph']['restapi']['user'] + group node['ceph']['restapi']['group'] + mode 0755 + action :create +end +ceph_client 'restapi' do + caps('mon' => 'allow *', 'osd' => 'allow *') + owner node['ceph']['restapi']['user'] + group node['ceph']['restapi']['group'] +end diff --git a/recipes/restapi_apache2.rb b/recipes/restapi_apache2.rb new file mode 100644 index 0000000..cc72f5b --- /dev/null +++ b/recipes/restapi_apache2.rb @@ -0,0 +1,49 @@ +# +# Author:: Kyle Bader +# Cookbook Name:: ceph +# Recipe:: restapi_apache2 +# +# Copyright 2011, DreamHost Web Hosting +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# For EL, delete the current fastcgi configuration +# and set the correct owners for dirs and logs +d_owner = d_group = 'root' +d_owner = d_group = 'apache' if node['platform_family'] == 'rhel' +node.default['ceph']['restapi']['user'] = node['apache']['user'] +node.default['ceph']['restapi']['group'] = node['apache']['group'] + +template '/usr/lib/ceph/restapi.wsgi' do + mode 0644 + owner 'root' + group 'root' +end + +file '/var/log/ceph/rest.log' do + owner d_owner + group d_group + mode '0644' + action :create +end + +if node['ceph']['restapi']['port'] + node.default['apache']['listen_ports'].push(node['ceph']['restapi']['port']) +end + +include_recipe 'apache2' +include_recipe 'apache2::mod_wsgi' + +web_app 'restapi' do + template 'restapi.conf.erb' +end diff --git a/templates/default/restapi.conf.erb b/templates/default/restapi.conf.erb new file mode 100644 index 0000000..f0cc65f --- /dev/null +++ b/templates/default/restapi.conf.erb @@ -0,0 +1,21 @@ + > +<% if node['ceph']['restapi']['name'] -%> + ServerName <%= node['ceph']['restapi']['name'] %> +<% end -%> + ServerAdmin <%= node['ceph']['restapi']['admin_email'] %> + DocumentRoot /var/www/ + + WSGIDaemonProcess cephrest user=<%=node['apache']['user']%> group=<%=node['apache']['group']%> processes=1 threads=5 + WSGIScriptAlias / /usr/lib/ceph/restapi.wsgi + + + WSGIProcessGroup cephrest + WSGIApplicationGroup %{GLOBAL} + Order deny,allow + Allow from all + + + ErrorLog /var/log/<%= node['apache']['package'] %>/error.log + CustomLog /var/log/<%= node['apache']['package'] %>/ceph-rest-access.log proxy_combined + ServerSignature Off + diff --git a/templates/default/restapi.wsgi.erb b/templates/default/restapi.wsgi.erb new file mode 100644 index 0000000..e1835bb --- /dev/null +++ b/templates/default/restapi.wsgi.erb @@ -0,0 +1,23 @@ +#!/usr/bin/env python +# vim: ts=4 sw=4 smarttab expandtab + +import sys + +# import now that env vars are available to imported module + +try: + import ceph_rest_api +except EnvironmentError as e: + print >> sys.stderr, "Error importing ceph_rest_api: ", str(e) + sys.exit(1) + +# let other exceptions generate traceback + +application = ceph_rest_api.generate_app( + conf = None, + cluster = None, + clientname = 'client.restapi.<%=node['hostname']%>', + clientid = None, + args = [] +) +