jetty init file prints wrong reachable information

Bug #1646202 reported by Rarylson Freitas
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
jetty (Ubuntu)
New
Undecided
Unassigned

Bug Description

When starting/stopping Jetty via its init script (/etc/init.d/jetty), we can get strange/wrong/inconsistent information about the host and port in which Jetty is/was listen.

This occurs in Ubuntu 14.04, but probably occurs in other Ubuntu/Debian versions since the `/etc/init.d/jetty` script is basically the same.

I will show some examples in a fresh install of Jetty (with `NO_START=0`) in a machine which hostname is `ip-172-31-45-218`.

```
root@ip-172-31-45-218:~# service jetty start
 * Starting Jetty servlet engine. jetty
 * Jetty servlet engine started, reachable on http://ip-172-31-45-218:8080/. jetty [ OK ]
root@ip-172-31-45-218:~# service jetty status
 * Jetty servlet engine is running with pid 5477, and is reachable on http://:8080/
root@ip-172-31-45-218:~# service jetty stop
 * Stopping Jetty servlet engine (was reachable on http://ip-172-31-45-218:8080/). jetty
 * Jetty servlet engine stopped. jetty [ OK ]
```

Here, we have the first strange thing:

- Start/stop report reachable on http://ip-172-31-45-218:8080/, while status reports reachable on http://:8080/. The outputs are somehow inconsistent.

Running some curls:

```
root@ip-172-31-45-218:~# curl http://ip-172-31-45-218:8080
curl: (7) Failed to connect to ip-172-31-45-218 port 8080: Connection refused
root@ip-172-31-45-218:~# curl http://127.0.0.1:8080
root@ip-172-31-45-218:~# curl http://127.0.0.1:8080
<HTML>
  <HEAD>
    <TITLE>Welcome to Jetty 6 on Debian</TITLE>
[...]
```

Even if we put `127.0.1.1 ip-172-31-45-218` or `172.31.45.218 ip-172-31-45-218` in `/etc/hosts`, as expected in Ubuntu hosts` in `/etc/hosts`, as expected in Ubuntu hosts, the first curl won't work.

This is because Jetty listens on 127.0.0.1 / ::1 when no host is informed:

```
root@ip-172-31-45-218:~# netstat -anlp | grep 8080
tcp6 0 0 127.0.0.1:8080 :::* LISTEN 5613/jsvc.exec
```

The same thing will happen if we change Jetty to listen in a specific IP address different than the represented by the hostname.

Now, the second thing:

- Start/stop can print unreachable address (Jetty is NOT reachable in this address).

And the third:

- Status prints a strange address if `JETTY_HOST` is blank, and it should print 127.0.0.1

Now, if we change in `/etc/default/jetty` `JETTY_HOST` to 90.90.90.90, do not restart Jetty (only change the config file), and run status, the status command will return the wrong host:

```
root@ip-172-31-45-218:~# service jetty status
 * Jetty servlet engine is running with pid 5613, and is reachable on http://90.90.90.90:8080/
root@ip-172-31-45-218:~# netstat -anlp | grep 8080
tcp6 0 0 127.0.0.1:8080 :::* LISTEN 5613/jsvc.exec
```

The same thing would happen if we change the `JETTY_PORT` config.

So, the fourth point:

- Status can return wrong reachable information if the config file (host/port) was modified after Jetty had started

There are a lot of other inconsistencies.

In my opinion, it's easier to remove these informations in the init script (the admin can always check the config files and run netstat to get the correct info).

But a more complex fix should consider checking netstat on stop/status commands, and checking the border cases (empty host - Jetty defaults to 12.0.0.1 / empty port - Jetty defaults to what is set in its XML config files, or 8080 if nothing more is changed) .

Tags: patch
Revision history for this message
Rarylson Freitas (rarylson) wrote :

Hi,

I discovered another strange and related behavior.

When leaving JETTY_HOST empty, instead of listening on all IPs (0.0.0.0 - IPv4 and IPv6), the server is listening on localhost (IPv4 127.0.0.1).

I run some tests and I discovered that passing an empty jetty.host as param is different than not setting it.

For example:

```
$ cd /usr/share/jetty/
$ java -jar start.jar
[...]
[main] INFO org.mortbay.log - Started SelectChannelConnector@0.0.0.0:8080

[CTRL+C]
$ java -Djetty.host=0.0.0.0 -jar start.jar
[...]
[main] INFO org.mortbay.log - Started SelectChannelConnector@0.0.0.0:8080

[CTRL+C]
$ java -Djetty.host= -jar start.jar
[main] INFO org.mortbay.log - Started SelectChannelConnector@:8080
```

And if we check netstat in the last case:

```
netstat -nlp | grep jsvc
tcp6 0 0 127.0.0.1:8983 :::* LISTEN 24209/jsvc.exec
```

It is, if we pass `-Djetty.host=`, Jetty will listening on 127.0.0.1. This happens when JETTY_HOST is empty:

```
JAVA_OPTIONS="$JAVA_OPTIONS -Djava.io.tmpdir=$JETTY_TMP \
  -DSTART=$JETTY_START_CONFIG \
  -Djetty.home=$JETTY_HOME -Djetty.logs=$LOGDIR \
  -Djetty.host=$JETTY_HOST -Djetty.port=$JETTY_PORT"

```

A good solution for this is always set JETTY_HOST and do NOT recommend the user to set it blank (as is done today).

So, I'm proposing some changes to the /etc/default/jetty and /etc/init.d/jetty file.

What do you think, guys?

Revision history for this message
Rarylson Freitas (rarylson) wrote :

And...

Revision history for this message
Ubuntu Foundations Team Bug Bot (crichton) wrote :

The attachment "etc_initd_jetty.reachable.patch" seems to be a patch. If it isn't, please remove the "patch" flag from the attachment, remove the "patch" tag, and if you are a member of the ~ubuntu-reviewers, unsubscribe the team.

[This is an automated message performed by a Launchpad user owned by ~brian-murray, for any issues please contact him.]

tags: added: patch
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.