Wednesday 05 January 2011 7:08:17 am
By : Marko Žmak
The recommended way of using the ezfind and ezodf extensions on a server with multiple eZP installations is to have only one instance of Solr server and one instance of OO conversion server for all the eZP installations.
Running single instances of this servers for multiple eZP installations is not a problem if you have full access to your server, but if you happen to have many eZP installation in a limited virtual hosting environment, setting this two servers can be a little bit tricky. So here is how you'll do it...
Situation:
Demands:
In order for this to work we have to run the OO conversion server as a user which has access to all the eZP installations, and write access to their "var" folders - this is because the OO conversion server writes the converted file inside the "var" folder of the eZP instance that requested the conversion. So the idea goes like this:
0) Install pre-requisites
Install the usual pre-requisites for Solr and OO conversion daemons that are described in their documentation.
1) Create an user for starting daemons
Create a new user with a shell access (let's call it ezdaemon), or ask your server admin to do it.
2) Install OO conversion macro
Install the needed conversion macro for ezdaemon user. The instructions for installation of the macro can be found here:
http://doc22.ez.no/Extensions/ODF-Import-Export/eZODF-extension
Note: There's a way for running OpenOffice and our OO conversion server without installing an XWindows server on the server. It's described later in the "Tweaks" section of this post.
3) Extract the eZP installation
In the home folder of ezdaemon user unpack the eZP installation. We only need this to get the servers in ezfind and ezodf extensions. Note that the versions of this two extensions unpacked here must match (or be compatible with) the versions of the same extensions used in all of your eZP installations.
4) Create the wrapper scripts
Create the scripts for starting the daemons as a user under which is your web server running. Let's say it's "nobody" user. I have started from the RHEL script that comes with the ezfind extension, and modified it to suit this specific needs. I've attached the full scripts along with this post.
5) Install the scripts as daemons
Ask your server admin to install your scripts as daemons. If running RHEL or similar OS, just put the scripts in the "/etc/init.d/" folder.
Also, ask the server admin to give the user ezdaemon sudo privileges for this two scripts.
6) Run the daemons
Run the daemons using the wrapper script. For example like this:
sudo /etc/init.d/ezodf start sudo /etc/init.d/solr start
Prior to running them make sure that the needed ports are open on the server (the ports are described in the docs for both servers).
Usage: /etc/init.d/solr {start|stop|restart|reload|status}
Code:
#!/bin/bash # # eZ Find init script for RHEL and CENTOS. # # Usage: # # Set the correct SOLR_HOME value, and copy this file to /etc/init.d # Symlink to /etc/init.d/solr to /etc/rc3.d/S70solr and /etc/rc5.d/S70solr # # Example: # cp solr /etc/init.d/solr # cd /etc/init.d && chmod 755 solr # cd /etc/rc3.d && ln -s ../init.d/solr S70solr # cd /etc/rc5.d && ln -s ../init.d/solr S70solr # cd /etc/rc3.d && ln -s ../init.d/solr K70solr # cd /etc/rc5.d && ln -s ../init.d/solr K70solr DESC="Solr indexing server" NAME=solr JAVA_HOME= SOLR_HOME=/home/ezdaemon/ezpublish/extension/ezfind/java HOME=/home/ezdaemon LOGDIR=$HOME/log LOG_STDOUT=$LOGDIR/solr_stdout.log LOG_STDERR=$LOGDIR/solr_stderr.log source /etc/rc.d/init.d/functions for JAVA in "$JAVA_HOME/bin/java" "/usr/bin/java" "/usr/local/bin/java" do if [ -x $JAVA ] then break fi done if [ ! -x $JAVA ] then echo "Unable to locate java. Please set JAVA_HOME environment variable." exit fi RETVAL=0 d_start() { CURRENT_DIR=`pwd` daemon --user=nobody --check $NAME --pidfile $HOME/var/run/solr.pid "cd $SOLR_HOME && nohup $JAVA -jar $SOLR_HOME/start.jar" >> $LOG_STDOUT 2>> $LOG_STDERR & RETVAL=$? sleep 1 # Sleep 1 second, to make sure java is registered. pid=`pidof java` echo $pid > $HOME/var/run/solr.pid cd $CURRENT_DIR [ $RETVAL -eq 0 ] && su - nobody -c "touch $HOME/var/lock/subsys/$NAME" return $RETVAL } d_stop() { killproc -p $HOME/var/run/solr.pid $NAME >> /dev/null 2&>1 RETVAL=$? [ $RETVAL -eq 0 ] && rm -f $HOME/var/lock/subsys/$NAME echo "#$RETVAL#" return $RETVAL } d_restart() { d_stop >> /dev/null 2&>1 sleep 2 d_start >> /dev/null 2&>1 } d_reload() { killproc -p $HOME/var/run/solr.pid $NAME -HUP 2&>1 RETVAL=$? return $RETVAL } d_status() { status -p $HOME/var/run/solr.pid $NAME >> /dev/null 2&>1 return $? } case "$1" in start) echo " * Starting $DESC ($NAME)" d_status if [ $? -eq 0 ] then echo " ...already running." else if d_start then echo " ...done." else echo " ...failed." RETVAL=1 fi fi ;; stop) echo " * Stopping $DESC ($NAME)" if d_stop then echo " ...done." else echo " ...failed." RETVAL=1 fi ;; restart) echo " * Restarting $DESC ($NAME)" d_status if [ $? -ne 0 ] then echo " ...not running." RETVAL=1 else if d_restart then echo " * ...done." else echo " * ...failed." RETVAL=1 fi fi ;; reload) echo " * Reloading $DESC ($NAME): " d_reload echo " ...done." ;; status) d_status if [ $? -eq 0 ] then echo " * $DESC ($NAME) is running" else echo " * $DESC ($NAME) is not running" fi ;; *) echo $"Usage: $0 {start|stop|restart|reload|status}" RETVAL=1 esac exit $RETVAL
Usage: /etc/init.d/ezodf {start|stop|restart|reload|status}
Code:
#!/bin/bash # # eZ ODF Conversion daemon init script for RHEL and CENTOS. # # Usage: # # Set the correct folder variables values, and copy this file to /etc/init.d # Symlink to /etc/init.d/ezodf to /etc/rc3.d/S70ezodf and /etc/rc5.d/S70ezodf # # Example: # cp ezodf /etc/init.d/ezodf # cd /etc/init.d && chmod 755 ezodf # cd /etc/rc3.d && ln -s ../init.d/ezodf S70ezodf # cd /etc/rc5.d && ln -s ../init.d/ezodf S70ezodf # cd /etc/rc3.d && ln -s ../init.d/ezodf K70ezodf # cd /etc/rc5.d && ln -s ../init.d/ezodf K70ezodf DESC="eZ ODF Conversion daemon" NAME=ezodf HOME=/home/ezdaemon VARDIR=$HOME/var LOGDIR=$HOME/log LOG_STDOUT=$LOGDIR/${NAME}_stdout.log LOG_STDERR=$LOGDIR/${NAME}_ezodf_stderr.log SCRIPT=$HOME/ezpublish/extension/ezodf/scripts/daemon.php PHP=/usr/local/bin/php PIDFILE=$VARDIR/run/ezodf.pid source /etc/rc.d/init.d/functions RETVAL=0 d_start() { CURRENT_DIR=`pwd` daemon --user=nobody --check $NAME --pidfile $PIDFILE "nohup $PHP $SCRIPT" >> $LOG_STDOUT 2>> $LOG_STDERR & RETVAL=$? sleep 1 pid=`pgrep -u nobody php` echo $pid > $PIDFILE cd $CURRENT_DIR [ $RETVAL -eq 0 ] && su - nobody -c "touch $VARDIR/lock/subsys/$NAME" return $RETVAL } d_stop() { killproc -p $PIDFILE $NAME >> /dev/null 2&>1 RETVAL=$? [ $RETVAL -eq 0 ] && rm -f $VARDIR/lock/subsys/$NAME return $RETVAL } d_restart() { d_stop >> /dev/null 2&>1 sleep 1 d_start >> /dev/null 2&>1 } d_reload() { killproc -p $PIDFILE $NAME -HUP 2&>1 RETVAL=$? return $RETVAL } d_status() { status -p $PIDFILE $NAME >> /dev/null 2&>1 return $? } case "$1" in start) echo " * Starting $DESC ($NAME)" d_status if [ $? -eq 0 ] then echo " ...already running." else if d_start then echo " ...done." else echo " ...failed." RETVAL=1 fi fi ;; stop) echo " * Stopping $DESC ($NAME)" if d_stop then echo " ...done." else echo " ...failed." RETVAL=1 fi ;; restart) echo " * Restarting $DESC ($NAME)" d_status if [ $? -ne 0 ] then echo " ...not running." RETVAL=1 else if d_restart then echo " * ...done." else echo " * ...failed." RETVAL=1 fi fi ;; reload) echo " * Reloading $DESC ($NAME): " d_reload echo " ...done." ;; status) d_status if [ $? -eq 0 ] then echo " * $DESC ($NAME) is running" else echo " * $DESC ($NAME) is not running" fi ;; *) echo $"Usage: $0 {start|stop|restart|reload|status}" RETVAL=1 esac exit $RETVAL
1) OpenOffice without the XWindows Server
If you want to run OpenOffice without the XWindows Server (which can spare you some headaches) you have to run it with the -headless parameter. To add this parameter you will have to edit the extension/ezodf/scripts/daemon.php script inside the eZP installation of the ezdaemon user. Just change this line:
$convertShellCommand = escapeshellcmd( $ooexecutable . " -writer -invisible" ) . " " .
to this:
$convertShellCommand = escapeshellcmd( $ooexecutable . " -writer -invisible -headless" ) . " " .
I have also proposed an enhancement that would allow to do this without hacking the script:
http://issues.ez.no/IssueView.php?Id=17308&activeItem=1
2) Running on non default ports
It's recommended to run the Solr and OO conversion server on non default ports. First, it's generally more secure not use default ports. And second, in this way you leave the default port free for some quick testings of new eZP installations.
To change the port on which the OO conversion server runs, you'll have to edit extension/ezodf/scripts/daemon.php inside the eZP installation for ezdeamon user and change the value of the $port variable.
To change the port for Solr server you'll have to edit /extension/ezfind/java/etc/jetty.xml in the eZP instllation of ezdaemon user. It's defined in the line that goes like this:
<Set name="port"><SystemProperty name="jetty.port" default="8983"/></Set>
eZFind: http://doc.ez.no/Extensions/eZ-Find/2.1/
eZODF: http://doc22.ez.no/Extensions/ODF-Import-Export/eZODF-extension