With the release of MacOS 10.4 (aka Tiger) Apple rolled out launchd which is a system startup program that replaces cron, xinetd, init, etc. It also replaces /Library/StartupItems which I have typically used in the last for launching Tomcat and Postgresql. To run Tomcat on my Mac Mini I decided to finally figure out launchd. Below is my launchd script file.
Save the following file as org.apache.tomcat.plist in your home directory
[sourcecode language=”xml”]
<?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>Debug</key>
<true/>
<key>GroupName</key>
<string>staff</string>
<key>Label</key>
<string>org.apache.tomcat</string>
<key>UserName</key>
<string>rcuprak</string>
<key>RunAtLoad</key>
<true/>
<key>Program</key>
<string>/usr/bin/java</string>
<key>ProgramArguments</key>
<array>
<string>-Djava.endorsed.dirs=/Applications/apache-tomcat-6.0.14/endorsed</string>
<string>-Dcatalina.base=/Applications/apache-tomcat-6.0.14</string>
<string>-Dcatalina.home=/Applications/apache-tomcat-6.0.14</string>
<string>-Djava.io.tmpdir=/Applications/apache-tomcat-6.0.14/tmp</string>
<string>-classpath</string>
<string>/Applications/apache-tomcat-6.0.14/bin/tomcat-juli.jar:/Applications/apache-tomcat-6.0.14/bin/commons-daemon.jar:/Applications/apache-tomcat-6.0.14/bin/commons-logging-api.jar:/Applications/apache-tomcat-6.0.14/bin/bootstrap.jar</string>
<string>org.apache.catalina.startup.Bootstrap</string>
</array>
<key>WorkingDirectory</key>
<string>/Applications/apache-tomcat-6.0.14</string>
</dict>
</plist>
[/sourcecode]
You made need to adjust the paths to reflect the version of Tomcat that you are using as well as the username under which to run tomcat.
Perform the following operations from the command line:
[sourcecode language=”xml”]
sudo bash
cd /Library/LaunchDaemons
cp /Users/<your username>/org.apache.tomcat.plist .
launchctl load org.apache.tomcat.plist
launchctl start org.apache.tomcat
[/sourcecode]
Tomcat should startup and will auto start next time the machine is restarted. Any errors will be recorded to syslog and visible if you run the Console application.
The paths to tomcat may need to be adjusted depending upon your version of tomcat.
Save this file to /Library/LaunchDaemons. You must first authenticate as root (sudo bash) before saving the file.
When the machine shuts down I believe launchd sends a kill signal at the process. There aren’t any hooks for invoking a shutdown logic from what I’ve seen thus far.