在Linux系统下配置service启动和关闭
- 通过命令cd /etc/init.d文件夹下
- 再通过命令 vim tomcat 进入vim编辑界面
- 用过 i键 现在把下面代码贴入编辑界面
shell脚本如下
#!/bin/bash# This is the init script for starting up the# Jakarta Tomcat server## chkconfig: 345 91 10# description: Starts and stops the Tomcat daemon.## Source function library.. /etc/rc.d/init.d/functions# Get config.. /etc/sysconfig/network# Check that networking is up.[ "${NETWORKING}" = "no" ] && exit 0export JAVA_HOME=/usr/local/javaweb/jdk1.8.0_192 #自己的jdk安装目录tomcat_home=/usr/local/tomcat/tomcat #自己的tomcat安装目录startup=$tomcat_home/bin/startup.shshutdown=$tomcat_home/bin/shutdown.shstart(){echo -n "Starting Tomcat service:"cd $tomcat_home$startupecho "tomcat is succeessfully started up"}stop(){echo -n "Shutting down tomcat: "cd $tomcat_home$shutdownecho "tomcat is succeessfully shut down."}status(){numproc=`ps -ef | grep catalina | grep -v "grep catalina" | wc -l`if [ $numproc -gt 0 ]; thenecho "Tomcat is running..."elseecho "Tomcat is stopped..."fi}restart(){stopstart}# See how we were called.case "$1" instart)start;;stop)stop;;status)status;;restart)restart;;*)echo $"Usage: $0 {start|stop|status|restart}"exit 1esac
(文件不能执行,请执行该命令)给文件添加权限,
使得脚本文件可以执行,命令为: chmod 755 /etc/rc.d/init.d/tomcat
- 将文件加入到服务队列中 ```shell chkconfig —add tomcat
5. 查看tomcat,文件是否加入服务列表成功```shellchkconfig --list
- 设置服务开机自启动 ```shell chkconfig tomcat on
```
