Nearly all Unix flavors have the notion of so-called initscripts, which are executed at startup (or when you switch the runlevel) and which start all required services or adapt settings. Usually all daemon and server processes are started via such initscripts. CQ5 doesn’t provide such a script out-of-the-box, but a rather complex shell script called “serverctl”, which performs many steps you would expect from a initscript:
- assembling parameters
- setting environment variables
- start/stop/status of the server process (start and stop are also available a separate scripts for ease of use)
This would easily qualify this script as a initscript, but it lacks one important task: Changing the uid for the to-be-started process, it doesn’t run as root user. While from a purely functional perspective this isn’t important, every sysadmin will tell you, that you shouldn’t run processes as root, when they don’t require such permissions to perform their tasks. And the security guys won’t even let you golive with such a setting. So if you write an init script, you should add this functionality there.
And one last plea: Do not start the java process directly in the initscript and assemble the commandline yourself, but call the start&stop scripts. Especially if you are not that familiar with the serverctl script. So, a simple initscript could look like this:
#!/bin/sh CQ5_ROOT=/opt/cq5 CQ5_USER=cq5 ######## SERVER=${CQ5_ROOT}/crx-quickstart/server START=${SERVER}/start STOP=${SERVER}/stop STATUS="${SERVER}/serverctl status" case "$1" in start) su - ${CQ5_USER} ${START} stop) su - ${CQ5_USER} ${STOP} status) su - ${CQ5_USER} ${STATUS} *) echo "Unknown argument $1" esac
why would you not just forward all arguments to the serverctl script? Looks to me, the serverctl script is already an initscript but has a small problem that it has to be invoked from the directory it lives in unless you change the path where to find cq in the script. Something like the following would be suficcient:
CQ_INSTALL_DIR=/opt/cq5
CQ_USER=cq5
cd $CQ_INSTALL_DIR
su – ${CQ_USER}./crx-quickstart/server/serverctl $*
Thanks reusr1 for your comment.
Yes, that’s the way I would do this; creating a small wrapper to prepare the environment, change to the correct path and so on.