Image of a power switch

Starting and Stopping Alfresco the Admin Way : Using Init

Running a Java process as a service has always been somewhat messy and causing headaches. In the typical case of the tomcat lifecyle, there are usually are a bunch of shell scripts involved. This post gives a recipe to hook Alfresco system lifecyle to init and to behave like an admin might expect.

Admins want tomcat to start and stop when the system goes up or down. And they want this to happen in an absolutely reliable way. If they tell it to stop, they want it to stop. They don’t care whether the process is out of memory or stuck for another reason. And most likely, admins do not want the process to run with root privileges. Still it may be required to bind to privileged ports.

System Lifecycle Management Tooling Provided

The interactive Alfresco installer provides you with a shell-script alfresco.sh to start and stop the system. Even database lifecycle is managed by this script if you chose to install the database as well. On top of that, there even is a graphical manager app. There is nothing wrong which these tools – they are great for initial exploration, but they are not really suited for init or upstart and hence, systems in production.

Hooking Alfresco System Lifecycle to Init

I have been writing at least half a dozen init shell scripts to manage lifecycle of Java based daemons. This time I wanted something ready made and maintained by other people. As expected, there is a tomcat7 package for Ubuntu (and other Debians most likely) shipping a fairly decent /etc/init.d/tomcat7 script. It reads configuration from /etc/default/tomcat7, so that is the place to set some variables, such as TOMCAT7_USER, TOMCAT7_GROUP, JAVA_HOME, JAVA_OPTS, AUTHBIND, CATALINA_HOME, CATALINA_BASE and some more. Setting it up is self explanatory. The init-script expects $CATALINA_BASE/conf/policy.d for concatenation as $CATALINA_BASE/work/catalina.policy. I have not checked what the package ships, but assuming it is sane, you can copy it to the Alfresco tomcat installation, e.g.:

cp -r /etc/tomcat7/policy.d /opt/alfresco/tomcat/conf

Beware of tomcat/bin/setenv.sh shipped with Alfresco. It unconditionally sets JAVA_HOME. The init script will fail if the value differs from the one in /etc/default/tomcat7. Hence, it is safer to wrap it:

if [ -z "$JAVA_HOME" ] ; then
    JAVA_HOME=/opt/alfresco_42s/java
    JRE_HOME=/opt/alfresco_42s/java
    JAVA_OPTS="$JAVA_OPTS "
    export JAVA_HOME
    export JRE_HOME
    export JAVA_OPTS
fi

Finally, you may want to try it out

/etc/init.d/tomcat7 start

and create appropriate links for init

sudo update-rc.d tomcat defaults

Beware that alfresco.sh and tomcat7 don’t mix. They both work on their own. But using one to start, the other to stop won’t work. This is due to the different pid file they use.

References

Andreas Steffan
Pragmatic ? Scientist and DevOps Mind @ Contentreich. Believes in Open Source, the Open Web and Linux. Freelancing in DevOps-, Cloud-, Kubernetes, JVM- and Contentland and speaks Clojure, Kotlin, Groovy, Go, Python, JavaScript, Java, Alfresco and WordPress. Built infrastructure before it was cool. ❤️ Emacs.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert