如何在启动时将Tomcat作为非root用户启动

时间:2013-05-14 17:27:38

标签: tomcat ubuntu

如何在启动时在不同用户下启动Tomcat?我尝试了以下命令,但它提示输入密码。

su -c "/etc/tomcat/bin/catalina.sh start" tomcat

我正在使用Tomcat 7.0.40和Ubuntu 12.04。

2 个答案:

答案 0 :(得分:2)

创建配置文件tomcat.conf并将其放在/etc/init

/etc/init包含Upstart

使用的配置文件

tomcat.conf将如下所示(注意:JAVA_HOMECATALINA_HOME替换为您自己的行):

description "Tomcat Server"

  start on runlevel [2345]
  stop on runlevel [!2345]
  respawn
  respawn limit 10 5

  # run as non privileged user 
  # add user with this command:
  ## adduser --system --ingroup www-data --home /opt/apache-tomcat apache-tomcat
  # Ubuntu 12.04: (use 'exec sudo -u apache-tomcat' when using 10.04)
  setuid apache-tomcat
  setgid www-data

  # adapt paths - Replace with your Paths:
  env JAVA_HOME=/usr/lib/jvm/jdk1.7.0_13/
  env CATALINA_HOME=/home/mohammed/apache-tomcat-7.0.27/

  # adapt java options to suit your needs:
  env JAVA_OPTS="-Djava.awt.headless=true -Xms512M -Xmx1024M -server -XX:+UseParallelGC"

  exec $CATALINA_HOME/bin/catalina.sh run

  # cleanup temp directory after stop
  post-stop script 
    rm -rf $CATALINA_HOME/temp/*
  end script

答案 1 :(得分:0)

使用JSVC,阅读Tomcat JSVC manual或只是安装包tomcat7