Linux下Tomcat,Jenkins 设置成服务

Linux下Tomcat设置成服务


1. 在/etc/init.d目录下新建文件,命名为tomcat
2. 对tomcat文件进行编辑,执行
# cd /etc/init.d/
# vi tomcat
将下面代码粘上去
注意:下面代码java_home和catalina_home是指jdk和tomcat安装的根路径
################################
#!/bin/bash
# description: Tomcat7 Start Stop Restart
# processname: tomcat7
# chkconfig: 234 20 80
# service tomcat start
# service tomcat stop
# service tomcat restart
# service tomcat status
JAVA_HOME=/usr/java/jdk1.8.0_151
export JAVA_HOME
PATH=$JAVA_HOME/bin:$PATH
export PATH
CATALINA_HOME=/usr/local/tomcat/apache-tomcat-8.5.24
case $1 in
start)
echo -n "Starting Tomcat service..."
sh $CATALINA_HOME/bin/startup.sh
echo "tomcat is succeessfully started up"
;;
stop)
echo -n "Stoping Tomcat service..."
sh $CATALINA_HOME/bin/shutdown.sh
echo "tomcat is succeessfully stopped."
;;
restart)
echo -n "Restarting Tomcat service..."
sh $CATALINA_HOME/bin/shutdown.sh
sh $CATALINA_HOME/bin/startup.sh
echo "tomcat is succeessfully restarted."
;;
status)
numproc=`ps -ef | grep catalina | grep -v "grep catalina" | wc -l`
if [ $numproc -gt 0 ]; then
echo "Tomcat is running..."
else
echo "Tomcat is stopped..."
fi
;;
esac
exit 0
################################
3. 按ESC退出,并#:wq
4. 设置tomcat的文件属性,把tomcat 修改为可运行的文件,命令参考如下
#chmod a+x tomcat
5. 设置服务运行级别
#chkconfig --add tomcat
6. 服务就添加成功了
然后用 chkconfig --list 查看,在服务列表里就会出现自定义的服务了
# chkconfig --list
7. 测试
service tomcat start
service tomcat stop
service tomcat restart
service tomcat status

Linux下Jenkins 设置成服务

#! /bin/sh
# chkconfig: 2345 10 90
# description: jenkins ....
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
#prefix=/usr/local/jenkins
JENKINS_ROOT=/usr/local/jenkins
JENKINSFILENAME=jenkins.war
#ֹͣStop LiuLinJie's jenkins
stop(){
echo "Stoping $JENKINSFILENAME "
ps -ef|grep $JENKINSFILENAME | grep jre/bin |awk '{print $2}'|while read pid
do
kill -9 $pid
echo " $pid kill"
echo " LiuLinJie's Jenkins is stopped ! "
done
}
#Start LiuLinJie's jenkins
start(){
echo "Staring LiuLinJie's Jenkins ..."
echo " The port of LiuLinJie's jenkins is '8888' "
/usr/java/jdk1.8.0_151/jre/bin/java -jar $JENKINS_ROOT/jenkins.war --httpPort=8888
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
jenkinsproc=`ps -ef|grep $JENKINSFILENAME | grep jre/bin | wc -l`
if [ $jenkinsproc -le 0 ];then
echo "LiuLinJie's Jenkins is stopped ..."
else
echo "LiuLinJie's Jenkins is running..."
fi
;;
*)
#  printf 'Usage: %s {start|stop|restart|status}\n'
#  exit 1
echo "$0 | Usage: {start | stop | restart | status}"
exit 4
;;
esac

你可能感兴趣的:(Linux下Tomcat,Jenkins 设置成服务)