场景描述:
springboot项目,有多个yml文件,每个yml文件配置了不同的服务端口
要求:
将springboot打成jar包之后,可以通过脚本命令启动多个服务端口
启动脚本编写
#!/bin/sh DB2PIDFILE=db2.pid ORAPIDFILE=ora.pid PAASPIDFILE=paas.pid MYSQLPIDFILE=mysql.pid if [ -f "$DB2PIDFILE" ] && kill -0 $(cat "$DB2PIDFILE"); then echo "xxl-job-admin-db2 is already running!" exit 1 fi if [ -f "$ORAPIDFILE" ] && kill -0 $(cat "$ORAPIDFILE"); then echo "xxl-job-admin-ora is already running!" exit 1 fi if [ -f "$PAASPIDFILE" ] && kill -0 $(cat "$PAASPIDFILE"); then echo "xxl-job-admin-paas is already running!" exit 1 fi if [ -f "$MYSQLPIDFILE" ] && kill -0 $(cat "$MYSQLPIDFILE"); then echo "xxl-job-admin-mysql is already running!" exit 1 fi rm -f *.log nohup java -jar hijob-jdbc-2.3.0.jar --spring.profiles.active=db2 > ./db2.log 2>&1 & echo $! > $DB2PIDFILE sleep 5 nohup java -jar hijob-jdbc-2.3.0.jar --spring.profiles.active=oracle > ./oracle.log 2>&1 & echo $! > $ORAPIDFILE sleep 5 nohup java -jar hijob-jdbc-2.3.0.jar --spring.profiles.active=paas > ./paas.log 2>&1 & echo $! > $PAASPIDFILE sleep 5 nohup java -jar hijob-jdbc-2.3.0.jar --spring.profiles.active=mysql > ./mysql.log 2>&1 & echo $! > $MYSQLPIDFILE echo "start succeed!"
启动之后的效果如下:我们看到有五个进程,表示每个yml文件的服务端口都起好了
[root@dbaa-kafka hijob-jdbc]# ll total 52340 -rw-r--r--. 1 root root 162991 Apr 10 15:16 db2.log -rw-r--r--. 1 root root 5 Apr 10 14:36 db2.pid -rw-r--r--. 1 root root 53017534 Apr 7 10:27 hijob-jdbc-2.3.0.jar -rw-r--r--. 1 root root 7794 Apr 10 14:37 mysql.log -rw-r--r--. 1 root root 5 Apr 10 14:36 mysql.pid -rw-r--r--. 1 root root 148349 Apr 10 15:17 oracle.log -rw-r--r--. 1 root root 5 Apr 10 14:36 ora.pid -rw-r--r--. 1 root root 85162 Apr 10 15:17 paas.log -rw-r--r--. 1 root root 5 Apr 10 14:36 paas.pid -rw-r--r--. 1 root root 1093 Apr 7 10:27 start.sh -rw-r--r--. 1 root root 1119 Apr 7 10:27 stop.sh [root@dbaa-kafka hijob-jdbc]# ps -ef|grep hijob-jdbc-2.3.0.jar root 2027 1 1 14:36 pts/3 00:00:38 java -jar hijob-jdbc-2.3.0.jar --spring.profiles.active=db2 root 2124 1 1 14:36 pts/3 00:00:41 java -jar hijob-jdbc-2.3.0.jar --spring.profiles.active=oracle root 2227 1 1 14:36 pts/3 00:00:31 java -jar hijob-jdbc-2.3.0.jar --spring.profiles.active=paas root 2339 1 1 14:36 pts/3 00:00:29 java -jar hijob-jdbc-2.3.0.jar --spring.profiles.active=mysql root 4257 1196 0 15:17 pts/3 00:00:00 grep --color=auto hijob-jdbc-2.3.0.jar [root@dbaa-kafka hijob-jdbc]#
当然也少不了停止脚本,脚本内容如下:
#!/bin/sh DB2PIDFILE=db2.pid echo "db2 pid file is $DB2PIDFILE" ORAPIDFILE=ora.pid echo "ora pid file is $ORAPIDFILE" PAASPIDFILE=paas.pid echo "paas pid file is $PAASPIDFILE" MYSQLPIDFILE=mysql.pid echo "mysql pid file is $MYSQLPIDFILE" if [ ! -f "$DB2PIDFILE" ] || ! kill -0 "$(cat "$DB2PIDFILE")"; then echo "process not running..." else echo "stopping process..." DB2PID="$(cat "$DB2PIDFILE")" kill -9 $DB2PID rm -f "$DB2PIDFILE" fi if [ ! -f "$ORAPIDFILE" ] || ! kill -0 "$(cat "$ORAPIDFILE")"; then echo "process not running..." else echo "stopping process..." ORAPID="$(cat "$ORAPIDFILE")" kill -9 $ORAPID rm -f "$ORAPIDFILE" fi if [ ! -f "$PAASPIDFILE" ] || ! kill -0 "$(cat "$PAASPIDFILE")"; then echo "process not running..." else echo "stopping process..." PAASPID="$(cat "$PAASPIDFILE")" kill -9 $PAASPID rm -f "$PAASPIDFILE" fi if [ ! -f "$MYSQLPIDFILE" ] || ! kill -0 "$(cat "$MYSQLPIDFILE")"; then echo "process not running..." else echo "stopping process..." MYSQLPID="$(cat "$MYSQLPIDFILE")" kill -9 $MYSQLPID rm -f "$MYSQLPIDFILE" fi echo "stop succeed!"