一。环境:
操作系统: utuntu11.10
JAVA_HOME: /document/opt/jdk1.6
Tomcat安装目录: /documet/opt/tomcat6
二。编写服务启动脚本
在/etc/init.d/下创建文件tomcatd :
#! /bin/sh
# chkconfig: 35 30 70
# descripttion: VirtualBox Linux kernel module
#
### BEGIN INIT INFO
# Provides: tomcat
# Required-Start: $remote_fs $network
# Required-Stop: $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Descripttion: tomcat
### END INIT INFO
export JAVA_HOME=/document/opt/jdk1.6
export CATALINA_HOME=/document/opt/tomcat-6
export CATALINA_PID=/var/run/tomcatd.pid
PIDFILE=/var/run/tomcatd.pid
pidof_tomcat() {
# if there is actually an apache2 process whose pid is in PIDFILE,
# print it and return 0.
if [ -e "$PIDFILE" ]; then
if pidof java | tr ' ' '\n' | grep -w $(cat $PIDFILE); then
return 0
fi
fi
return 1
}
start() {
PID=$(pidof_tomcat) || true
if [ -n "$PID" ]; then
echo "tomcat is running (pid $PID)."
exit 0
else
sh $CATALINA_HOME/bin/startup.sh
fi
}
stop() {
PID=$(pidof_tomcat) || true
if [ -n "$PID" ]; then
sh $CATALINA_HOME/bin/shutdown.sh
PID=$(pidof_tomcat) || true
if [ -n "$PID" ]; then
echo "tomcat is still running (pid $PID)."
echo "kill process..."
kill -9 $PID
fi
else
echo "tomcat is NOT running."
fi
}
restart() {
stop
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
PID=$(pidof_tomcat) || true
if [ -n "$PID" ]; then
echo "tomcat is running (pid $PID)."
exit 0
else
echo "tomcat is NOT running."
if [ -e "$PIDFILE" ]; then
exit 1
else
exit 3
fi
fi
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
esac
三。添加服务:
[root@root init.d]# chmod uog+rx tomcatd
[root@root init.d]# sysv-rc-conf --level 2345 tomcatd on
四。注意:
1. 在tomcat文件的头两行的注释语句中,需要包含chkconfig和descriptttion两部分内容(确认不要拼写错误),否则在执行“chkconfig --add tomcatd”时,会出现“tomcatd 服务不支持 chkconfig”的错误提示。
2. 如果提示sysv-rc-conf 命令不存在就执行 apt-get install sysv-rc-conf 安装。
3. 如果tomcat用户不存在通过如下命令则建立:#useradd -U -s /sbin/nologin tomcat
查看服务添加结果:
[root@root init.d]# sysv-rc-conf --list tomcatd
tomcatd 2:on 3:on 4:on 5:on
[root@root init.d]# /etc/init.d/tomcatd start
删除服务:
[root@root init.d]# sysv-rc-conf tomcatd off
分享到:
相关推荐
ubuntu开机自启动nginx服务
Ubuntu安装Redis并设置为开机自启动服务.rar
Ubuntu环境下 Tomcat服务 自启动脚本编写及实现方式
主要介绍了Ubuntu下配置Tomcat服务器以及设置自动启动的方法,适用于Java的web程序开发,需要的朋友可以参考下
由于PostgreSQL是编译安装的,需要设置开机启动。这篇文章主要介绍了Ubuntu 16.04设置PostgreSQL开机启动的方法,需要的朋友可以参考下
ubuntu系统配置jar项目开机自启 ubuntu系统配置jar项目开机自启 ubuntu系统配置jar项目开机自启
在UBUNTU环境有多种应用,但很多UBUNTU环境应用介绍的书却未涉及UBUNTU添加程序开机自动启动的方法,这篇总结不错,有需要的下载。
ubuntu ubuntu_设置开机自启动命令_脚本
ubuntu linux下安装tomcat
ubuntu tmux 自动执行shell脚本,可创建多个session,多个window。多个panes, 平铺所有的panes,对指定session下指定window的指定panes发送指定的多条命令,后台创建! 稍微修改可做成自己的自启动脚本,
Ubuntu下运行免安装Redis及Redis开机自动启动配置 免安装, 直接解压压缩包即可使用Redis 配置Redis开机自动启动 https://blog.csdn.net/Coxhuang/article/details/107691240
在Ubuntu 环境有多种应用,但很多Ubuntu 环境应用介绍的书却未涉及Ubuntu 添加程序开机自动启动的方法,这篇总结不错,有需要的下载。
ubuntu 16.04安装tomcat 8.0图文详细教程
要在Linux系统上安装Google Chrome浏览器并设置开机自动启动并打开默认指定页面,请按照以下步骤进行操作: 下载Google Chrome浏览器的安装包,你可以从Google的官方网站或者第三方下载站点上获取。 解压缩安装包并...
主要介绍了ubuntu中编写shell脚本开机自动启动,本文给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下
2. 对于开机启动程序,需要关注4个地方(排序有分先后) 3. 新建启动脚本 4. 直接添加到rc.local 5. 退出登录时自动运行程序 6. 定期自动运行程序 7. 定时自动运行程序一次 8. 依赖于图形界面的自动运行程序
ubuntu中部署tomcat
教你如何设置开机自动启动,你会发现非常容易
该文档介绍了ununtu如何将tomcat注册成系统服务。