如何在启动时在不同用户下启动Tomcat?我尝试了以下命令,但它提示输入密码。
su -c "/etc/tomcat/bin/catalina.sh start" tomcat
我正在使用Tomcat 7.0.40和Ubuntu 12.04。
答案 0 :(得分:2)
创建配置文件tomcat.conf
并将其放在/etc/init
/etc/init
包含Upstart
tomcat.conf
将如下所示(注意:将JAVA_HOME
和CATALINA_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。