See line 3 of your script? It sources in the /etc/rc.common script, which sets up some common functions used by run control scripts.
At the very bottom of /etc/rc.common is a line which sources in /etc/hostconfig - this is the file which specifies the configuration for your host (your computer). It's basic format is something like:
Line 1 is important - it indicates that this file may not exist in the future, so this way of starting Tomcat may not work in some future version of OS/X.
Line 3 tells any script that wants to know whether the AFP Server should be started or not that it is not to be started.
Line 5 specifies that the AUTOMOUNT system should be started (I have mixed feelings about that one).
Basically you need to add a line to this file which specifies that you want Tomcat started. Viz:
Try that and see if it solves your problem.
I am not familiar with have a /Library/System directory (and subdirectories) - there is no such directory structure on my Mac running 10.6.3, nor on my Mac running 10.5.8. I would normally expect a script to be in either /System/Library/StartupItems (the old way of doing startup scripts) or in /System/Library/LaunchDaemons. So if just adding the TOMCAT variable to the hostconfig file does not help you get an automatic startup, let us know.
To follow up, the changes you recommended worked great in as far as I could finally run the script. However, that path I had the file in was bad. I was going to put it in the /System/Library/LaunchDaemons directory, as you recommended, but what would I need to do? Everything in there is a ".plist" file and they are all in XML format.
Thanks, - Dave
author and jackaroo
Here is the annoying thing ... if you're going to use LaunchDaemons (which is the way I recommend) then your existing script has little to no value.
You are correct - you will need a plist file to use a LaunchDaemon. Here's my "org.apache.tomcat.plist" file:
You will have to modify this to suit your requirements. Some things you will have to change include:
Line 6 (defined by line 5): I have a group named "tomcat" (of which I am a member). The "tomcat" user only belongs to this group. This does give more security, however it relies on you creating extra groups. You can change this to an existing group if you prefer.
Lines 15 & 16: The "startup.sh" script provided with Tomcat is designed to start Tomcat in the background. This is not good for the LaunchDaemon - once it can no longer confirm that Tomcat is running in the foreground, it will try to start a new instance. And a new instance. And a new instance. .... Fortunately there is an easy solution: in the same directory as your startup.sh script, you will find a catalina.sh script. This takes a parameter to tell it what to do (hence line 16: provide the "run" parameter). The only change you should need here is to change line 15 to use /Library/Tomcat/... instead of my /opt/apache-tomcat/...
Line 21 - as mentioned 2 points above, I have a "tomcat" user and a "tomcat" group. The tomcat user I created is not shown in the login screen, or in the fast user switching .... Again: this is for security purposes. But you can change this to any user you like if you do not wish to create a "tomcat" user.
With that you should be able to get it started when you boot your computer.