{"id":295,"date":"2005-11-29T10:06:20","date_gmt":"2005-11-29T16:06:20","guid":{"rendered":"http:\/\/www.mooreds.com\/wordpress\/?p=295"},"modified":"2005-11-29T10:06:20","modified_gmt":"2005-11-29T16:06:20","slug":"running-tomcat-on-port-80","status":"publish","type":"post","link":"https:\/\/www.mooreds.com\/wordpress\/archives\/295","title":{"rendered":"Running Tomcat on port 80"},"content":{"rendered":"<p>The typical java web application is fronted by a web server (usually Apache) for a number of reasons.  Apache handles static content well, and also is easier to configure to listen on privileged ports (under 1024).  I&#8217;ve written before about <a href='http:\/\/www.mooreds.com\/weblog\/archives\/000223.html'>different options for connecting Tomcat and Apache<\/a>, but there are times when all you need is a servlet engine, and installing Apache is overkill.  If you don&#8217;t want users to see a nonstandard port in their url (http:\/\/foo.com:8080\/webapp\/), then you have a couple of options.  <\/p>\n<p>You can run tomcat as root.  This is probably not a good idea, since anyone who can write a jsp can now execute arbitrary commands as root.  I don&#8217;t know how Tomcat&#8217;s security is, but in general, the fewer applications running with super user privileges, the better.  <\/p>\n<p>If you share my dislike of Tomcat running as root, here&#8217;s an excellent <a href='http:\/\/www.klawitter.de\/tomcat80.html'>rundown of the options for running Tomcat on port 80<\/a>.  I went the route of <a href='http:\/\/jakarta.apache.org\/commons\/daemon\/jsvc.html'>jsvc<\/a>.  This seemed to work just fine, though every time we shut down tomcat, we would get an entry in the error log file: <code>jsvc.exec error: Service exit with a return value of 143<\/code>.  <\/p>\n<p>That didn&#8217;t start to disturb me until I realized that the <code>destroy<\/code> method of our servlets weren&#8217;t being called.  This method cleaned up after the servlet and it was important that it get executed.  A bit of googling turned up <a href='http:\/\/junlu.com\/msg\/129283.html'>a discussion of this very problem<\/a>.  The version of jsvc that ships with Tomcat 5.0.27 doesn&#8217;t shut down Tomcat very nicely.<\/p>\n<p>I downloaded and compiled subversion, because that&#8217;s the version control system that the daemon jakarta project (of which jsvc is a part) used.  I then checked out the version of the source tagged <code>daemon-1_0_1<\/code>  (<code>svn co http:\/\/svn.apache.org\/repos\/asf\/jakarta\/commons\/proper\/daemon\/tags\/daemon-1_0_1\/<\/code>) and rebuilt jsvc.  This new version allows tomcat to call the destroy methods of servlets, and everything seems to be happy.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The typical java web application is fronted by a web server (usually Apache) for a number of reasons. Apache handles static content well, and also is easier to configure to [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-295","post","type-post","status-publish","format-standard","hentry","category-java"],"_links":{"self":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts\/295","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/comments?post=295"}],"version-history":[{"count":0,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts\/295\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/media?parent=295"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/categories?post=295"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/tags?post=295"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}