Jenkins安装完成后,实现开机自启动
- 创建脚本文件
- 在/etc/init.d目录下新建脚本文件,文件名为“tomcat"
#!/bin/sh
#chkconfig: 2345 10 90
#description: Starts and Stops the Tomcat daemon.
#by erlang 2021-11-24
#Make sure the java and the tomcat installation path has been added to the PATH
JAVA_HOME=/usr/local/jdk #JDK安装目录
CATALINA_HOME=/usr/local/tomcat #tomcat安装目录
export JAVA_HOME
export CATALINA_HOME
###############################################
start_tomcat=$CATALINA_HOME/bin/startup.sh #tomcat启动文件
stop_tomcat=$CATALINA_HOME/bin/shutdown.sh #tomcat关闭文件
###如果运行了多个tomcat可以使用例如 start_tomcat1, start_tomcat2来区分不同的tomcat实例。
start() {
echo -n "Starting tomcat: "
${start_tomcat}
echo "tomcat start ok."
}
stop() {
echo -n "Shutting down tomcat: "
${stop_tomcat}
echo "tomcat stop ok."
}
# See how we were called
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 10
start
;;
*)
echo "Usage: $0 {start|stop|restart}"
esac
exit 0
- 添加tomcat为系统服务
chmod +x /etc/init.d/tomcat //给tomcat脚本文件添加执行权限
chkconfig --add tomcat // 添加为系统服务
chkconfig --level 345 tomcat on //添加启动运行级别
到这里就结束了,可以在测试环境执行reboot命令重启后查看是否自动运行。
- 验证
ps -ef |grep tomcat
netstat -untlp |grep 8080
本文介绍了如何在Jenkins安装完成后,通过创建/etc/init.d/tomcat脚本实现Tomcat的开机自启动,包括设置环境变量、启动/停止脚本引用、添加服务到系统以及验证方法。
1224





