可指定tomcat启动用户的脚本
2010-10-29 16:16
471 查看
可指定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的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修改成自己想要使用的用户即可,不过不要忘记给脚本赋相应的权限。
相关文章推荐
- Linux下tomcat作为守护进程运行(开机启动、以指定的用户运行、解决非root身份不能绑定1024以下端口的问题)的配置方法
- Centos 7关于rc.local脚本命令开机不执行及指定用户启动的解决方法
- 简易shell脚本提示Tomcat没有在正确的用户下启动。
- shell 脚本,将war包从指定位置解压到tomcat/WebApps下并启动项目
- tomcat以指定用户启动
- Linux以指定用户启动tomcat6.0
- Tomcat 自启动环境参数的设置及 Linux 脚本的启动顺序
- 启动Tomcat提示:指定的服务未安装
- linux下用脚本监测tomcat停止并且自动启动
- Tomcat启动脚本
- 在关机时执行用户指定的程序或脚本
- 一个简单的dos脚本, svn 获取代码 - Tomcat 备份 - Maven 编译 - 停止/启动Tomcat - Tomcat站点 发布
- tomcat日志,用户以及启动时的一些问题
- Linux系统使用ROOT用户启动tomcat报错的问题
- CentOS 单个Tomcat 的启动服务脚本
- URL检查 跳板机 创建用户 Nginx启动 随机密码的脚本
- tomcat启动脚本
- Windows下定时备份Oracle数据库指定用户数据脚本
- shell脚本启动,关闭tomcat
- 使用普通用户启动tomcat