AnsweredAssumed Answered

New ubuntu boot script

Question asked by loonsailor on Nov 17, 2008
Latest reply on Feb 6, 2009 by howardjacobson
I've written a new bootup script for alfresco labs 3.0, which can be added to init.d and managed with boot-up manager (BUM).  There were a couple kicking around, but they didn't work for me, so I wrote my own. 

#! /bin/sh -e
# Provides:          alfresco
# Required-Start:    $syslog $time $network
# Required-Stop:     $syslog $time $network
# Default-Start:     2 3 4 5
# Default-Stop:      1
# Short-Description: Alfresco doeument control system
# Description:       Debian init script for the Alfresco document and content management system
# Author:   Jerry Fiddler
set -e

# Set the following.

#  Location of the alfresco start/stop script

# user ID under which to run alfresco.  This is important because the "stop" version of this script will limit the processes to those with this UID, rather than stopping all java processes

# process name of the alfresco process


test -x $ALFRESCOSCRIPT || exit 0

. /lib/lsb/init-functions

case "$1" in
   log_daemon_msg "Starting alfresco"
   start-stop-daemon –start –oknodo –user $ALFRESCOUSER –name $ALFRESCOPROCNAME –startas $ALFRESCOSCRIPT –chuid $ALFRESCOUSER – start
   log_end_msg $?
   log_daemon_msg "Stopping deferred execution scheduler" "atd"

   # This next line shouldn't be necessary, but for some reason doesn't kill the actual java process running alfresco.
   # So, this does it explicitly
   killall -u alfresco java

   log_end_msg $?
    echo "Usage: /etc/init.d/alfresco {start|stop}"
    exit 1

exit 0

Just put it in a file in /etc/init.d, make sure the file is executable, check that the variables early in the file are right for your system (You'll probably need to change the script location variable), then run bootup-manager (System->Administration->bootup-manager) and enable it. Alfresco will run automatically when you boot.

A couple of points to note about the script.  For some reason (a bug?) when I stop alfresco (with " stop" or "" or "/etc/init.d/alfresco stop") the java process running alfresco doesn't quit.  So, I added a killall in this init.d script to explicitly kill that process.  It also, as a side benefit, kills the open office child process that alfresco creates.  In order to do that, it needs to "killall java".  Since there might be other java processes in a system unrelated to alfresco that one might not want to kill, the killall constrains to the "alfresco" user.  The script runs alfresco as the alfresco user, rather than as root, which seems like good practice in any event.

Therefore, it is important to create an alfresco user (I made an alfresco group as well, though this isn't essential), and make sure all the files in the alfresco tree, especially the repository, are owned by alfresco, or at least are read-write for alfresco.  If in doubt, go to the alfresco root directory and execute the following:
>sudo chown -R alfresco *
>sudo chgrp -R alfresco *
Also, for some reason one of the directories in the openoffice tree was read-only and owned by root, so that alfresco running as the alfresco user (and not root) couldn't start it.  If you have this problem, go down the open office directory tree (/usr/lib/openoffice/program on my computer) and make sure everything can be read and executed by everyone.