在安裝好 Plone Unified Installer 之後,可以利用 paster 工具來建立 plone buildout 目錄,在這 buildout 目錄底下,除了視作為一個 Plone 開發環境之外,也可將這個 buildout 當作上線的 Plone-Site 使用。
Unified Installer 的安裝介紹可參考:Installing Plone 3 with the Unified Installer。下載完檔案後,打開 README.txt 了解如何安裝:
To install Plone 3.2.1 in a stand-alone (single Zope instance) configuration:
* cd to the installer directory and issue the following command:
>> sudo ./install.sh standalone
To install Plone 3.2.1 in a ZEO Cluster (ZEO server, 2 clients) configuration:
* cd to the installer directory and issue the following command:
>> sudo ./install.sh zeo
安裝完成後,即可使用 buildout 來建置 Plone 系統,事前可參考 Working with buildout 這份文件。更完整的教學可以參考 Managing projects with Buildout。
以下簡略將安裝步驟整理:
安裝 unified-installer
$ sudo ./install.sh standalone
設定 PATH
$ export PATH="/opt/Plone-3.1/Python-2.4/bin:$PATH"
$ vi .profile; which python ; python -v
更新 ZopeSkel
$ sudo easy_install -U ZopeSkel
$ sudo paster create --list-templates
設定專案目錄
$ paster create -t plone3_buildout MyBuildout
設定起始環境
$ cd MyBuildout ; python bootstrap.py
下載與安裝
$ bin/buildout
啟動 Plone
$ cd ~/MyBuildout
$ bin/instance start | fg
修改與更新
$ bin/buildout -No
以上是利用 buildout 建立 Plone-Site 的範例。
接下來要展示 Plone One-Click Install with Buildout 的測試範例,用來模擬 Plone Hosting 可能的概況。使用者可透過一個互動介面來輸入 Project Name,接著系統將自動產生一個 Plone-Site 提供給這個 Project 使用。
使用 shell scripts 將 buildout 過程自動化,並額外執行 install.py 來修改 buildout.cfg 的內容,主要目的是產生 random password 以及 port number。最後再執行 siteAutoInstall.py 自動產生 Plone-Site。
Shell Scripts 長像這樣:
#!/bin/bash
read -p "Please Insert Project Name:" pname
paster create -t plone3_buildout --no-interactive $pname
cd $pname && python bootstrap.py
cp buildout.cfg buildout.cfg.ori
cp buildout.cfg buildout.cfg.tmp
python ../install.py
bin/buildout
bin/instance run ../siteAutoInstall.py $pname admin
bin/instance start
port=`cat port.txt`
pwd=`cat pwd.txt`
echo -e "已完成安裝!"
echo -e "Plone-Site: http://localhost:$port/$pname"
echo -e "Password: $pwd (登入後請立即更改密碼)"
install.py 用途是修改 buildout.cfg 的 admin pwd 跟 port,主要使用的 function 如 Python random password 及 Python search-and-replace string in files,整個 scripts 會長得像這樣:
>>>from random import Random
>>>import string
>>>from glob import *
>>>import re
>>>
>>>PWD = ''.join( Random().sample(string.letters+string.digits, 12) )
>>>f=open('pwd.txt', 'w')
>>>f.write(PWD)
>>>f.close
>>>
>>>f=open('../port-num.txt', 'r')
>>>old_num=f.read()
>>>f.close()
>>>tmp_num=int(old_num)
>>>tmp_num2=tmp_num+1
>>>new_num=str(tmp_num2)
>>>f=open('../port-num.txt', 'w')
>>>f.write(new_num)
>>>f.close
>>>
>>>f=open('port.txt', 'w')
>>>f.write(new_num)
>>>f.close
>>>
>>>fileList = glob('buildout.cfg.ori')
>>>pattern = re.compile('admin:', re.IGNORECASE)
>>>replace = "admin:"+PWD
>>>cfg = open('buildout.cfg.tmp', 'wU')
>>>for filename in fileList:
>>> for line in file(filename):
>>> print >>cfg,pattern.sub(replace, line),
>>>cfg.close()
>>>
>>>fileList2 = glob('buildout.cfg.tmp')
>>>pattern2 = re.compile('8080', re.IGNORECASE)
>>>replace2 = new_num
>>>cfg2 = open('buildout.cfg', 'wU')
>>>for filename in fileList2:
>>> for line in file(filename):
>>> print >>cfg2,pattern2.sub(replace2, line),
>>>cfg2.close()
最後一個執行的 Scripts 是 siteAutoInstall.py,這個檔案用途是自動化建立一個 Plone-Site(with NuPlone Skin)。如果僅是純粹產生 Default Plone-Site 的話,可以執行:
>>>from sys import exit
>>>import transaction
>>>from AccessControl.SecurityManagement import \
>>> newSecurityManager, noSecurityManager
>>>from Testing.makerequest import makerequest
>>>
>>>app = makerequest(app)
>>>admin_username='admin'
>>>
>>>oids = app.objectIds()
>>>pid = 'Plone'
>>>if pid in oids:
>>> print "A Plone site already exists"
>>> exit(1)
>>>
>>>acl_users = app.acl_users
>>>user = acl_users.getUser(admin_username)
>>>if user:
>>> user = user.__of__(acl_users)
>>> newSecurityManager(None, user)
>>> #print "Retrieved the admin user"
>>>else:
>>> print "Retrieving admin user failed"
>>> exit(1)
>>>
>>>factory = app.manage_addProduct['CMFPlone']
>>>factory.addPloneSite(pid, title='Portal')
>>>print "Added Plone"
>>>
>>>transaction.commit()
>>>noSecurityManager()
>>>
>>>print "Finished adding Plone site"
最後參照 Running Plone and Zope behind an Apache 2 web server 來設定 mod_rewrite,把新建立的 buildout Plone 位址對應到 ex: http://localhost/CMS or http://localhost/project ..etc。
目前這些測試,是在 Shell 底下執行,另外必須研究如何將這互動介面產生到 Web Page 或者是 Plone 頁面上,並且在最後執行成功時,自動 Email 給註冊者相關網址及帳號資訊等 (搭配 mail server)。
以上是直覺化的使用 buildout 建立多個 Plone-Site,每個專案網站擁有一個自己的 buildout 目錄。但這種方式在處理 port 數量以及 Plone+mod_rewrite 時會有問題 (因為要對應許多 port),相對的這些 port 也會造成更多的安全疑慮問題。
因此另一種較好的方法是,研究 siteAutoInstall.py 程式的運作原理,另外撰寫自動化 scripts,並處理好各別 Plone-Site 的 Admin 權限問題後,利用 mod_rewrite 的方式,僅針對各別目錄 rewrite 即可,就能完成一個初階的 Plone Hosting 構想。
Google 上也有類似的 Plone Hosting 構想 (Easier Plone Hosting: Some Ideas),但未見其實作的內容。若 Plone Hosting 的考量需像 http://objectis.org/ 這樣的完整時,需考量及面臨的技術問題就更具規模了。