cancel
Showing results for 
Search instead for 
Did you mean: 

Does anyone have a nice /etc/init.d/alfresco script?

tvaughan77
Champ in-the-making
Champ in-the-making
Hi,

Does anyone have a nice *nix based alfresco startup script they can share?  I'm looking for something that does a good job running the /opt/alfresco/alfresco.sh as a non-root user, and making sure both the alfresco and virtual tomcat servers are started…

Thanks,
Tom
2 REPLIES 2

jottley
Confirmed Champ
Confirmed Champ
Here is one that covers most of what you are after.  It starts alfresco using alfresco.sh.  It starts the alfresco virtual server if found. It updates the virtual server config to reflect you servers IP address for previews.

It *does not* change to a non system user. That should actually be pretty easy to add. 

It lives here: http://svn.ottleys.net/alfresco/init/ubuntu/alfresco 

Don't forget that if you do want to run Alfresco as a non root user and you need ftp, cifs and/or nfs you need to use port forwarding as discussed here: http://wiki.alfresco.com/wiki/File_Server_Configuration#Running_SMB.2FCIFS_from_a_normal_user_accoun...


#!/bin/bash
#
# alfresco      This shell script takes care of starting and stopping alfresco
#
#               author: Jared Ottley
#               email:   jared dot ottley at alfresco dot com
#
# chkconfig: - 80 20
#
### BEGIN INIT INFO
# Provides: alfresco
# Required-Start: $network $syslog
# Required-Stop: $network $syslog
# Default-Start:
# Default-Stop:
# Description: Alfresco Enterprise Content Management 2.1.1
# Short-Description: start and stop alfresco
### END INIT INFO
#

NAME="$(basename $0)"
unset ISBOOT
if [ "${NAME:0:1}" = "S" -o "${NAME:0:1}" = "K" ]; then
    NAME="${NAME:3}"
    ISBOOT="1"
fi

# Path to alfresco root dir
_ALFRESCO="/opt/alfresco"

# Path to the alfresco launch script
_SCRIPT="${_ALFRESCO}/alfresco.sh"

# Alfresco program name
_PROG="$NAME"

export JAVA_HOME=/usr/lib/jvm/java-1.5.0-sun

SHUTDOWN_WAIT=30

RETVAL="0"

function checkpid() {
    local i
    for i in $* ; do
        if [ -d "/proc/${i}" ]; then
            return 0
        fi
    done
    return 1
}

function echo_failure() {
    echo -en "\\033[60G"
    echo -n "[  "
    echo -n $"FAILED"
    echo -n "  ]"
    echo -ne "\r"
    return 1
}

function echo_success() {
    echo -en "\\033[60G"
    echo -n "[  "
    echo -n $"OK"
    echo -n "  ]"
    echo -ne "\r"
    return 0
}

function getIP() {
   ipaddr=""

    inet=$(ip addr show dev eth0 | grep "inet")

   if [ "$inet" != "" ]; then
          set – $inet
          shift
      
      echo ${1%%/*} | grep -E \([0-9]\{1,3\}.\{3\}\)[0-9]\{1,3\} > /dev/null

      if [ $? -ne 1 ]; then
             ipaddr=$(echo ${1%%/*} | sed -e s/[.]/-/g)
      fi
   fi

   if [ $ipaddr = "" ]; then
      return -1
   fi
}

function updateVirtDomain() {
   virt_server=${_ALFRESCO}/virtual-tomcat/conf/alfresco-virtserver.properties
   virt_server_property=alfresco.virtserver.domain
   
   if [ -e $virt_server ]; then
      grep -E ^alfresco\.virtserver\.domain=\([0-9]\{1,3\}-\)\{3\}[0-9]\{1,3\} $virt_server
      if [ $? -eq 0 ]; then
         sed -i -r -e s/^${virt_server_property}=\([0-9]\{1,3\}-\)\{3\}[0-9]\{1,3\}/${virt_server_property}=${ipaddr}/ \
         $virt_server
      else
         sed -i -r -e s/^${virt_server_property}=/${virt_server_property}=${ipaddr}/ \
         $virt_server
      fi
   fi
}

# See how we were called.
function start() {
    echo -n "Starting ${_PROG}: "
        if [ -f "/var/run/${NAME}.pid" ]; then
            read kpid < /var/run/${NAME}.pid
                if checkpid $kpid 2>&1; then
                    echo "$NAME process already running"
                        return -1
                    else
                        echo "lock file found but no process running for"
                        echo "pid $kpid, continuing"
                fi
        fi
   
   ###Insert start script here###
   getIP
   if [ $? -ne -1 ]; then
      updateVirtDomain
   else
      echo_failure
      exit
   fi   
   $_SCRIPT start

    RETVAL="$?"
    if [ "$RETVAL" -eq 0 ]; then
   sleep 3
   pidof -s java > /var/run/${NAME}.pid
        echo_success
    else
        echo_failure
    fi
    echo
    return $RETVAL
}

function status() {
    RETVAL="1"
    if [ -f "/var/run/${NAME}.pid" ]; then
        read kpid < /var/run/${NAME}.pid
        if checkpid $kpid 2>&1; then
            echo "$0 is already running (${kpid})"
            RETVAL="0"
        else
            echo "lock file found but no process running for pid $kpid"
        fi
    else
        pid="$(pgrep -u root java)"
        if [ -n "$pid" ]; then
            echo "$0 running (${pid}) but no PID file exists"
            RETVAL="0"
        else
            echo "$0 is stopped"
        fi
    fi
    return $RETVAL
}

function stop() {
    local STOP_VERBOSE="false"
    echo -n "Stopping $_PROG: "
       
   ###Insert Stop script here###
   $_SCRIPT stop

   RETVAL="$?"
        if [ "$RETVAL" -eq "0" ]; then
            count="0"
            if [ -f "/var/run/${NAME}.pid" ]; then
                read kpid < /var/run/${NAME}.pid
                until [ "$(ps –pid $kpid | grep -c $kpid)" -eq "0" ] || \
                      [ "$count" -gt "$SHUTDOWN_WAIT" ]; do
                    if [ "$STOP_VERBOSE" = "true" ]; then
                        echo -n -e "\nwaiting for processes $kpid to exit"
                    fi
                    sleep 1
                    let count="${count}+1"
                done
                if [ "$count" -gt "$SHUTDOWN_WAIT" ]; then
                    if [ "$STOP_VERBOSE" = "true" ]; then
                        echo -n -e "\nkilling processes which didn't stop"
                        echo -n -e "after "
                        echo -n "$SHUTDOWN_WAIT seconds"
                    fi
                    kill -9 $kpid
                fi
                echo_success
                if [ "$count" -gt "0" ]; then
                    echo -n -e "\n"
                fi
            fi
       rm -f /var/run/${NAME}.pid
   else
      echo_failure
   fi   
}


# See how we were called.
case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    restart)
        stop
        sleep 2   
        start
        ;;
    status)
        status
        ;;
    *)
        echo "Usage: $_PROG {start|stop|restart|status}"
        exit 1
esac

exit $RETVAL

bkoszut
Champ in-the-making
Champ in-the-making
/etc/init.d/alfresco


#!/bin/sh
#
# Alfresco startup script
#

tomcatPID=`ps -ef|grep "/opt/Alfresco/tomcat"|grep java| awk '{print $2}'`
virtualTomcatPID=`ps -ef|grep "/opt/Alfresco/virtual-tomcat"|grep java| awk '{print $2}'`
ip=`/sbin/ifconfig eth0|grep "inet addr"|awk '{print $2}'|sed "s/addr://"`

case "$1" in
  start)
   echo "Today's IP address is $ip"
   /opt/Alfresco/virtual_alf.sh start $ip
   /opt/Alfresco/alfresco.sh start
   ;;
  stop)
   /opt/Alfresco/alfresco.sh stop
   if ! test -z $tomcatPID
   then
      echo "Killing Tomcat process $tomcatPID"
      kill -9 $tomcatPID
   fi
   /opt/Alfresco/virtual_alf.sh stop
   if ! test -z $virtualTomcatPID
   then
      echo "Killing Virtual Tomcat process $virtualTomcatPID"
      kill -9 $virtualTomcatPID
   fi
   ;;
  restart)
   $0 stop
   sleep 1
   $0 start
   ;;
  *)
   echo "Usage: $0 {start|stop|restart}"
   exit 1
   ;;
esac

exit 0

And modified JAVA_OPTS in /opt/Alfresco/virtual-tomcat/bin/catalina.sh


JAVA_OPTS="$JAVA_OPTS "-Djava.rmi.server.hostname=$2