18

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 check port 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.

2
  • Why use MacPorts when they have official binaries available? I hate the reliance some Mac users have for MacPorts, especially when most MacPorts packages are out of date and thus you open yourself up to security holes.
    – Cromulent
    Sep 22, 2010 at 12:38
  • Simon, this is required because macports is also a package manager so you'll get over a lot of problems using this way. Also you will be able to upgrade tomcat very easy.
    – sorin
    Sep 23, 2010 at 14:18

3 Answers 3

14

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.

2
  • 1
    Could be me as I'm new to Mac (OS X 10.8.2) but I had to do: sudo launchctl load -w /Library/LaunchDaemons/org.apache.tomcat.plist to get it to start
    – Steve
    Nov 26, 2012 at 21:59
  • I haven't had it working until I made the file's owner root. So, when editing the file type sudo nano /Library/LaunchDaemons/org.apache.tomcat.plist Jan 25, 2020 at 19:28
1

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/).

1
  • Yes, launchd has a keepalive option, both as yes/no and with four optional conditions.
    – flumignan
    May 26, 2011 at 20:47
1

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>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .