1

I have a Ubuntu 10.04 machine that has tomcat6 on it. When I start tomcat6 with /etc/init.d/tomcat6 start I get

* Starting Tomcat servlet engine tomcat6
/bin/bash already running.

and the server fails to start. Unfortunately, there is nothing in /var/log/tomcat/catalina.out to help debug the issue. With some cleverly placed echo statements it seems to be the line from /etc/init.d/tomcat6:

start-stop-daemon --start -u "$TOMCAT6_USER" -g "$TOMCAT6_GROUP" \
                -c "$TOMCAT6_USER" -d "$CATALINA_TMPDIR" \
                -x /bin/bash -- -c "$AUTHBIND_COMMAND $TOMCAT_SH"

The only thing I've changed in this script is TOMCAT6_USER=root. In servers.xml, the only thing I've changed is <Connector port="80" protocol="HTTP/1.1" from port 8080. I have tried reinstalling the package by first removing everything sudo apt-get --purge remove tomacat6 and then sudo apt-get install tomcat6 but this has not solved the issue. I have also restarted the server multiple times in hopes of some magic. Everything was working until I restarted my server. Any ideas?

Andrew
  • 143
  • 1
  • 7
  • Hi, The issue seems to be setting TOMCAT_USER=root. Changing this back fixes the issue, but doing so doesn't let me listen on port 80. – Andrew Jul 02 '10 at 17:28
  • 1
    **Do NOT** run Tomcat as root. Never, ever. Tomcat wasn't designed for that purpose. Also, I recommend not allowing users to connect directly to Tomcat, in any port. Run httpd in front and use mod_proxy_ajp. – Juliano Jul 07 '10 at 14:26

4 Answers4

1

Sometimes you gotta do what you gotta do.

Here's a patch that makes running tomcat as root work:

--- init.d.old/tomcat6  2010-09-01 15:31:01.996208252 -0700
+++ init.d/tomcat6  2010-09-01 15:30:10.315146226 -0700
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/sh -x
 #
 # /etc/init.d/tomcat6 -- startup script for the Tomcat 6 servlet engine
 #
@@ -141,6 +141,12 @@
        cd \"$CATALINA_BASE\"; \
        \"$CATALINA_SH\" $@"

+   cat >/etc/init.d/tomcat_exec.sh <<-EOT
+   #!/bin/bash
+   $TOMCAT_SH
+   EOT
+   chmod +x /etc/init.d/tomcat_exec.sh 
+
    if [ "$AUTHBIND" = "yes" -a "$1" = "start" ]; then
        TOMCAT_SH="'$TOMCAT_SH'"
    fi
@@ -151,7 +157,7 @@
    chown $TOMCAT6_USER "$CATALINA_PID" "$CATALINA_BASE"/logs/catalina.out
    start-stop-daemon --start -u "$TOMCAT6_USER" -g "$TOMCAT6_GROUP" \
        -c "$TOMCAT6_USER" -d "$CATALINA_TMPDIR" \
-       -x /bin/bash -- -c "$AUTHBIND_COMMAND $TOMCAT_SH"
+       -x /etc/init.d/tomcat_exec.sh 
    status="$?"
    set +a -e
    return $status
Bruce Edge
  • 111
  • 2
1

There's an Ubuntu bug for this issue, with a proposed patch.

It's not necessarily anything to do with running as root - if your tomcat6 user has a /bin/bash process (say, you're using it to run some commands to support your Tomcat application), then you will hit it as well.

crb
  • 7,928
  • 37
  • 53
0

Looking at the man page for start-stop-daemon, it looks for processes which match the name, uid, and/or gid of the command it's being asked to start. From the error message, I'd guess it may be doing this based on the /bin/bash command - so it's finding that there's already a root process running the /bin/bash command, and refusing to start a "duplicate" one.

You could work around this by hacking the init script around. But running Tomcat as root is Bad, so better to look at other ways to send port 80 to Tomcat, even while Tomcat runs as a non-root user. The most common approach is to run Apache httpd in front, another (if you don't want to fiddle with connectors) is to use iptables to map port 80.

See the serverfault question for details on how to do these.

Kief
  • 301
  • 3
  • 3
0

This is (was) a known Ubuntu bug that has since been fixed: https://bugs.launchpad.net/ubuntu/+source/tomcat6/+bug/632554

The init script won't start tomcat6 daemon if the user has a bash shell running.

The fix as listed in the bug report is simply to add -p "$CATALINA_PID" to the start-stop-daemon command.

*** tomcat6~ 2010-10-11 13:21:52.000000000 -0500
--- tomcat6 2010-11-03 12:19:04.000000000 -0500
***************
*** 152,154 ****
   start-stop-daemon --start -b -u "$TOMCAT6_USER" -g "$TOMCAT6_GROUP" \
! -c "$TOMCAT6_USER" -d "$CATALINA_TMPDIR" \
    -x /bin/bash -- -c "$AUTHBIND_COMMAND $TOMCAT_SH"
--- 152,154 ----
   start-stop-daemon --start -b -u "$TOMCAT6_USER" -g "$TOMCAT6_GROUP" \
! -c "$TOMCAT6_USER" -d "$CATALINA_TMPDIR" -p "$CATALINA_PID" \
    -x /bin/bash -- -c "$AUTHBIND_COMMAND $TOMCAT_SH"
}}}
Gene Gotimer
  • 2,442
  • 20
  • 16