Sunday 16 May 2010

Alfresco Ubuntu/Postgres install - in a nutshell

I'd known of Alfresco for a couple of years and have even installed it a few time to see what was on offer (versus the likes of Sharepoint), with upcoming projects under the www.appfusions.com umbrella, the Confluence - Alfresco plugin has caused me to see whats new in Alfresco 3.3. The Alfresco Install Guide for the installation is pretty comprehensive, I'm only giving the Autobahn subset:

Installation

The install bundled idea is appealing to some people but perhaps the engineer in me just wants to know what is being installed, where and why. So I opted for the *alfresco-community-tomcat-3.3.tar.gz* download.

Extracting

What could go wrong? Kaboom, instant tarball explosion (ALF-2820 duly raised!), grrrr, and only a little mopping up later, I unpacked the tarball in /usr/local/apps/alfresco-3.3.

Database

I use Postgresql for pretty much everything these days. Getting Alfresco to work is straight forward, just create an alfresco database, alfresco user and set its password to, yea, alfresco.

Getting the database driver, surely I would have a copy around the place, but no, so download that and dump in INSTALL_ROOT/tomcat/lib. As I'm using JRE 1.6, I get the JDBC4 version.

Configuration file changes

Next up we need to tweak a config file located at INSTALL_ROOT/tomcat/shared/classes/alfresco-global.properties. Its annoying to find in a linux .tgz distribution that the properties files have got the windows line ending characters (^M), this can be cured with apt-get install tofrodos, more annoyingly, the names of the binaries in the latest 10.04 Ubuntu have changed, used to be 'dos2unix' and 'unix2dos', now, its 'fromdos' and 'todos', ah well, progress. So to strip the ^M do this from the alfresco install dir:

fromdos ./tomcat/shared/classes/alfresco-global.properties

From the documentation the following need to be applied and overridden:

db.driver=org.postgresql.Driver
db.name=alfresco
db.url=jdbc:postgresql://localhost/
db.username=alfresco
db.password=alfresco
hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
hibernate.query.substitutions=true TRUE, false FALSE

One final tweak to the config file was external storage:

dir.root=/srv/alf_data

Starting up

There is a startup script alfresco.sh, it only responds to 'start' and 'stop' arguments, but thats fine for testing. To startup automatically I did the following:

  • Create a alfresco user.

  • Modify the 'alfresco.sh' script to validate who is running it, prevents user ownership issues, inject the following at the top of the script (after line1)

    ALFRESCO_USER=alfresco
    if [ ! "`whoami`" = "$ALFRESCO_USER" ];
    then
    echo "Alfresco must be run as [$ALFRESCO_USER] user, not as ["`whoami`"] (current user)"
    exit
    fi

  • Use the following startup script, it wraps the a alfresco script, and runs it as that user:

    #! /bin/sh
    ### BEGIN INIT INFO
    # Provides: skeleton
    # Required-Start: $remote_fs
    # Required-Stop: $remote_fs
    # Default-Start: 2 3 4 5
    # Default-Stop: 0 1 6
    # Short-Description: Example initscript
    # Description: This file should be used to construct scripts to be
    # placed in /etc/init.d.
    ### END INIT INFO

    #
    # Please remove the "Author" lines above and replace them
    # with your own name if you copy and modify this script.

    # Do NOT "set -e"

    # PATH should only include /usr/* if it runs after the mountnfs.sh script
    PATH=/sbin:/usr/sbin:/bin:/usr/bin
    ALFRESCO_HOME=/usr/local/apps/alfresco/alfresco-community-tomcat-3.3
    DESC="Alfresco"
    NAME=alfresco
    DAEMON=${ALFRESCO_HOME}/${NAME}.sh
    #DAEMON_ARGS="--options args"
    PIDFILE=/var/run/$NAME.pid
    SCRIPTNAME=/etc/init.d/$NAME

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

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

    # 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
    echo calling start
    start-stop-daemon --chuid alfresco --start --quiet --pidfile $PIDFILE --exec $DAEMON start --test > /dev/null \
    || return 1
    start-stop-daemon --chuid alfresco --start --quiet --pidfile $PIDFILE --exec $DAEMON start -- \
    $DAEMON_ARGS \
    || return 2
    # Add code here, if necessary, that waits for the process to be ready
    # to handle requests from services started subsequently which depend
    # on this one. As a last resort, sleep for some time.
    }

    #
    # 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
    start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
    RETVAL="$?"
    [ "$RETVAL" = 2 ] && return 2
    # Wait for children to finish too if this is a daemon that forks
    # and if the daemon is only ever run from this initscript.
    # If the above conditions are not satisfied then add some other code
    # that waits for the process to drop all resources that could be
    # needed by services started subsequently. A last resort is to
    # sleep for some time.
    start-stop-daemon --chuid alfresco --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON stop
    [ "$?" = 2 ] && return 2
    # Many daemons don't delete their pidfiles when they exit.
    rm -f $PIDFILE
    return "$RETVAL"
    }

    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
    ;;
    restart)
    #
    # 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}" >&2
    exit 3
    ;;
    esac


  • In /etc/init.d, register the alfresco script to be auto started with
    update-rc.d alfresco start 99 2 3 4 5 .



Other packages


I found stacks in the log like:

Execution result:
os: Linux
command: [./bin/pdf2swf, -V]
succeeded: false
exit code: 1
out:
err: Cannot run program "./bin/pdf2swf": java.io.IOException: error=2, No such file or directory

To fix this, you need to install swfutils, install with 'sudo apt-get install swfutils'.

Starting should now be a matter of /etc/init.d/alfresco start. The default port is :8080

More on usage and integration next time.

1 comment:

Anonymous said...

thanks, really appreciate your init.d script for alfresco