Linux setup tomcat, redis, Nginx, Apache, play boot self-start script

Linux setup tomcat, redis, Nginx, Apache, play boot self-start script

method:

I created a script file here.
Order:

vim /etc/init.d/startTomcat

File content (details are explained later in the article):

#!/bin/bash 
# 
# tomcat startup script for the Tomcat server 
# 
# chkconfig: 345 80 20 
# description: start the tomcat deamon 
# 
# Source function library 
. /etc/rc.d/init.d/functions
prog=tomcat 
JAVA_HOME=/usr/java/jdk1.8.0_181/
export JAVA_HOME
CATALANA_HOME8185=/usr/local/apache-tomcat-7/apache-tomcat-7-8185/
CATALANA_HOME8186=/usr/local/apache-tomcat-7/apache-tomcat-7-8186/
CATALANA_HOME8187=/usr/local/apache-tomcat-7/apache-tomcat-7-8187/
export CATALINA_HOME8185
export CATALINA_HOME8186
export CATALINA_HOME8187


#start Redis		
#/usr/local/redis/redis-4.0.6/src/redis-server /usr/local/redis/redis-4.0.6/redis.conf
sleep 120
#start nginx		
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
sleep 5
#start apache	
/usr/local/apache/bin/apachectl start


sleep 5


case "$1" in
start) 
  echo "Starting Tomcat..."
  $CATALANA_HOME8185/bin/startup.sh
  $CATALANA_HOME8186/bin/startup.sh
  $CATALANA_HOME8187/bin/startup.sh
  ;; 
stop) 
  echo "Stopping Tomcat..."
  $CATALANA_HOME8185/bin/startup.sh
  $CATALANA_HOME8186/bin/startup.sh
  $CATALANA_HOME8187/bin/startup.sh
  ;; 
restart) 
  echo "Stopping Tomcat..."
  $CATALANA_HOME8185/bin/startup.sh
  $CATALANA_HOME8186/bin/startup.sh
  $CATALANA_HOME8187/bin/startup.sh
  sleep 2 
  echo
  echo "Starting Tomcat..."
  $CATALANA_HOME8185/bin/startup.sh
  $CATALANA_HOME8186/bin/startup.sh
  $CATALANA_HOME8187/bin/startup.sh
  ;; 
*) 
  echo "Usage: $prog {start|stop|restart}"
  ;; 
esac 
sleep 5
#start play		
rm  -f   /usr/local/play-java-1.0-SNAPSHOT/RUNNING_PID
sleep 2
rm -f /usr/local/play-java-1.0-SNAPSHOT/bin/nohup.out
sleep 2
chmod a+x  /usr/local/play-java-1.0-SNAPSHOT/bin/play-java
sleep 2
nohup /usr/local/play-java-1.0-SNAPSHOT/bin/play-java -Dconfig.file=/usr/local/play-java-1.0-SNAPSHOT/conf/application.conf &    
exit 0

Here you also need to configure the created file and execute the command in the terminal to remember to execute sentence by sentence:

chmod +x /etc/init.d/startTomcat
chkconfig startTomcat on
service startTomcat start
# 这句代码执行是看上面写好的脚本文件是否有用

Note: in the above command startTomcatis the name of the file created above. You can modify it according to your own needs as long as it is consistent with the above file name.
If there are no problems with the above, you can restart the server to see if the settings are valid. My server is centos7.

Here is the content of the file:

  • JAVA_HOMEThis is the location of the jdk of your own server, which needs to be changed according to the location of your own server.
  • CATALANA_HOME8185This is the path of my tomcat, which needs to be modified according to your own situation.
  • CATALANA_HOME8186This is the path of my tomcat, which needs to be modified according to your own situation.
  • CATALANA_HOME8187This is the path of my tomcat, which needs to be modified according to your own situation. If you only have one tomcat, configure one, and delete all other associated ones.
  • The configuration of redis is useless to me here, but you can configure it in the same way.
  • sleepIs the meaning of sleep, the number behind the unit is seconds. There is a problem here before, that is to say, when tomcat starts, redis has not started, causing the project to start an error, here sleep for a while, after redis starts, the command to start tomcat will not report an error.
  • The next step is to start Nginx and Apache commands. It is best to sleep for a few seconds after executing a command between these commands and then execute the subsequent commands. If many commands are executed at the same time, an error may be reported.
  • $CATALANA_HOME8186/bin/startup.shThe commands here correspond to the commands for configuring the location of Tomcat before. If you only have one Tomcat, leave only one.
  • The last one is the command to start play, here is also to sleep for a few seconds after executing a command, and then execute another command.

Guess you like

Origin blog.csdn.net/javaXiaoAnRan/article/details/103239669