Skip to content

Commit 606d693

Browse files
committed
[fix] fix the bug of container deployment failure
1 parent 24d098d commit 606d693

File tree

6 files changed

+11
-20
lines changed

6 files changed

+11
-20
lines changed

others/script/build_docker.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ if [ "$startup" = "y" ] || [ "$startup" = "Y" ]; then
6565
-p 7700:7700 -p 10086:10086 -p 5001:5005 -p 10001:10000 \
6666
-e JVMOPTIONS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=10000 -Dcom.sun.management.jmxremote.rmi.port=10000 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false" \
6767
-e PARAMS="--spring.profiles.active=pre" \
68+
-e TZ="Asia/Shanghai" \
6869
-v ~/docker/powerjob-server:/root/powerjob-server -v ~/.m2:/root/.m2 \
6970
tjqq/powerjob-server:$version
7071
sleep 1

others/script/debug.sh

Lines changed: 0 additions & 12 deletions
This file was deleted.

others/script/jenkins_auto_build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ docker run -d \
2626
--name powerjob-server \
2727
-p 7700:7700 -p 10086:10086 -p 5001:5005 -p 10001:10000 \
2828
-e JVMOPTIONS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=10000 -Dcom.sun.management.jmxremote.rmi.port=10000 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false" \
29-
-e PARAMS="--spring.profiles.active=product --spring.datasource.core.jdbc-url=jdbc:mysql://139.224.83.134:3306/powerjob-product?useUnicode=true&characterEncoding=UTF-8 --spring.data.mongodb.uri=mongodb://139.224.83.134:27017/powerjob-product" \
29+
-e PARAMS="--spring.profiles.active=product --spring.datasource.core.jdbc-url=jdbc:mysql://remotehost:3306/powerjob-product?useUnicode=true&characterEncoding=UTF-8 --spring.data.mongodb.uri=mongodb://remotehost:27017/powerjob-product" \
3030
-v ~/docker/powerjob-server:/root/powerjob-server -v ~/.m2:/root/.m2 \
3131
tjqq/powerjob-server:latest
3232
sleep 60

powerjob-server/docker/Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ ENV M2_HOME=/opt/powerjob-maven
1313

1414
# 设置时区
1515
ENV TZ=Asia/Shanghai
16-
RUN ln -sf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
1716

1817
# 设置其他环境变量
1918
ENV APP_NAME=powerjob-server

powerjob-server/src/main/resources/application-pre.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ logging.config=classpath:logback-product.xml
33

44
####### 数据库配置 #######
55
spring.datasource.core.driver-class-name=com.mysql.cj.jdbc.Driver
6-
spring.datasource.core.jdbc-url=jdbc:mysql://remotehost:3391/powerjob-pre?useUnicode=true&characterEncoding=UTF-8
6+
spring.datasource.core.jdbc-url=jdbc:mysql://remotehost:3306/powerjob-pre?useUnicode=true&characterEncoding=UTF-8
77
spring.datasource.core.username=root
88
spring.datasource.core.password=No1Bug2Please3!
99
spring.datasource.core.hikari.maximum-pool-size=20

powerjob-worker/src/main/java/com/github/kfcfans/powerjob/worker/container/OmsContainerFactory.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.github.kfcfans.powerjob.common.request.ServerDeployContainerRequest;
88
import com.github.kfcfans.powerjob.common.request.WorkerNeedDeployContainerRequest;
99
import com.github.kfcfans.powerjob.common.response.AskResponse;
10+
import com.github.kfcfans.powerjob.common.utils.CommonUtils;
1011
import com.github.kfcfans.powerjob.worker.OhMyWorker;
1112
import com.github.kfcfans.powerjob.worker.common.utils.AkkaUtils;
1213
import com.github.kfcfans.powerjob.worker.common.utils.OmsWorkerFileUtils;
@@ -67,7 +68,7 @@ public static OmsContainer getContainer(Long containerId) {
6768
deployContainer(deployRequest);
6869
}
6970
}catch (Exception e) {
70-
log.error("[OmsContainer-{}] deployed container failed, exception is {}", containerId, e.toString());
71+
log.error("[OmsContainer-{}] get container failed, exception is {}", containerId, e.toString());
7172
}
7273

7374
return CARGO.get(containerId);
@@ -92,11 +93,11 @@ public static synchronized void deployContainer(ServerDeployContainerRequest req
9293
return;
9394
}
9495

95-
try {
96+
String filePath = OmsWorkerFileUtils.getContainerDir() + containerId + "/" + version + ".jar";
97+
// 下载Container到本地
98+
File jarFile = new File(filePath);
9699

97-
// 下载Container到本地
98-
String filePath = OmsWorkerFileUtils.getContainerDir() + containerId + "/" + version + ".jar";
99-
File jarFile = new File(filePath);
100+
try {
100101
if (!jarFile.exists()) {
101102
FileUtils.forceMkdirParent(jarFile);
102103
FileUtils.copyURLToFile(new URL(request.getDownloadURL()), jarFile, 5000, 300000);
@@ -118,6 +119,8 @@ public static synchronized void deployContainer(ServerDeployContainerRequest req
118119

119120
}catch (Exception e) {
120121
log.error("[OmsContainer-{}] deployContainer(name={},version={}) failed.", containerId, containerName, version, e);
122+
// 如果部署失败,则删除该 jar(本次失败可能是下载jar出错导致,不删除会导致这个版本永久无法重新部署)
123+
CommonUtils.executeIgnoreException(() -> FileUtils.forceDelete(jarFile));
121124
}
122125
}
123126

0 commit comments

Comments
 (0)