<?xml version="1.0"?>
<rss version="2.0">
<channel>
  <title>waelchatila.com - jetty tag</title>
  <link>http://waelchatila.com:80/tags/jetty/</link>
  <description>Notes on Software, Engineering and Science</description>
  <language>en</language>
  <copyright>Wael Chatila</copyright>
  <lastBuildDate>Thu, 11 Mar 2010 03:23:48 GMT</lastBuildDate>
  <generator>Pebble (http://pebble.sourceforge.net)</generator>
  <docs>http://backend.userland.com/rss</docs>
  
  
  <item>
    <title>Running Jetty as Non Root</title>
    <link>http://waelchatila.com:80/2009/01/20/1232522160000.html</link>
    
      
        <description>
          I&#039;m kicking the tires of Jetty and am in the process of setting it up on a production machine and found that the latest Jetty realeas (6.1.14) has a really easy way to start jetty out running as root and later switch to a uid of your choice which enables you to open up server sockets on the privileged ports 80 &amp; 443. See the README file under {jetty.root}/extras/setuid. The process is just a one-liner...well, there are some more perks as you&#039;ll see at the end.
&lt;p&gt;
The README seems little bit out of date as my
&lt;div class=&#034;codeSample&#034;&gt;mvn install&lt;/div&gt;
did all of the compiling and copying steps. However, when I try to launch jetty with the new jetty-setuid.xml config file I get the following error.

&lt;div class=&#034;codeSample&#034;&gt;
2009-01-20 23:10:33.887::WARN:  Config error at &amp;lt;Set name=&#034;uid&#034;&amp;gt;jetty&amp;lt;/Set&amp;gt;
2009-01-20 23:10:33.888::WARN:  EXCEPTION
java.lang.reflect.InvocationTargetException
   at java.lang.reflect.Constructor.newInstance(libgcj.so.81)
   at org.mortbay.xml.XmlConfiguration.set(XmlConfiguration.java:405)
   at org.mortbay.xml.XmlConfiguration.configure(XmlConfiguration.java:248)
   at org.mortbay.xml.XmlConfiguration.configure(XmlConfiguration.java:214)
   at org.mortbay.xml.XmlConfiguration.main(XmlConfiguration.java:974)
   at java.lang.reflect.Method.invoke(libgcj.so.81)
   at org.mortbay.start.Main.invokeMain(Main.java:194)
   at org.mortbay.start.Main.start(Main.java:523)
   at org.mortbay.start.Main.main(Main.java:119)
Caused by: java.lang.NumberFormatException: invalid character at position 1 in jetty
   at java.lang.Integer.parseInt(libgcj.so.81)
   at java.lang.Integer.&amp;lt;init&amp;gt;(libgcj.so.81)
   at java.lang.reflect.Constructor.newInstance(libgcj.so.81)
   ...8 more
&lt;/div&gt;
My jetty-setuid.xml file looks like:
&lt;div class=&#034;codeSample&#034;&gt;
&amp;lt;Configure id=&#034;Server&#034; class=&#034;org.mortbay.setuid.SetUIDServer&#034;&amp;gt;
  &amp;lt;Set name=&#034;startServerAsPrivileged&#034;&amp;gt;false&amp;lt;/Set&amp;gt;
  &amp;lt;Set name=&#034;umask&#034;&amp;gt;2&amp;lt;/Set&amp;gt;
  &amp;lt;Set name=&#034;uid&#034;&amp;gt;jetty&amp;lt;/Set&amp;gt;
  &amp;lt;Set name=&#034;gid&#034;&amp;gt;jetty&amp;lt;/Set&amp;gt;
&amp;lt;/Configure&amp;gt;
&lt;/div&gt;
For some reason its expecting an integer instead of &#034;jetty&#034;...well well
&lt;div class=&#034;codeSample&#034;&gt;
&amp;gt; su jetty
&amp;gt; id
uid=1002(jetty) gid=1003(jetty) groups=1003(jetty)
&lt;/div&gt;
My jetty-setuid.xml now looks like:
&lt;div class=&#034;codeSample&#034;&gt;
&amp;lt;Configure id=&#034;Server&#034; class=&#034;org.mortbay.setuid.SetUIDServer&#034;&amp;gt;
  &amp;lt;Set name=&#034;startServerAsPrivileged&#034;&amp;gt;false&amp;lt;/Set&amp;gt;
  &amp;lt;Set name=&#034;umask&#034;&amp;gt;2&amp;lt;/Set&amp;gt;
  &amp;lt;Set name=&#034;uid&#034;&amp;gt;1002&amp;lt;/Set&amp;gt;
  &amp;lt;Set name=&#034;gid&#034;&amp;gt;1003&amp;lt;/Set&amp;gt;
&amp;lt;/Configure&amp;gt;
&lt;/div&gt;
...works like a charm.
        </description>
      
      
    
    
    
    <category>Unix/Linux</category>
    
    <category>Java</category>
    
    <category>Web</category>
    
    <comments>http://waelchatila.com:80/2009/01/20/1232522160000.html#comments</comments>
    <guid isPermaLink="true">http://waelchatila.com:80/2009/01/20/1232522160000.html</guid>
    <pubDate>Wed, 21 Jan 2009 07:16:00 GMT</pubDate>
  </item>
  
  </channel>
</rss>

