Plone 3 on a cPanel server started by daemontools (supervise)

by esperanto last modified Jun 03, 2009 09:22 PM

Some notes I made while I installed Plone3 on a server controlled by cPanel. Plone is started/stopped and monitored by daemontools.

Purpose

Anyone who whats to use Plone on a cPanel server or with Daemontools.

Prerequisities

You should already have a working buildout setup. I used zeoserver.

Step by step

 

Prepare Plone


I created an account with the name plone on the machine. So I get the homedir /home/plone. In the /home/plone/plone subdirectory I ran my buildout.

I had to mount /tmp as executable:

# mount -o remount,exec /tmp


(after compiling you can put it back with # mount -o remount,noexec /tmp )

I also had to supply the tmp dir when running buildout in the /home/plone/plone directory:

# TMPDIR=/var/tmp bin/buildout -c deployment.cfg



Prepare apache in cPanel to be used with Plone:

 

  1. first make sure the site is added to cPanel
  2. In '/usr/local/apache/conf/httpd.conf' for the virtualhost you created make sure the line that is like:
    Include "/usr/local/apache/conf/userdata....."
    is not commented.
  3. make sure the directory of the line you just uncommented exist (you should probably create it):
    mkdir -p /usr/local/apache/conf/userdata/username/hostname
  4. create a plone.conf file in that directory containing something like:
    RewriteEngine On
    RewriteRule ^(.*)
    http://localhost:8082/VirtualHostBase/http/www.mydomain.com:80/ZEOMOUNTPOINTNAME/SITENAME/VirtualHostRoot/$1 [L,P]
    (make sure you set the correct port, domain, zeo mount and site name)
  5. Run apache distiller
    /usr/local/cpanel/bin/apache_conf_distiller --update
  6. Restart apache:
    /etc/init.d/httpd graceful

 

Because I wanted to be able to edit the site in a secure environment I also created a plone.conf (steps 3,4 and 5 from above) for a https virtual host entry with the following contents:

 

<Location /plonedav>
    <IfModule mod_security2.c>
        SecRuleRemoveById 960032 960038 960904
    </IfModule>
</Location>

RewriteEngine On

RewriteRule ^/plonedav/(\w+)(/(.*))? http://localhost:1980/$1/$1/$3 [L,P]

RewriteRule ^/zmi(.*) http://localhost:8080/VirtualHostBase/https/%{SERVER_NAME}:443/VirtualHostRoot/_vh_zmi/$1 [P]

RewriteRule ^/plone/(\w+)(/(.*))? http://127.0.0.1:8082/VirtualHostBase/https/%{SERVER_NAME}:443/$1/VirtualHostRoot/_vh_plone/$1/$3 [L,P]

This enabled webdav on /plonedav and made all sites approachable under https with /plone/mysiteID (the rewrite rule assumes that the zeo mountpoint is the same as the site id)

Daemontools


Install Daemontools. (via source or package manager http://cr.yp.to/daemontools.html)

To be able to use daemontools I created a dir with the name of each service I wanted to control in /var/service and in that dir a log directory. So for example for zeoserver:

mkdir -p /var/service/zeoserver
mkdir -p /var/service/zeoserver/log

The following creates this for 'varnish zeo-client-primary zeodebugclient zeodebugclient':

sh -c '\
for name in varnish zeo-client-primary zeodebugclient zeodebugclient; \
do \
mkdir -p /var/service/${name}; \
mkdir -p /var/service/${name}/log; \
done'


create the run files for all logging. For each create in the log dir the following file named 'run' and make it executable (you can also run the sh code below that does it for you, just copy paste it on the commandline):

#!/bin/sh
exec multilog t ./main

 

sh -c '\
for name in varnish zeo-client-primary zeodebugclient zeodebugclient; \
do \
printf '\''#!/bin/sh\nexec multilog t ./main\n'\'' > /var/service/${name}/log/run; \
chmod 755 /var/service/${name}/log/run; \
done'


Now we have to create the run files for each service and make them executable (they all should be named 'run' and in the service dir according to their name:

varnish/run:

#!/bin/sh`
echo starting
exec /home/plone/plone/bin/varnish-instance -F


zeo-client-primary/run (make sure to have the correct bin file in the last exec line. Mine is called primary in buildout):

#!/bin/sh
echo starting
exec 2>&1
exec /home/plone/plone/bin/primary console -Z 0


zeodebugclient/run (make sure to have the correct bin file in the last exec line. Mine is called secondary in buildout):

#!/bin/sh
echo starting
exec /home/plone/plone/bin/secondary console


zeoserver/run:

#!/bin/sh
echo starting
exec 2>&1
exec /usr/bin/python2.4 run.py /home/plone/plone
echo stopped


zeoserver/run.py
Because the way zeoserver is ran we have to create a workaround. We create run.py in the service directory:

#!/usr/bin/python2.4

import sys,os

inst=sys.argv[1]

sys.path[0:0] = [ "%s/bin" % inst ]

import zeoserver

os.execl("/usr/bin/python2.4", "python2.4", "%s/parts/zope2/lib/python/ZEO/runzeo.py" % inst, "-C", "%s/parts/zeoserver/etc/zeo.conf" % inst)


to be able to 'import zeoserver' we have to create a symbolic link:

ln -s /home/plone/plone/bin/zeoserver /home/plone/plone/bin/zeoserver.py


Don't forget to make them all executable:

sh -c '\
for name in varnish zeo-client-primary zeodebugclient zeodebugclient; \
do \
chmod 755 /var/service/${name}/run; \
done'


Now we are done and we create all the symlinks from /service to /var/service. (Supervise will monitor the /service dir and this enables us to work on the files without having supervise starting it while we are on it)

sh -c '\
for name in varnish zeo-client-primary zeodebugclient zeodebugclient; \
do \
ln -s /var/service/${name} /service/${name}; \
done'



to check what is running with daemontools run:

svstat /service/*


you can start a specific service by:

svc -u /service/SERVICENAME


stop it with:

svc -d /service/SERVICENAME


To be able to start/stop everything at once I created these scripts:

cat /root/plone-up.sh

#!/bin/sh
svc -u /service/varnish
svc -u /service/zeoserver
svc -u /service/zeo-client-primary
# svc -u /service/zeodebugclient


cat /root/plone-down.sh

#!/bin/sh
svc -d /service/varnish
svc -d /service/zeoserver
svc -d /service/zeo-client-primary
svc -d /service/zeodebugclient


I also created a script that you can pass /service/servicename that prints out the last log:
cat /root/svlog.sh

#!/bin/sh

tail -f --follow=name  ${*}/log/main/current |tai64nlocal


Off course these should be executable.

 

 

Further information

Daemontools: http://cr.yp.to/daemontools.html.