Merge lp:~thedac/charms/precise/solr-jetty/persistent-storage into lp:~charmers/charms/precise/solr-jetty/trunk

Proposed by David Ames
Status: Merged
Merged at revision: 16
Proposed branch: lp:~thedac/charms/precise/solr-jetty/persistent-storage
Merge into: lp:~charmers/charms/precise/solr-jetty/trunk
Diff against target: 136 lines (+99/-1)
5 files modified
config.yaml (+20/-0)
hooks/config-changed (+6/-0)
hooks/install (+7/-0)
revision (+1/-1)
scripts/mount-volume.py (+65/-0)
To merge this branch: bzr merge lp:~thedac/charms/precise/solr-jetty/persistent-storage
Reviewer Review Type Date Requested Status
Matthew Wedgwood (community) Approve
Review via email: mp+160520@code.launchpad.net

Description of the change

Use persistent storage when configured

To post a comment you must log in.
Revision history for this message
Matthew Wedgwood (mew) wrote :

Confirmed that boolean values are always "True" or "False", never "true" etc

Approved.

review: Approve
16. By Matthew Wedgwood

[thedac] Use persistent storage when configured

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'config.yaml'
2--- config.yaml 2013-04-22 20:19:35 +0000
3+++ config.yaml 2013-04-24 18:07:30 +0000
4@@ -33,3 +33,23 @@
5 default: ""
6 type: string
7 description: Health check regex on output from check_url
8+ volume-ephemeral:
9+ type: boolean
10+ default: true
11+ description: >
12+ If false, the /var/lib/solr will be symlinked to persistent storage. A
13+ configure-error state will be raised if
14+ volume-map[$JUJU_UNIT_NAME] is not set (see "volume-map"
15+ below).
16+ If true, solr-jetty will run from its default directory /var/lib/solr/.
17+ All data will be destroyed with the instance.
18+ Note volumes require charmsupport to be installed
19+ volume-map:
20+ type: string
21+ default: '{}'
22+ description: >
23+ YAML map as e.g. "{ solr-jetty/0: /dev/vdb, solr-jetty/1: /dev/vdb}".
24+ Service units will raise a configure-error if volume-persistent
25+ is 'true' and no volume-map value is set. Use 'juju set' to set a
26+ value and 'juju resolved' to complete configuration.
27+ Note volumes require charmsupport to be installed
28
29=== modified file 'hooks/config-changed'
30--- hooks/config-changed 2012-09-27 13:12:55 +0000
31+++ hooks/config-changed 2013-04-24 18:07:30 +0000
32@@ -52,3 +52,9 @@
33 fi
34
35 open-port 8080/tcp
36+
37+# If persistent storage is configured, mount and use it
38+EPHEMERAL=$(config-get volume-ephemeral)
39+if [[ "$EPHEMERAL" != 'True' ]]; then
40+ /usr/bin/python scripts/mount-volume.py
41+fi
42
43=== modified file 'hooks/install'
44--- hooks/install 2013-01-03 22:13:12 +0000
45+++ hooks/install 2013-04-24 18:07:30 +0000
46@@ -14,5 +14,12 @@
47 done
48 fi
49
50+
51+apt-add-repository -y ppa:charmsupport/ppa
52+apt-get update
53+
54+# charmsupport for persistent storage support
55+apt-get install python-charmsupport
56+
57 # default-jdk should be a prerequisite for jetty (Bug#1046732)
58 apt-get install -y solr-jetty default-jdk curl
59
60=== modified file 'revision'
61--- revision 2012-09-06 16:01:05 +0000
62+++ revision 2013-04-24 18:07:30 +0000
63@@ -1,1 +1,1 @@
64-1
65+3
66
67=== added directory 'scripts'
68=== added file 'scripts/mount-volume.py'
69--- scripts/mount-volume.py 1970-01-01 00:00:00 +0000
70+++ scripts/mount-volume.py 2013-04-24 18:07:30 +0000
71@@ -0,0 +1,65 @@
72+#!/usr/bin/env python
73+
74+import sys
75+import os
76+from charmsupport import volumes
77+from charmsupport import hookenv
78+from charmsupport import host
79+from pwd import getpwnam
80+
81+def storage_is_persistent():
82+ if os.path.islink(SOLR_DIR):
83+ target = os.readlink(SOLR_DIR)
84+ if os.path.ismount(target):
85+ return True
86+ return False
87+
88+def volume_change_pre():
89+ host.service_stop('jetty')
90+
91+
92+def volume_change_post():
93+ pass
94+
95+
96+def set_permissions():
97+ if storage_is_persistent():
98+ # make sure data on external storage are owned
99+ # by the jetty user
100+ jetty_uid = getpwnam('jetty').pw_uid
101+ os.chown(SOLR_DIR, jetty_uid, -1)
102+ for root, dirs, files in os.walk(SOLR_DIR):
103+ for file in files:
104+ os.chown(os.path.join(root, file), jetty_uid, -1)
105+ for subdir in dirs:
106+ os.chown(os.path.join(root, subdir), jetty_uid, -1)
107+
108+
109+SOLR_DIR = '/var/lib/solr'
110+SAVED_DIR = "{}.{}".format(SOLR_DIR, 'charm_saved')
111+
112+if __name__ == '__main__':
113+ try:
114+ mountpoint = volumes.configure_volume(before_change=volume_change_pre, after_change=volume_change_post)
115+ except volumes.VolumeConfigurationError:
116+ hookenv.log('Storage could not be configured', hookenv.ERROR)
117+ sys.exit(1)
118+
119+ if mountpoint == 'ephemeral':
120+ if os.path.islink(SOLR_DIR):
121+ os.remove(SOLR_DIR)
122+ if os.path.isdir(SAVED_DIR):
123+ os.rename(SAVED_DIR, SOLR_DIR)
124+ else:
125+ os.path.mkdir(SOLR_DIR)
126+ else:
127+ if not storage_is_persistent():
128+ try:
129+ os.rename(SOLR_DIR, SAVED_DIR)
130+ except OSError as e:
131+ hookenv.log('ERROR: could not preserve existing log directory', hookenv.ERROR)
132+ hookenv.log(e.strerror, hookenv.ERROR)
133+ sys.exit(1)
134+ os.symlink(mountpoint, SOLR_DIR)
135+ set_permissions()
136+ host.service_start('jetty')

Subscribers

People subscribed via source and target branches

to all changes: