How do I start Apache Tomcat at boot on Mac OS X?
I observed that there is no full guide for installing tomcat on OS X that will include setting it up to start at boot time.
Here is the quick guide:
- install macports
suport port upgrade
-
sudo port upgrade outdated
.
-
sudo port install tomcat6
, or if you want other version checkport list|grep tomcat
- config is now at:
/opt/local/share/java/tomcat6/conf
-
startup script:
/opt/local/share/java/tomcat6/bin/tomcatctl
cp /opt/local/share/java/tomcat6/conf/tomcat-users.xml.sample /opt/local/share/java/tomcat6/conf/tomcat-users.xml nano /opt/local/share/java/tomcat6/conf/tomcat-users.xml
... check article
But I'm missing the part on how to make it run as true service/daemon: at system startup and optionally to make it restart if it does crash.
This is for installing tomcat as a daemon on port 8080 but enable also port 80 by using a firewall redirection. It was tested on Mac OS 10.6 but should work also with 10.5.
Edit /opt/local/share/java/tomcat6/conf/server.xml
and add proxyport="80" URIEncoding="UTF-8"
inside <Connector .../>
.
For forwarding port 80 to 8080 run this line and add it do /bin/catalina.sh
:
sudo ipfw add 100 fwd 127.0.0.1,8080 tcp from any to any 80 in
Assign enough memory to the Java machine or you may be in trouble later.
Inside /opt/local/share/java/tomcat6/conf/local.env
export JAVA_JVM_VERSION=CurrentJDK
export JAVA_OPTS="-Xmx3000M -Xms3000M -Djava.awt.headless=true -Duser.timezone=UTC"
In my example I allocated ~3Gb or RAM but you can adapt this, anyway don't put less than 1GB if you are running hudson
inside tomcat.
Running as a service
Run nano /Library/LaunchDaemons/org.apache.tomcat.plist
and paste the code below:
<?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>Disabled</key>
<false/>
<key>Label</key>
<string>org.apache.tomcat</string>
<key>ProgramArguments</key>
<array>
<string>/opt/local/share/java/tomcat6/bin/catalina.sh</string>
<string>run</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
Check that launchd detected you new daemon, if not reboot :(
launchctl list|grep tomcat
Start tomcat manually.
launchctl start org.apache.tomcat
If the status is something else than -
, you have a problem and you should investigate it: launchctl log level debug
and check /var/log/system.log
.
You need to register tomcat as an item that needs to be executed on startup. On Mac OS, this is handled by launchd (http://developer.apple.com/macosx/launchd.html). I don't know if launchd supports auto restarting, but otherwise you should have a look at something like supervisord (http://supervisord.org/).
For Snow Leopard launch on startup I created a plist file in /Library/LaunchDaemons/ The plist file will look like this (below, amend to match your directories). You can start/stop the service for testing by issuing "launchctl load org.macports.tomcat6.plist" or "launchctl unload org.macports.tomcat6.plist". Once you have it working reboot to prove the autostart at boot.
sh-3.2# more org.macports.tomcat6.plist
<?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>org.macports.tomcat6</string>
<key>ProgramArguments</key>
<array>
<string>/opt/local/bin/daemondo</string>
<string>--label=tomcat6</string>
<string>--start-cmd</string>
<string>/opt/local/bin/tomcatctl</string>
<string>start</string>
<string>;</string>
<string>--pid=fileclean</string>
<string>--pidfile</string>
<string>/opt/local/share/java/tomcat6/logs/tomcat6.pid</string>
</array>
<key>Debug</key><false/>
<key>Disabled</key><false/>
<key>OnDemand</key><false/>
<key>RunAtLoad></key><true/>
</dict>
</plist>