Starting Redwood Platform Automatically with Launchd
Launchd was first shipped with macOS version 10.4 and is also available on FreeBSD as well as other systems. Below are a pair of example files you can use with launchd. You adjust the paths in the files to your installation path, which should point to the directory containing j2ee. In that directory, you create a directory named bin and create a shell script as outlined below; adapt the paths and user in the PLIST file accordingly.
Launchd Shell Script Wrapper
Copy
#!/bin/bash
# PATH to installation directory
RW_INSTALL=/opt/redwood
SERVER=${RW_INSTALL}/j2ee/cluster/server1
CATALINA_PID=${SERVER}/logs/process.pid
#Source your environment
if [ -e ${SERVER}/bin/setvars.sh ]; then
. ${SERVER}/bin/setvars.sh
fi
function stopInstance() {
date
echo "Shutting down Redwood"
${SERVER}/bin/start.sh
}
function startInstance() {
date
echo "Starting Redwood"
${SERVER}/bin/stop.sh
}
function restartInstance() {
date
echo "Restarting Redwood"
${SERVER}/bin/restart.sh
}
startInstance
# trap signal to quit/terminate
trap stopInstance INT QUIT ABRT KILL ALRM TERM TSTP
# trap HUP
trap restartInstance HUP
echo "Waiting for `cat ${CATALINA_PID}`"
wait `cat ${CATALINA_PID}`
PLIST File Contents
Copy
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.redwood.scheduler</string>
<key>OnDemand</key>
<false/>
<key>RunAtLoad</key>
<true/>
<key>Program</key>
<string>/opt/redwood/bin/launchd_wrapper.sh</string>
<key>ServiceDescription</key>
<string>Redwood Platform</string>
<key>StandardErrorPath</key>
<string>/opt/redwood/j2ee/cluster/server1/logs/launchd.err</string>
<key>StandardOutPath</key>
<string>/opt/redwood/j2ee/cluster/server1/logs/launchd.out</string>
<key>UserName</key>
<string>nobody</string>
</dict>
</plist>
Procedure
- Create a directory named
<install_dir>/binand create a file namedlaunchd_wrapper.shcontaining the above shell script code. - Make the file executable by issuing the following command
chmod +x <install_dir>/bin/launchd_wrapper.sh. - Copy the contents for the PLIST file into
/Library/LaunchDaemons/com.redwood.scheduler.plist. - Adapt any paths and change the user (default in this example is
nobody). - Issue
sudo launchctl load /Library/LaunchDaemons/com.redwood.scheduler.plist. - Issue
sudo launchctl listand make sure your process has a PID.