Tu sei qui: Portale > Plone > Init script per ubuntu
Accedi


Hai dimenticato la tua password?
« febbraio 2012 »
febbraio
lumamegivesado
12345
6789101112
13141516171819
20212223242526
272829
 

Init script per ubuntu

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
— archiviato sotto: , , ,

Semplice howto per avere uno script di init per il nostro amato CMS plone su ubuntu

Premessa

Il codice contenuto in questo howto è stato sviluppato e testato per Plone 3.3.x e ubunutu LTS 10.04.

Il cuore

Lo script plone da porre nella directory /etc/init.d/plone:

#! /bin/sh
### BEGIN INIT INFO
# Provides:          plone
# Required-Start:    $local_fs $remote_fs $network $syslog
# Required-Stop:     $local_fs $remote_fs $network $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Plone init script
# Description:       Ubuntu init script for plone. Tested only 
#                    on plone 3.x
### END INIT INFO

# Author: Amedeo Salvati <amedeo.salvati@gmail.com>
#

# Do NOT "set -e"

# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="Plone CMS service"
NAME=plone
DAEMON_DIR=
DAEMON_ARGS=""
SCRIPTNAME=/etc/init.d/$NAME

# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME

# where plone reside
DAEMON_DIR=$PLONE_HOME

# Exit if the package is not installed
[ -d "$DAEMON_DIR" ] || exit 0

# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh

# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions

#
# Function that starts the daemon/service
#
do_start()
{
	# Return
	#   0 if daemon has been started
	#   1 if daemon was already running
	#   2 if daemon could not be started
	for i in $PLONE_START
	do
		log_daemon_msg "Starting: $i"
		CMD="su -c '${PLONE_HOME}/bin/${i} start' ${PLONE_USER}"
		STATUS=`eval $CMD `
		#echo $STATUS
		LEN=`echo $STATUS | grep 'daemon process already running' `
		if [ "$LEN" != "" ]; then
			echo -n "    "
			echo -n "Daemon $i already running with pid: "
			LEN=`echo $LEN | awk '{ print $5 }' | sed 's/pid=//g' `
			echo -n $LEN
			log_end_msg 1
		else
			LEN=`echo $STATUS | grep 'daemon process started' `
			if [ "$LEN" != "" ]; then
				echo -n "    "
				echo -n "Daemon $i started with pid: "
				LEN=`echo $LEN | awk '{ print $5 }' | sed 's/pid=//g' `
				echo -n $LEN
				log_end_msg 0
			else
				log_end_msg 2
			fi
		fi
		sleep ${SLEEP_SECOND}
	done
}

#
# Function that stops the daemon/service
#
do_stop()
{
	# Return
	#   0 if daemon has been stopped
	#   1 if daemon was already stopped
	#   2 if daemon could not be stopped
	#   other if a failure occurred
	for i in $PLONE_STOP
	do
		log_daemon_msg "Stopping: $i"
		CMD="su -c '${PLONE_HOME}/bin/${i} stop' ${PLONE_USER}"
		STATUS=`eval $CMD `
		#echo $STATUS
		LEN=`echo $STATUS | grep 'daemon process stopped' `
		if [ "$LEN" != "" ]; then
			log_end_msg 0
		else
			LEN=`echo $STATUS | grep 'daemon manager not running' `
			if [ "$LEN" != "" ]; then
				echo -n "    "
				echo -n "Daemon $i was already stopped"
				log_end_msg 1
			else
				log_end_msg 2
			fi
		fi
		sleep ${SLEEP_SECOND}
	done
}

#
# Function that sends a SIGHUP to the daemon/service
#
do_reload() {
	#
	# If the daemon can reload its configuration without
	# restarting (for example, when it is sent a SIGHUP),
	# then implement that here.
	#
	start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
	return 0
}

do_status() {
	# Return
	#   0 if daemon is running
	#   2 if daemon is not running
	for i in $PLONE_START
	do
		log_daemon_msg "Status: $i"
		CMD="su -c '${PLONE_HOME}/bin/${i} status' ${PLONE_USER}"
		STATUS=`eval $CMD `
		#echo $STATUS
		LEN=`echo $STATUS | grep 'program running' `
		if [ "$LEN" != "" ]; then
			echo -n "    "
			echo -n "Daemon $i is running with pid: "
			LEN=`echo $LEN | awk '{ print $3 }' | sed 's/pid=//g' `
			echo -n $LEN
			log_end_msg 0
		else
			echo -n "    "
			echo -n "Daemon $i is NOT running"
			log_end_msg 2
		fi
	done
}

case "$1" in
  start)
	[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
	do_start
	case "$?" in
		0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
		2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
	esac
	;;
  stop)
	[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
	do_stop
	case "$?" in
		0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
		2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
	esac
	;;
  status)
  	do_status
	case "$?" in
		0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
		2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
	esac
    ;;
  #reload|force-reload)
	#
	# If do_reload() is not implemented then leave this commented out
	# and leave 'force-reload' as an alias for 'restart'.
	#
	#log_daemon_msg "Reloading $DESC" "$NAME"
	#do_reload
	#log_end_msg $?
	#;;
  restart|force-reload)
	#
	# If the "reload" option is implemented then remove the
	# 'force-reload' alias
	#
	log_daemon_msg "Restarting $DESC" "$NAME"
	do_stop
	case "$?" in
	  0|1)
		do_start
		case "$?" in
			0) log_end_msg 0 ;;
			1) log_end_msg 1 ;; # Old process is still running
			*) log_end_msg 1 ;; # Failed to start
		esac
		;;
	  *)
	  	# Failed to stop
		log_end_msg 1
		;;
	esac
	;;
  *)
	#echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
	echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
	exit 3
	;;
esac

:

Il file di configurazione

Il classico file di configurazione per plone da porre nella directory /etc/default/plone:

#
# Configuration file for plone service
#

# user who start instance
PLONE_USER=plone

# home
PLONE_HOME=/home/plone/site

# instances to start
PLONE_START="zeoserver instance01 instance02"

# instances to stop
PLONE_STOP="instance02 instance01 zeoserver"

# sleep time bt starting instance
SLEEP_SECOND=5

Configurazione di default/plone

Controllare il file /etc/default/plone verificando quali istanze far partire e con quale ordine, ovvero la variabile PLONE_START definirà la sequenza di avvio, mentre la variabile PLONE_STOP definirà la sequenza di stop. La variabile PLONE_USER definisce l'utenza con la quale avviare il servizio ed in ultimo SLEEP_SECOND indicherà quanti secondi aspettare tra l'avvio di un'istanza e quella successiva.

Pronti per il via

Una volta configurato il tutto non resta che istruire la nostra macchina ubuntu su quando effettuare l'avvio del servizio plone, per fare questo ci viene in aiuto il comando update-rc.d. Da terminale eseguire:

$ sudo update-rc.d plone defaults

Questo farà si che il servizio venga startato nei runlevel 2, 3, 4, e 5 anche se il runlevel utilizzato da ubuntu è soltanto il 2.

Sorgenti

I sorgenti del codice sopra esposto è possibile reperirlo presso su github.

Azioni sul documento