制作一个/etc/init.d/tomcat的脚本来控制tomcat的启动停止
时间: 2023-08-11 19:05:09 浏览: 101
Tomcat启动停止脚本
好的,以下是一个简单的启动、停止和重启 Tomcat 的脚本,你可以将其保存为“/etc/init.d/tomcat”文件。
```
#!/bin/bash
# Tomcat startup script
# Define Tomcat home and binary locations
TOMCAT_HOME=/opt/tomcat
CATALINA_HOME=$TOMCAT_HOME/bin
# Define functions
# Function to start Tomcat
start() {
echo "Starting Tomcat..."
$CATALINA_HOME/startup.sh
}
# Function to stop Tomcat
stop() {
echo "Stopping Tomcat..."
$CATALINA_HOME/shutdown.sh
}
# Function to restart Tomcat
restart() {
echo "Restarting Tomcat..."
stop
sleep 5
start
}
# Parse command line arguments
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
;;
esac
exit 0
```
保存脚本后,运行以下命令使其可执行:
```
sudo chmod +x /etc/init.d/tomcat
```
然后,你可以使用以下命令来启动、停止或重启 Tomcat:
```
sudo service tomcat start
sudo service tomcat stop
sudo service tomcat restart
```
阅读全文