Win a copy of Mastering Corda: Blockchain for Java Developers this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
  • salvin francis
  • Frits Walraven
  • Piet Souris

Start Tomcat 7 as tomcat user (not root user)

Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Id like to use tomcat (user) to startup tomcat server. Not root. Can you help figure out where i am going wrong?
$su -p -s /bin/sh tomcat $CATALINA_HOME/bin/

--Detailed question --
I have a question about setting up Tomcat 7 on ubuntu server. In short, I am unable to start tomcat server using my user (user: tomcat; group: tomcat). I am able to get it started and showing the default welcome page using root. I posted similar on unbuntu forum. hope that is ok.

I would like assistance understanding how to get tomcat server running with the correct user.

Here is some basic information.

My capabilities:
I am new to Linux; taken one intro course. I can navigate around ok...I will research commands or switches if I dont understand one you've recommended. I may ask why a specific switch is used in a situation.

My objective:
I want to run JSP pages on tomcat 7; and learn to secure the web server.

My goal is to convert over to JSP from visual basic. I've been learning Java, Java Servlets over the past year and half. I've always used tomcat, glassfish embedded in Eclipse and Netbeans. I would like to completely setup tomcat server so i can replicate on a virtual server provided by a web hosting company.

My computer is running:
Ubuntu Server, with Linux 2.6.38-13-server x86_64
ubuntu 11.04 server

Probably too much information:
- I have installed from CD, no server options selected (ftp, dns, samba, lamp, etc).
- Updated repository: apt-get update
- Upgraded files: apt-get upgrade
- Upgraded Distribution: apt-get dist-upgrade
- Added sysstat, enabled system activity reporting (SAR)
- Added nmap
- Downloaded and installed openjdk-6-jre and openjdk-6-jdk

Tomcat Download:
Retrieved tomcat 7 from

Extracted files and set in permanent location:
$tar xzvf apache-tomcat-7.0.23.tar.gz
$sudo mv apache-tomcat-7.0.23 /var/lib/tomcat

Set environment variables (I chose in /etc/environment):
$sudo vi /etc/environment

Created tomcat group & user and changed ownership of Tomcat directory
$groupadd tomcat
$useradd -g tomcat -s /sbin/nologin -m -d /home/tomcat tomcat
$passwd tomcat
$chown -R tomcat.tomcat /var/lib/tomcat

Changed Permissions of tomcat log directory
$sudo chmod -R 777 /var/lib/tomcat/logs

Changed permissions of server.xml
sudo chmod A=wx /var/lib/tomcat/conf/server.xml

Start up tomcat server. This is where i am stuck...
Following the instructions here, I am trying to start tomcat server using the tomcat user (not root). I am unsuccessful and I am not sure why.

First, I looked at the /Logs/catalina.out log file; which is blank (prior to running the start up script). I attempt to start tomcat server by running the command:

$su -p -s /bin/sh tomcat $CATALINA_HOME/bin/

When running this command, there is no output to terminal. I also checked the catalina.out log file and it is still blank. So i do not understand why no response. I thought i would see an error message at terminal output if command or any parameters are wrong.

Now if i run the command below using sudo, it starts up and i see the start up log entries recorded in catalina.out

$sudo sh
Using CATALINA_BASE: /var/lib/tomcat
Using CATALINA_HOME: /var/lib/tomcat
Using CATALINA_TMPDIR: /var/lib/tomcat/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/lib/tomcat/bin/bootstrap.jar:/var/lib/tomcat/bin/tomcat-juli.jar
$ _

And tomcat welcome page is working.

My question again: Do you have advice on how to use tomcat user to start Tomcat 7 server?

Thank you for your assistance! Gregg
Saloon Keeper
Posts: 22997
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Normally I set up an init script to start/stop Tomcat. Among other things, this means that I can ensure that if the server is restarted, Tomcat will also restart. You can use the "su" command and specify the Tomcat userID on the start and stop command handlers in the script.

One thing that can bite. If you start Tomcat under the root user ID, then attempt to run it later under its own ID, the root version of Tomcat will have written log, temp, and work files out under the root user's filesystem permissions, which can keep them from being updated by the Tomcat running under its own user ID. So it's good to make sure that these files have all been cleaned out before running the Tomcat server under its own ID.
Gregg Setzer
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I will research how to implement a startup script. Thanks for your help. Gregg
Tomorrow is the first day of the new metric calendar. Comfort me tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic