You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Thomas T. Veldhouse" <ve...@veldy.net> on 2000/08/03 18:08:18 UTC

Running tomcat under a different user - solution!

The problem with running tomcat under a different (unprivileged) user is not
FreeBSD specific at all.  The problem I was having is that when I ran tomcat
under the user, tomcat, it failed right away.  Upon looking more closely, I
found that the JDK path was not included.  So, I created the tomcat user as
follows.

# entry in /etc/passwd
tomcat:*:56:56:Tomcat Pseudo User:/usr/local/tomcat:/usr/local/bin/bash

There also is a tomcat group (gid=56).

# entry in /etc/group
tomcat:*:56:

I then created a .bash_profile in /usr/local/tomcat with the following:

# begin /usr/local/tomcat/.bash_profile
JAVA_COMPILER=tya
JAVA_HOME=/usr/local/jdk1.2.2
PATH=$PATH:$JAVA_HOME/bin
export PATH JAVA_HOME JAVA_COMPILER


Then, I created /usr/local/etc/rc.d/apache.sh as follows:

#!/bin/sh
#
# Modified Apache startup script to start Tomcat and Apache.
# Modified the modified version from Kees Jan Koster
#

if ! PREFIX=$(expr $0 : "\(/.*\)/etc/rc\.d/$(basename $0)\$"); then
    echo "$0: Cannot determine the PREFIX" >&2
    exit 1
fi

case "$1" in
start)
        [ -x ${PREFIX}/tomcat/bin/tomcat.sh ] && su -l tomcat -c
"${PREFIX}/tomcat/bin/tomcat.sh start > /dev/null" && echo -n ' tomcat'
        [ -x ${PREFIX}/sbin/apachectl ] && ${PREFIX}/sbin/apachectl start &>
/dev/null && echo -n ' apache'
        ;;
stop)
        su -l tomcat -c "${PREFIX}/tomcat/bin/tomcat.sh stop &> /dev/null"
&& echo -n ' tomcat'
        [ -r /var/run/httpd.pid ] && ${PREFIX}/sbin/apachectl stop >
/dev/null && echo -n ' apache'
        ;;
*)
        echo "Usage: `basename $0` {start|stop}" >&2
        ;;
esac

exit 0

# end apache.sh


I hope you find this useful!

Tom Veldhouse
veldy@veldy.net