Launching Tomcat with Launchd

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" ""&gt;
<plist version="1.0">

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

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.

%d bloggers like this: