Automatic Plone (re)starts

Introduction

Tips on how to automatically start Plone on server boot.

This manual assumes, that you are installed Plone via the Unified-Installer as root install if you did a different install, please addjust the examples below for your own needs, the user as which you are running Plone maybe different for example.

plonectl script

The general-purpose plonectl control command for Plone installations is:

yourbuildoutfolder/bin/plonectl

yourbuildoutfolder is the topmost folder of your Plone installation. It will always contain a buildout.cfg file and a bin directory.

The plonectl command is a convenience script that controls standalone or cluster configurations. In a standalone installation, this will restart the instance part. In a ZEO cluster install it will restart the zeoserver and client parts.

If you have installed Plone in production mode, the Plone server components are meant to be run as a special user, usually plone_daemon. (In older versions, this was typically plone.) In this case, the start, stop and restart commands are:

# start
sudo -u plone_daemon bin/plonectl start
#
# stop
sudo -u plone_daemon bin/plonectl stop
#
# restart
sudo -u plone_daemon bin/plonectl restart

Starting on boot

It is best practice to start Plone service if the server is rebooted. This way your site will automatically recover from power loss etc.

On a Linux or BSD system, you have two major alternatives to arrange automatic starting for a production install:

  1. A process-control system, like supervisor.
  1. Through init.d (BSD rc.d) scripts.

Using supervisor

supervisor is a general-purpose process-control system that is well-known and highly recommended in the Plone community.

Process-control systems generally run their controlled programs as subprocesses. This means that the controlled program must not detach itself from the console (daemonize).

Zope/Plone's "start" command does not work for this purpose. Instead use console. Do not use fg which turns on debug switches that will dramatically slow your site.

Supervisor is well-documented, easy to set up, and included as an instalable package with popular Linux and BSD distributions.

Debian LSBInitScripts

Short documentation about how to make an Init Script LSB

This example will start a plone site on boot:

#!/bin/sh
### BEGIN INIT INFO
# Provides:          start_plone.sh
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Should-Start:      my plone site
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start plone at boot time
# Description:       Start my plone site at boot time
#
#
#
#
### END INIT INFO

su - plone_daemon -c "/usr/local/Plone/zeocluster/bin/plonectl start"

Save this script as start_plone.sh in /etc/init.d and make it executable.

add the script to dependency-based booting:

insserv start_plone.sh

Where start_plone.sh is an executable init script placed in /etc/init.d, insserv will produce no output if everything went OK. Examine the error code in $? if you want to be sure.

This another example (/etc/init.d/plone):

#!/bin/sh

### BEGIN INIT INFO
# Provides:          plone
# Required-Start:    $syslog $remote_fs
# Required-Stop:     $syslog $remote_fs
# Should-Start:      $remote_fs
# Should-Stop:       $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start plone instances
# Description:       Start the instances located at /srv/Plone/zeocluster/bin/plonectl
### END INIT INFO

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

[ -f /usr/local/Plone/zeocluster/bin/plonectl ] || exit 0

DAEMON=/usr/local/Plone/zeocluster/bin/plonectl
NAME="plone "
DESC="daemon zeoserver & client"

. /lib/lsb/init-functions

case "$1" in
    start)
        log_daemon_msg "Starting $DESC" "$NAME"
        if start-stop-daemon --quiet --oknodo --chuid plone:plone \
                             --exec ${DAEMON} --start start
        then
            log_end_msg 0
        else
            log_end_msg 1
        fi
        ;;

    stop)
        log_daemon_msg "Stopping $DESC" "$NAME"
        if start-stop-daemon --quiet --oknodo --chuid plone:plone \
                             --exec ${DAEMON} --start stop
        then
            log_end_msg 0
        else
            log_end_msg 1
        fi
        ;;

    restart)
        log_daemon_msg "Restarting $DESC" "$NAME"
        if start-stop-daemon --quiet --oknodo --chuid plone:plone \
                             --exec ${DAEMON} --start restart
        then
            log_end_msg 0
        else
            log_end_msg 1
        fi
        ;;

    status)
        start-stop-daemon --chuid plone:plone \
                            --exec ${DAEMON} --start status
        ;;

    force-reload)
        echo "Plone doesn't support force-reload, use restart instead."
        ;;

    *)
        echo "Usage: /etc/init.d/plone {start|stop|status|restart}"
        exit 1
        ;;
esac

exit 0

Make sure to read:

http://wiki.debian.org/LSBInitScripts

Upstart

Upstart is an event-based replacement for the /sbin/init daemon which handles starting of tasks and services during boot, stopping them during shutdown and supervising them while the system is running. It was originally developed for the Ubuntu distribution, but is intended to be suitable for deployment in all Linux distributions as a replacement for the venerable System-V init.

Example of a plone.conf file in /etc/init/ -> /etc/init/plone.conf:

# Plone - Web-Content Management System
#
# Based on Python and ZOPE

description "start plone"
author "Josh Sehn based on previous work by Christoph Glaubitz"
version "0.3"

console none
respawn

start on (local-filesystems and net-device-up and runlevel [2345])
stop on runlevel [!2345]

exec sudo -u plone_daemon /usr/local/Plone/zeocluster/bin/plonectl start

Make sure to read: http://upstart.ubuntu.com/

Also check the original source of this sample file: http://chrigl.de/blogentries/my-plone-configuration

The above sample has not been extensively tested and is intended for use with in a zeocluster configuration. To use the above sample for a normal (non-root) user installation, replace the last line with:

exec /home/$USERID/Plone/plonectl start

Systemd

Create services file plone.service in /etc/systemd/system:

[Unit]
Description=Plone content management system
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/Plone/zeocluster/bin/plonectl start
ExecStop=/usr/local/Plone/zeocluster/bin/plonectl stop
ExecReload=/usr/local/Plone/zeocluster/bin/plonectl restart

[Install]
WantedBy=multi-user.target

Make systemd take notice of it:

systemctl daemon-reload

Activate a service immediately:

systemctl start plone.service

Check status of service:

systemctl status plone.service

Enable a service to be started on bootup:

systemctl enable plone.service

More detailed log information:

systemd-journalctl -a

Make sure to read: http://www.freedesktop.org/wiki/Software/systemd/

Crontab

These instructions apply for Debian-based Linuxes.

Example crontab of yourploneuser:

@reboot /usr/local/Plone/zeocluster/bin/plonectl start

rc.local script

For Debian-based Linuxes, add the following line to the /etc/rc.local script:

/usr/local/Plone/zeocluster/bin/plonectl restart

Table Of Contents

About Plone

This is documentation for Plone®. Plone is a popular, open source, content management system written in Python programming language.

Contributors

This documentation page was brought you by these awesome persons:

Edit this document

The source code of this file is hosted on GitHub. Everyone can update and fix errors in this document with few clicks - no downloads needed.

  1. Go to Automatic Plone (re)starts on GitHub.
  2. Press the Fork button. This will create your own personal copy of the documentation.
  3. Edit files using GitHub's text editor in your web browser
  4. Fill in the Commit message text box at the end of the page telling why you did the changes. Press the Propose file change button next to it when done.
  5. Then head to the Send a pull request page (you won't need to fill in any additional text). Just press Send pull request button.
  6. Your changes are now queued for review under project's Pull requests tab on Github.

For basic information about updating this manual and Sphinx format please see Writing and updating the manual guide.