Share » Learn » eZ Publish » Running eZ Publish daemons in shared...

Running eZ Publish daemons in shared virtual hosting environment

Wednesday 16 March 2011 3:51:46 am

  • Currently 4 out of 5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

OpenOffice startup script

To start the OpenOffice conversion server, we use the same script, modified to run the conversion daemon.

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}_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
 
36 542 Users on board!

Tutorial menu

Printable

Printer Friendly version of the full article on one page with plain styles

Author(s)