Month: November 2012

OpenDJ & OpenAM automatic startup on Ubuntu


I have been installing the ForgeRock stack on Ubuntu a lot lately.  One of the things that I noticed is that when configuring OpenAM and OpenDJ for automatic startup you need to let OpenDJ finish starting up before starting Tomcat (OpenAM) … otherwise OpenAM will not be able to find it’s configuration and assume that it’s a new install.  I added a timer to the start up script to make the script sleep for a minute before starting (YMMV) Mark Craig (from ForgeRock) clued me into a nice little bit of code “start on started opendj” essentially this tells the startup script to wait until opendj has started before starting Tomcat.  Thanks Mark, that’s exactly what I was looking for.

OpenDJ

cd [install dir]/opendj/bin

sudo ./create-rc-script -f /etc/init.d/opendj -u [user to run as]

cd /etc/init.d

sudo update-rc.d opendj defaults

OpenAM [on Tomcat]

sudo vi /etc/init.d/tomcat

Now paste the following content:

    # Tomcat auto-start
    #
    # description: Auto-starts tomcat
    # start tomcat with user: ubuntu
    # pidfile: /var/run/tomcat.pid

    export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64

    case $1 in
    start)
            start on started opendj
            /bin/su ubuntu /opt/tomcat/bin/startup.sh
            ;;
    stop)
            /bin/su ubuntu /opt/tomcat/bin/shutdown.sh
            ;;
    restart)
            /bin/su ubuntu /opt/tomcat/bin/shutdown.sh
            /bin/su ubuntu /opt/tomcat/bin/startup.sh
            ;;
    esac
    exit 0

Make the script executable by running the chmod command:

sudo chmod 755 /etc/init.d/tomcat

The last step is linking this script to the startup folders with a symbolic link. Run the following two commands:.

sudo ln -s /etc/init.d/tomcat /etc/rc1.d/K99tomcat

sudo ln -s /etc/init.d/tomcat /etc/rc2.d/S99tomcat

Restart the system and tomcat will start automatically.