Skip to content

Commit

Permalink
Adds a restapi recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
Walter Huf committed Apr 7, 2014
1 parent 6485470 commit c5bf8e9
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 0 deletions.
26 changes: 26 additions & 0 deletions attributes/restapi.rb
Original file line number Diff line number Diff line change
@@ -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'] = '[email protected]'
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
43 changes: 43 additions & 0 deletions recipes/restapi.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#
# Author:: Kyle Bader <[email protected]>
# 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
49 changes: 49 additions & 0 deletions recipes/restapi_apache2.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#
# Author:: Kyle Bader <[email protected]>
# 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
21 changes: 21 additions & 0 deletions templates/default/restapi.conf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<VirtualHost <%= node['ceph']['restapi']['addr'] %> >
<% 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

<Location />
WSGIProcessGroup cephrest
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Location>

ErrorLog /var/log/<%= node['apache']['package'] %>/error.log
CustomLog /var/log/<%= node['apache']['package'] %>/ceph-rest-access.log proxy_combined
ServerSignature Off
</VirtualHost>
23 changes: 23 additions & 0 deletions templates/default/restapi.wsgi.erb
Original file line number Diff line number Diff line change
@@ -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 = []
)

0 comments on commit c5bf8e9

Please sign in to comment.