From cf43b6bb238d4f3bc7bdea6ebdecbf165b0bbbc7 Mon Sep 17 00:00:00 2001
From: James Page <james.page@ubuntu.com>
Date: Wed, 14 Jan 2015 09:10:04 +0000
Subject: [PATCH 1/2] Add support of use of embedded webserver

---
 config.yaml         | 10 ++++++++++
 hooks/hooks.py      | 44 ++++++++++++++++++++++++++++++++------------
 templates/ceph.conf |  6 +++++-
 3 files changed, 47 insertions(+), 13 deletions(-)

diff --git a/config.yaml b/config.yaml
index 469bef34..5a70b7e4 100644
--- a/config.yaml
+++ b/config.yaml
@@ -57,3 +57,13 @@ options:
         100-continue. See the following page for more info:
 
         http://ceph.com/docs/dumpling/radosgw/manual-install/#continue-support
+  use-embedded-webserver:
+    type: boolean
+    default: false
+    description: |
+      Newer versions of the Ceph RADOS Gateway support use of an embedded web
+      container instead of Apache + mod-fastcgi, avoiding some of the nuances
+      of using the stock mod-fastcgi packages from Ubuntu.
+      .
+      Enable this option to disable use of Apache and enable the embedded
+      web container feature.
diff --git a/hooks/hooks.py b/hooks/hooks.py
index cdc7053a..ad432f58 100755
--- a/hooks/hooks.py
+++ b/hooks/hooks.py
@@ -28,9 +28,13 @@ from charmhelpers.core.hookenv import (
 from charmhelpers.fetch import (
     apt_update,
     apt_install,
+    apt_purge,
     add_source,
 )
-from charmhelpers.core.host import lsb_release
+from charmhelpers.core.host import (
+    lsb_release,
+    restart_on_change
+)
 from utils import (
     render_template,
     get_host_ip,
@@ -68,16 +72,29 @@ def install_ceph_optimised_packages():
         add_source(source, key='6EAEAE2203C3951A')
 
 
+PACKAGES = [
+    'radosgw',
+    'ntp',
+]
+
+APACHE_PACKAGES = [
+    'libapache2-mod-fastcgi',
+    'apache2',
+]
+
+
 def install_packages():
     add_source(config('source'), config('key'))
-    if config('use-ceph-optimised-packages'):
+    if (config('use-ceph-optimised-packages') and
+            not config('use-embedded-webserver')):
         install_ceph_optimised_packages()
 
     apt_update(fatal=True)
-    apt_install(['radosgw',
-                 'libapache2-mod-fastcgi',
-                 'apache2',
-                 'ntp'], fatal=True)
+    apt_install(PACKAGES, fatal=True)
+    if config('use-embedded-webserver'):
+        apt_purge(APACHE_PACKAGES)
+    else:
+        apt_install(APACHE_PACKAGES, fatal=True)
 
 
 @hooks.hook('install')
@@ -98,7 +115,8 @@ def emit_cephconf():
         'mon_hosts': ' '.join(get_mon_hosts()),
         'hostname': get_unit_hostname(),
         'old_auth': cmp_pkgrevno('radosgw', "0.51") < 0,
-        'use_syslog': str(config('use-syslog')).lower()
+        'use_syslog': str(config('use-syslog')).lower(),
+        'embedded_webserver': config('use-embedded-webserver'),
     }
 
     # Check to ensure that correct version of ceph is
@@ -143,14 +161,16 @@ def apache_reload():
 
 @hooks.hook('upgrade-charm',
             'config-changed')
+@restart_on_change({'/etc/ceph/ceph.con', ['radosgw']})
 def config_changed():
     install_packages()
     emit_cephconf()
-    emit_apacheconf()
-    install_www_scripts()
-    apache_sites()
-    apache_modules()
-    apache_reload()
+    if not config('use-embedded-webserver'):
+        emit_apacheconf()
+        install_www_scripts()
+        apache_sites()
+        apache_modules()
+        apache_reload()
 
 
 def get_mon_hosts():
diff --git a/templates/ceph.conf b/templates/ceph.conf
index a94483d1..5c1473ba 100644
--- a/templates/ceph.conf
+++ b/templates/ceph.conf
@@ -16,9 +16,13 @@ host = {{ hostname }}
 keyring = /etc/ceph/keyring.rados.gateway
 rgw socket path = /tmp/radosgw.sock
 log file = /var/log/ceph/radosgw.log
+{% if embedded_webserver %}
+rgw frontends = civetweb port=80
+{% else %}
 # Turn off 100-continue optimization as stock mod_fastcgi
 # does not support it
-rgw print continue = false 
+rgw print continue = false
+{% endif %}
 {% if auth_type == 'keystone' %}
 rgw keystone url = {{ auth_protocol }}://{{ auth_host }}:{{ auth_port }}/
 rgw keystone admin token = {{ admin_token }}

From 4b174ee4b07f2bedd562ad33e891f6b3745fe23e Mon Sep 17 00:00:00 2001
From: James Page <james.page@ubuntu.com>
Date: Wed, 14 Jan 2015 09:13:44 +0000
Subject: [PATCH 2/2] fixups

---
 hooks/hooks.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hooks/hooks.py b/hooks/hooks.py
index ad432f58..119771e7 100755
--- a/hooks/hooks.py
+++ b/hooks/hooks.py
@@ -161,7 +161,7 @@ def apache_reload():
 
 @hooks.hook('upgrade-charm',
             'config-changed')
-@restart_on_change({'/etc/ceph/ceph.con', ['radosgw']})
+@restart_on_change({'/etc/ceph/ceph.conf': ['radosgw']})
 def config_changed():
     install_packages()
     emit_cephconf()