Create jetty server in init() so we can open privileged ports when running with jsvc.

This commit is contained in:
hns 2008-12-13 02:36:39 +00:00
parent 256335adde
commit c820cab550
2 changed files with 13 additions and 8 deletions

View file

@ -18,6 +18,7 @@ package helma.main;
import org.mortbay.http.HttpServer; import org.mortbay.http.HttpServer;
import org.mortbay.http.HttpContext; import org.mortbay.http.HttpContext;
import org.mortbay.http.SocketListener;
import org.mortbay.http.ajp.AJP13Listener; import org.mortbay.http.ajp.AJP13Listener;
import org.mortbay.util.InetAddrPort; import org.mortbay.util.InetAddrPort;
@ -34,8 +35,7 @@ public class JettyServer {
// the AJP13 Listener, used for connecting from external webserver to servlet via JK // the AJP13 Listener, used for connecting from external webserver to servlet via JK
protected AJP13Listener ajp13; protected AJP13Listener ajp13;
public static JettyServer init(Server server) public static JettyServer init(Server server) throws IOException {
throws MalformedURLException, IOException {
if (server.configFile != null && server.configFile.exists()) { if (server.configFile != null && server.configFile.exists()) {
return new JettyServer(server.configFile.toURI().toURL()); return new JettyServer(server.configFile.toURI().toURL());
} else if (server.websrvPort != null || server.ajp13Port != null) { } else if (server.websrvPort != null || server.ajp13Port != null) {
@ -52,9 +52,15 @@ public class JettyServer {
throws IOException { throws IOException {
http = new HttpServer(); http = new HttpServer();
// start embedded web server if port is specified // create embedded web server if port is specified
if (webPort != null) { if (webPort != null) {
http.addListener(new InetAddrPort(webPort.getInetAddress(), webPort.getPort())); // opening the listener here allows us to run on priviledged port 80 under jsvc
// even as non-root user, because init() is called with root privileges
// while start() will be called with the user we will actually run as
InetAddrPort addr = new InetAddrPort(webPort.getInetAddress(), webPort.getPort());
SocketListener listener = new SocketListener(addr);
listener.open();
http.addListener(listener);
} }
// activate the ajp13-listener // activate the ajp13-listener

View file

@ -118,7 +118,7 @@ public class Server implements Runnable {
* Static main entry point. * Static main entry point.
* @param args the command line arguments * @param args the command line arguments
*/ */
public static void main(String[] args) { public static void main(String[] args) throws IOException {
loadServer(args); loadServer(args);
// parse properties files etc // parse properties files etc
server.init(); server.init();
@ -411,7 +411,7 @@ public class Server implements Runnable {
/** /**
* initialize the server * initialize the server
*/ */
public void init() { public void init() throws IOException {
// set the log factory property // set the log factory property
String logFactory = sysProps.getProperty("loggerFactory", String logFactory = sysProps.getProperty("loggerFactory",
@ -490,6 +490,7 @@ public class Server implements Runnable {
if (sysProps.getProperty("extensions") != null) { if (sysProps.getProperty("extensions") != null) {
initExtensions(); initExtensions();
} }
jetty = JettyServer.init(this);
} }
@ -573,8 +574,6 @@ public class Server implements Runnable {
*/ */
public void run() { public void run() {
try { try {
jetty = JettyServer.init(this);
if (xmlrpcPort != null) { if (xmlrpcPort != null) {
String xmlparser = sysProps.getProperty("xmlparser"); String xmlparser = sysProps.getProperty("xmlparser");