feat: 增加lib分离部署方式

master
王兵 3 weeks ago
parent 42359a7d2e
commit ee4675c4c2

@ -6,7 +6,7 @@
<groupId>xyz.wbsite</groupId> <groupId>xyz.wbsite</groupId>
<artifactId>deployee-maven-plugin</artifactId> <artifactId>deployee-maven-plugin</artifactId>
<version>3.0.1-SNAPSHOT</version> <version>3.0.2-SNAPSHOT</version>
<packaging>maven-plugin</packaging> <packaging>maven-plugin</packaging>
<description>deployee</description> <description>deployee</description>

@ -117,6 +117,14 @@ public class Deploy extends AbstractMojo {
sh = StrUtil.replace(sh, "{1}", targetFile); sh = StrUtil.replace(sh, "{1}", targetFile);
sh = StrUtil.replace(sh, "{2}", server.getDeployActive()); sh = StrUtil.replace(sh, "{2}", server.getDeployActive());
sh = StrUtil.replace(sh, "{3}", server.getDeployPort()); sh = StrUtil.replace(sh, "{3}", server.getDeployPort());
String appArgStr = "";
if (server.getAppArgs() != null && server.getAppArgs().length > 0) {
appArgStr = String.join(" ", server.getAppArgs());
}
sh = StrUtil.replace(sh, "{4}", appArgStr);
sh = StrUtil.replace(sh, "{5}", String.valueOf(server.isLibSeparated()));
if (StrUtil.isNotBlank(server.getDeployActive())) { if (StrUtil.isNotBlank(server.getDeployActive())) {
client.write(serverPath + "/service-" + server.getDeployActive() + ".sh", sh); client.write(serverPath + "/service-" + server.getDeployActive() + ".sh", sh);
client.exec("chmod +x {}", serverPath + "/service-" + server.getDeployActive() + ".sh"); client.exec("chmod +x {}", serverPath + "/service-" + server.getDeployActive() + ".sh");
@ -180,6 +188,17 @@ public class Deploy extends AbstractMojo {
}); });
printLog(StrUtil.format("upload package {}", "finish")); printLog(StrUtil.format("upload package {}", "finish"));
if (server.isLibSeparated()) {
File libDir = new File(targetPath, "lib");
if (libDir.exists() && libDir.isDirectory()) {
printLog("start upload lib directory");
client.putFiles(libDir.getAbsolutePath(), serverPath + "/lib");
printLog("upload lib directory finish");
} else {
printLog("[WARN] lib directory not found: {}, skip lib upload", libDir.getAbsolutePath());
}
}
printLog("stop service {}", server.getName()); printLog("stop service {}", server.getName());
client.exec("systemctl stop {}.service", server.getName()); client.exec("systemctl stop {}.service", server.getName());

@ -48,6 +48,18 @@ public class Server {
*/ */
private JreVersion jre; private JreVersion jre;
/**
* --xxx=yyyservice.shAPP_ARG
* @parameter
*/
private String[] appArgs;
/**
* libtarget/lib使-cp
* @parameter defaultValue="false"
*/
private boolean libSeparated;
public enum JreVersion { public enum JreVersion {
jre8, jre8,
jre17 jre17
@ -124,4 +136,20 @@ public class Server {
public void setJre(JreVersion jre) { public void setJre(JreVersion jre) {
this.jre = jre; this.jre = jre;
} }
public String[] getAppArgs() {
return appArgs;
}
public void setAppArgs(String[] appArgs) {
this.appArgs = appArgs;
}
public boolean isLibSeparated() {
return libSeparated;
}
public void setLibSeparated(boolean libSeparated) {
this.libSeparated = libSeparated;
}
} }

@ -10,7 +10,9 @@ ACTIVE={2}
#port #port
PORT={3} PORT={3}
#more arg #more arg
APP_ARG= APP_ARG={4}
#lib separated mode
LIB_SEP={5}
usage() { usage() {
echo "Usage: sh service-*.sh [start|stop|restart|status]" echo "Usage: sh service-*.sh [start|stop|restart|status]"
@ -30,9 +32,13 @@ start(){
is_exist is_exist
if [ $? -eq "0" ]; then if [ $? -eq "0" ]; then
echo "${APP_NAME} is already running. pid=${pid} ." echo "${APP_NAME} is already running. pid=${pid} ."
else
if [ "$LIB_SEP" = "true" ]; then
nohup ${JAVA_HOME}/bin/java -Dfile.encoding=UTF-8 -Dloader.path=lib -jar $APP_NAME --spring.profiles.active=$ACTIVE --server.port=${PORT} $APP_ARG > /dev/null 2>&1 &
else else
nohup ${JAVA_HOME}/bin/java -Dfile.encoding=UTF-8 -jar $APP_NAME --spring.profiles.active=$ACTIVE --server.port=${PORT} $APP_ARG > /dev/null 2>&1 & nohup ${JAVA_HOME}/bin/java -Dfile.encoding=UTF-8 -jar $APP_NAME --spring.profiles.active=$ACTIVE --server.port=${PORT} $APP_ARG > /dev/null 2>&1 &
fi fi
fi
} }
stop(){ stop(){

Loading…
Cancel
Save

Powered by TurnKey Linux.