File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Mac OS and the fly likes Trouble figuring out why Tomcat isn't launching on startup Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » Mac OS
Bookmark "Trouble figuring out why Tomcat isn Watch "Trouble figuring out why Tomcat isn New topic
Author

Trouble figuring out why Tomcat isn't launching on startup

Dave Alvarado
Ranch Hand

Joined: Jul 02, 2008
Posts: 436
Hi,

I'm using Tomcat 6.0.26 on Mac 10.6.3. I have this script (with 755 perms and root ownership) at /Library/System/Tomcat/Tomcat



However, I notice that when I reboot my system, Tomcat isn't running (by doing ps -ef | grep java -- no processes listed). When I tried to run the script by hand, I get this error ...



Any ideas how I define "TOMCAT" and thus, what I can do to get Tomcat to start at system startup? - Dave

Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Sounds like more of a Unix/Mac startup script issue.

I'll move this to our Mac forum where you will probably get better help.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11432
    
  85

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.


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Dave Alvarado
Ranch Hand

Joined: Jul 02, 2008
Posts: 436
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
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11432
    
  85

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.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Trouble figuring out why Tomcat isn't launching on startup