可指定tomcat启动用户的脚本
来源:互联网 发布:wp config sample.php 编辑:程序博客网 时间:2024/06/05 18:07
可指定tomcat启动用户的脚本
网上很多的同仁说tomcat无法指定启动的用户,造成很大的不方便,其实自己也曾遇到过这样的问题,之前草草的写了一个脚本,不过是漏洞百出,因为需要重命名tomcat的startup.sh为tstartup.sh,虽然公司内部在使用,但是还是不好意思拿出来和大家分享。不过这里还是会和大家拿出来,以示思考的历程,实在是太简单,让同仁们见笑了!
原来的老脚本如下:
#!/bin/bash
#wrint by :liuyunfeng
#used to start tomcat use as not root
#date : 2010-09-24
runuser=www
tomdir=$(dirname "$0")
if [ "$USER" != "${runuser}" ];then
echo "Tomcat runuser is $runuser, but you are $USER."
echo "Action: We will start tomcat use ${runuser} !!"
su - $runuser <<EOF
${tomdir}/tstartup.sh
EOF
else
${tomdir}/tstartup.sh
fi
用法:重命名tomcat自带的startup.sh为tstartup.sh,然后添加该脚本为startup.sh即可。
现在的脚本是根据tomcat自身所带脚本本身上稍加改动实现的,需要在用的时候指定下用户即可。脚本中默认用户为root,可根据自己的需要修改成相应的用户。脚本如下:
#!/bin/sh
# -----------------------------------------------------------------------------
# Start Script for the CATALINA Server
#
# $Id: startup.sh 385888 2006-03-14 21:04:40Z keith $
# Modified by : Yunfeng-Liu
# Description : Specifies the user starts tomcat
# Modified date : 2010-10-29
# -----------------------------------------------------------------------------
# Better OS/400 detection: see Bugzilla 31132
user=root # tomcat run user
os400=false
darwin=false
case "`uname`" in
CYGWIN*) cygwin=true;;
OS400*) os400=true;;
Darwin*) darwin=true;;
esac
# resolve links - $0 may be a softlink
PRG="$0"
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> /(.*/)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`/"$link"
fi
done
PRGDIR=`dirname "$PRG"`
EXECUTABLE=catalina.sh
# Check that target executable exists
if $os400; then
# -x will Only work on the os400 if the files are:
# 1. owned by the user
# 2. owned by the PRIMARY group of the user
# this will not work if the user belongs in secondary groups
eval
else
if [ ! -x "$PRGDIR"/"$EXECUTABLE" ]; then
echo "Cannot find $PRGDIR/$EXECUTABLE"
echo "This file is needed to run this program"
exit 1
fi
fi
###### Modified Content ###############
if [ "$USER" != "$user" ];then
exec su "$user" "$PRGDIR"/"$EXECUTABLE" start "$@"
else
exec "$PRGDIR"/"$EXECUTABLE" start "$@"
fi
用法:将原来的startup.sh删除或者是根据内容比对修改都可以,随你意!user修改成自己想要使用的用户即可,不过不要忘记给脚本赋相应的权限。
- 可指定tomcat启动用户的脚本
- tomcat的启动脚本
- 创建SysV系统脚本(可指定运行级别自动启动)
- 简易shell脚本提示Tomcat没有在正确的用户下启动。
- 启动Tomcat时加载指定的servlet
- Tomcat启动指定的Web工程
- 指定Tomcat启动时用的JDK
- tomcat启动指定项目
- tomcat启动指定项目
- tomcat启动指定项目
- Tomcat的启动脚本浅析(二)
- Tomcat的启动脚本浅析(三)
- Tomcat的启动脚本浅析(一)
- Tomcat的启动脚本浅析(二)
- Tomcat的启动脚本浅析(三)
- Tomcat的启动脚本浅析(一)
- CentOS Tomcat 的启动服务脚本
- tomcat 死亡自己启动的脚本。
- 重看C语言,做的一道题及动态二维数组的实现
- 使用outfile、infile导出导入mysql数据库表中部分数据
- java调用wsdl2java(axis2)存根用户认证
- windows下ffmpeg-php的配置
- taskkill
- 可指定tomcat启动用户的脚本
- 关于static, register, volatile,auto 变量的比较
- Content Provider的经典详细讲解
- PHP extract() 函数
- 对称加密DES和TripleDES
- 没什么
- Cassandra 和 HBase 中使用的 BigTable 模型
- C/C++多种方法获取文件大小
- C#运算符优先级