CoreSessionTracking with ZEO
This How-To describes setting up CoreSessionTracking to work with ZEO. I used a Linux machine, and the following software:
Berkeley DB Storage
My configuration uses a FileStorage for the site's "main" content, and a BerkeleyStorage for session data.
I assume you already have ZEO setup and running, and Zope is configured to work with ZEO. If not, consult the README file in the ZEO tar for help.
Next would be to install ExternalMount: http://www.zope.org/Members/hathawsh/ExternalMount.
After that's setup, install BDB with python and storage support. You should skip the section on "Configuring Zope for Berkeley DB", as we will be doing that step somewhat differently: http://www.zope.org/Members/andyd/zopeberkeleydb
Now we need to configure ZEO to serve both storages. Create a file in your lib/python/ZEO directory called StorageConfig.py: (note, you can call this what you want)
import ZODB.FileStorage, ZODB.BerkeleyStorage
# Change the filenames to suit your system
main_storage = ZODB.FileStorage.FileStorage('/var/opt/zope/Data.fs')
session_storage = ZODB.BerkeleyStorage.SleepyStorage('/var/opt/zope/SessionData.fs')
This defines two storages we can later serve from ZEO.
Then update your custom_zodb.py file (should be in your zope dir):
# Change the filename/ClientStorage options to match your ZEO configuration.
Storage = ZEO.ClientStorage.ClientStorage('/var/opt/zope/zeo.sock', storage='main')
The important part of this custom_zodb.py that might be different from a standard custom_zodb.py is the storage='main' argument. This tells Zope to use the 'main' storage from ZEO, rather than the default which is named '1'.
At this point you should shutdown Zope and ZEO. Then restart ZEO, adding these arguments when you run start.py in addition to the arguments you have been using:
-S main=StorageConfig:main_storage -S session=StorageConfig:session_storage
The -S switch is a storage specification, and tells ZEO where to find the storage to serve.
Now start Zope as usual.
Check out your site, make sure it's working. At this point, nothing should be different :)
Now we need to mount the session storage in our main storage. We are going to use the ExternalMount product to do this, so first we need to create an External Method. Create /opt/zope/Extensions/SessionMount.py (updated for your directory structure):
import ZODB, ZEO.ClientStorage
# Changes to StorageConfig.py need to be reflected here, and fix the path to match
# your directory structure.
return ZODB.DB(ZEO.ClientStorage.ClientStorage('/var/opt/zope/zeo.sock', storage='session'))
Now comes the fun part :)
We need to create an application object in the new storage. Change to your lib/python directory, start python, and run the following script:
from App.Extensions import getObject
fn = getObject('SessionMount', 'createSessionDB', 0)
db = fn()
conn = db.open()
root = conn.root()
from OFS.Application import Application
app = Application()
root['Application'] = app
from OFS.Folder import Folder
folder = Folder()
folder.id = 'session_storage'
folder.title = 'Session Storage'
Now close the python interpreter, and goto the Zope management interface for you server. Add a "Mount via External Method". Fill out the form as follows:
At this time you should be able to navigate to the /session_storage folder, which is stored in the Berkeley Storage.
Add a Session Data Container object with the id session_data_continer to the session_storage folder. Finally, either create a new Session ID Manager and Session Data Manager, or update your pre-existing Session Data Manager to use the new Session Data Container. In either case, the correct path to the Session Data Container is /session_storage/session_data_container.
Now you should have CoreSessionTracking backed by a Berkeley Storage, served from ZEO.