提交 fc8d51d8 authored 作者: wangqiang's avatar wangqiang

wins

上级 8a854f28
package com.priusis.client.service.core;
import lombok.Data;
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
import org.eclipse.paho.client.mqttv3.internal.security.SSLSocketFactoryFactory;
import org.springframework.util.Base64Utils;
import org.springframework.util.StringUtils;
import java.io.FileInputStream;
import java.nio.charset.StandardCharsets;
import java.security.*;
import java.util.Properties;
/**
* Created by priusis on 18.01.17.
......@@ -17,6 +8,7 @@ import java.util.Properties;
@Data
public class MqttClientSecurityConfiguration {
private boolean apiByMac;
private String accessToken;
private String keystore;
private String keystorePassword;
......@@ -24,74 +16,4 @@ public class MqttClientSecurityConfiguration {
private String truststore;
private String truststorePassword;
public boolean isTokenBased() {
return !StringUtils.isEmpty(accessToken);
}
public boolean isSsl() {
return !StringUtils.isEmpty(truststore);
}
public void setupSecurityOptions(MqttConnectOptions options) {
if (this.isTokenBased()) {
options.setUserName(this.getAccessToken());
if (!StringUtils.isEmpty(this.getTruststore())) {
Properties sslProperties = new Properties();
sslProperties.put(SSLSocketFactoryFactory.TRUSTSTORE, this.getTruststore());
sslProperties.put(SSLSocketFactoryFactory.TRUSTSTOREPWD, this.getTruststorePassword());
sslProperties.put(SSLSocketFactoryFactory.TRUSTSTORETYPE, "JKS");
sslProperties.put(SSLSocketFactoryFactory.CLIENTAUTH, false);
options.setSSLProperties(sslProperties);
}
} else {
//TODO: check and document this
Properties sslProperties = new Properties();
sslProperties.put(SSLSocketFactoryFactory.KEYSTORE, this.getKeystore());
sslProperties.put(SSLSocketFactoryFactory.KEYSTOREPWD, this.getKeystorePassword());
sslProperties.put(SSLSocketFactoryFactory.KEYSTORETYPE, "JKS");
sslProperties.put(SSLSocketFactoryFactory.TRUSTSTORE, this.getTruststore());
sslProperties.put(SSLSocketFactoryFactory.TRUSTSTOREPWD, this.getTruststorePassword());
sslProperties.put(SSLSocketFactoryFactory.TRUSTSTORETYPE, "JKS");
sslProperties.put(SSLSocketFactoryFactory.CLIENTAUTH, true);
options.setSSLProperties(sslProperties);
}
}
public String getClientId() {
if (this.isTokenBased()) {
return sha256(this.getAccessToken().getBytes(StandardCharsets.UTF_8));
} else {
try {
FileInputStream is = new FileInputStream(this.getKeystore());
KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
keystore.load(is, this.getKeystorePassword().toCharArray());
Key key = keystore.getKey(this.getKeystoreKeyAlias(), this.getKeystorePassword().toCharArray());
if (key instanceof PrivateKey) {
// Get certificate of public key
java.security.cert.Certificate cert = keystore.getCertificate(this.getKeystoreKeyAlias());
// Get public key
PublicKey publicKey = cert.getPublicKey();
return sha256(publicKey.getEncoded());
} else {
throw new RuntimeException("No public key!");
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
private String sha256(byte[] data) {
try {
MessageDigest md = MessageDigest.getInstance("SHA-256");
md.update(data);
return Base64Utils.encodeToString(md.digest());
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
}
}
package com.priusis.client.service.core;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.io.Resources;
......@@ -15,16 +18,19 @@ import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.handler.ssl.SslContext;
import io.netty.handler.ssl.SslContextBuilder;
import io.netty.util.concurrent.Promise;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import oshi.hardware.NetworkIF;
import javax.annotation.PostConstruct;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.TrustManagerFactory;
import java.io.*;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.security.KeyStore;
......@@ -47,6 +53,12 @@ import static com.priusis.client.util.JsonTools.*;
@Slf4j
public class MqttServiceImpl implements MqttService, MqttHandler, MqttClientCallback {
@Value(value = "${apq.iot-gateway}")
private String gateway;
@Value(value = "${apq.url.device_info}")
private String deviceInfo;
//private static final String GATEWAY_RPC_TOPIC = "gateway/rpc";
//private static final String GATEWAY_ATTRIBUTES_TOPIC = "gateway/attrs";
//private static final String GATEWAY_TELEMETRY_TOPIC = "gateway/telemetry";
......@@ -342,7 +354,6 @@ public class MqttServiceImpl implements MqttService, MqttHandler, MqttClientCall
.method(payload.get("method").asText()).params(payload.get("params").asText()).build();
// 存储rpc下发的数据
try {
......@@ -516,7 +527,12 @@ public class MqttServiceImpl implements MqttService, MqttHandler, MqttClientCall
private MqttClient initMqttClient() {
try {
MqttClientConfig mqttClientConfig = getMqttClientConfig();
mqttClientConfig.setUsername(connection.getSecurity().getAccessToken());
if (connection.getSecurity().isApiByMac()) {
mqttClientConfig.setUsername(getClientSecurityByMac().getAccessToken());
} else {
mqttClientConfig.setUsername(connection.getSecurity().getAccessToken());
}
tbClient = MqttClient.create(mqttClientConfig, this);
tbClient.setCallback(this);
tbClient.setEventLoop(nioEventLoopGroup);
......@@ -570,27 +586,32 @@ public class MqttServiceImpl implements MqttService, MqttHandler, MqttClientCall
private MqttClientConfig getMqttClientConfig() {
MqttClientConfig mqttClientConfig;
if (!StringUtils.isEmpty(connection.getSecurity().getAccessToken())) {
if (StringUtils.isEmpty(connection.getSecurity().getTruststore())) {
mqttClientConfig = new MqttClientConfig();
mqttClientConfig.setUsername(connection.getSecurity().getAccessToken());
if (connection.getSecurity().isApiByMac()) {
mqttClientConfig = new MqttClientConfig();
mqttClientConfig.setUsername(getClientSecurityByMac().getAccessToken());
} else {
if (!StringUtils.isEmpty(connection.getSecurity().getAccessToken())) {
if (StringUtils.isEmpty(connection.getSecurity().getTruststore())) {
mqttClientConfig = new MqttClientConfig();
mqttClientConfig.setUsername(connection.getSecurity().getAccessToken());
} else {
try {
SslContext sslCtx = initOneWaySslContext(connection.getSecurity());
mqttClientConfig = new MqttClientConfig(sslCtx);
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new RuntimeException(e);
}
}
} else {
try {
SslContext sslCtx = initOneWaySslContext(connection.getSecurity());
SslContext sslCtx = initTwoWaySslContext(connection.getSecurity());
mqttClientConfig = new MqttClientConfig(sslCtx);
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new RuntimeException(e);
}
}
} else {
try {
SslContext sslCtx = initTwoWaySslContext(connection.getSecurity());
mqttClientConfig = new MqttClientConfig(sslCtx);
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new RuntimeException(e);
}
}
return mqttClientConfig;
}
......@@ -635,4 +656,27 @@ public class MqttServiceImpl implements MqttService, MqttHandler, MqttClientCall
public void setPersistentFileService(PersistentFileService persistentFileService) {
this.persistentFileService = persistentFileService;
}
private MqttClientSecurityConfiguration getClientSecurityByMac() {
try {
NetworkIF networkIF = new NetworkIF();
networkIF.setNetworkInterface(NetworkInterface.getByInetAddress(InetAddress.getLocalHost()));
String mac = networkIF.getMacaddr();
if (StrUtil.isBlank(mac)) {
log.warn("未获取到MAC地址");
return null;
}
deviceInfo = StrUtil.format(deviceInfo, mac);
String remoteDeviceVoJson = HttpUtil.get(gateway + deviceInfo);
RemoteDeviceVo remoteDeviceVo = JSONUtil.toBean(remoteDeviceVoJson, RemoteDeviceVo.class);
MqttClientSecurityConfiguration mqttClientSecurityConfiguration = new MqttClientSecurityConfiguration();
mqttClientSecurityConfiguration.setAccessToken(remoteDeviceVo.getSecretKey());
return mqttClientSecurityConfiguration;
} catch (Exception e) {
log.error("获取Mac地址异常", e);
}
return null;
}
}
package com.priusis.client.service.core;
import lombok.Data;
import java.io.Serializable;
/**
* <p>
* 设备表
* </p>
*/
@Data
public class RemoteDeviceVo implements Serializable {
/**
* 设备通讯id
*/
private String did;
/**
* 设备编码
*/
private String code;
/**
* 业务code
*/
private String bizCode;
/**
* 秘钥
*/
private String secretKey;
/**
* 设备名称
*/
private String name;
}
......@@ -24,12 +24,13 @@ core:
path: D://storage
bufferSize: 6
connection:
host: "${GATEWAY_HOST:127.0.0.1}"
host: "${PC_HOST:127.0.0.1}"
port: 1884
retryInterval: 3000
maxInFlight: 1000
security:
accessToken: "${GATEWAY_ACCESS_TOKEN:1hTbcWoaQvPzl2PpbkTG}"
apiByMac: "${PC_API_BY_MAC:true}"
# accessToken: "${PC_ACCESS_TOKEN:1hTbcWoaQvPzl2PpbkTG}"
remoteConfiguration: false
extensions:
-
......@@ -42,5 +43,6 @@ apq:
iot-gateway: 192.168.124.19:7002
url:
install: /ops/install/getList?pageNum={}&pageSize={}
device_info: /facility/getByMacAddress?macAddress={}
upgrade: /ops/upgrade/getList?pageNum={}&pageSize={}
add-program: /ops/program/addFacProgram
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
<id>windows</id>
<formats>
<format>zip</format>
</formats>
<!-- Workaround to create logs directory -->
<fileSets>
<fileSet>
<directory>${pkg.win.dist}</directory>
<outputDirectory>logs</outputDirectory>
<excludes>
<exclude>*/**</exclude>
</excludes>
</fileSet>
<fileSet>
<directory>${pkg.win.dist}/conf</directory>
<outputDirectory>conf</outputDirectory>
<lineEnding>windows</lineEnding>
<excludes>
<exclude>*.der</exclude>
<exclude>*.cer</exclude>
<exclude>*.pfx</exclude>
</excludes>
</fileSet>
<fileSet>
<directory>${pkg.win.dist}/conf</directory>
<outputDirectory>conf</outputDirectory>
<includes>
<include>*.der</include>
<include>*.cer</include>
<include>*.pfx</include>
</includes>
</fileSet>
</fileSets>
<files>
<file>
<source>${project.build.directory}/${project.build.finalName}-boot.${project.packaging}</source>
<outputDirectory>lib</outputDirectory>
<destName>${pkg.name}.jar</destName>
</file>
<file>
<source>${pkg.win.dist}/service.exe</source>
<outputDirectory/>
<destName>${pkg.name}.exe</destName>
</file>
<file>
<source>${pkg.win.dist}/service.xml</source>
<outputDirectory/>
<destName>${pkg.name}.xml</destName>
<lineEnding>windows</lineEnding>
</file>
<file>
<source>${pkg.win.dist}/install.bat</source>
<outputDirectory/>
<lineEnding>windows</lineEnding>
</file>
<file>
<source>${pkg.win.dist}/uninstall.bat</source>
<outputDirectory/>
<lineEnding>windows</lineEnding>
</file>
</files>
</assembly>
export JAVA_OPTS="$JAVA_OPTS -Dplatform=@pkg.platform@"
export LOG_FILENAME=${pkg.name}.out
export LOADER_PATH=${pkg.installFolder}/conf
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration>
<configuration>
<appender name="fileLogAppender"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${pkg.logFolder}/${pkg.name}.log</file>
<rollingPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${pkg.logFolder}/${pkg.name}.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<maxFileSize>100MB</maxFileSize>
<maxHistory>30</maxHistory>
<totalSizeCap>3GB</totalSizeCap>
</rollingPolicy>
<encoder>
<pattern>%d{ISO8601} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<logger name="org.priusis" level="INFO" />
<logger name="org.eclipse.milo" level="INFO" />
<logger name="org.eclipse.paho" level="INFO" />
<root level="INFO">
<appender-ref ref="fileLogAppender"/>
</root>
</configuration>
pkg.logFolder=${pkg.unixLogFolder}
\ No newline at end of file
pkg.logFolder=${BASE}\\logs
pkg.winWrapperLogFolder=%BASE%\\logs
[Unit]
Description=${pkg.name}
After=syslog.target
[Service]
User=${pkg.user}
ExecStart=${pkg.installFolder}/bin/${pkg.name}.jar
SuccessExitStatus=143
[Install]
WantedBy=multi-user.target
#!/bin/sh
chown -R ${pkg.user}: ${pkg.logFolder}
chown -R ${pkg.user}: ${pkg.installFolder}
update-rc.d ${pkg.name} defaults
#!/bin/sh
update-rc.d -f ${pkg.name} remove
#!/bin/sh
if ! getent group ${pkg.user} >/dev/null; then
addgroup --system ${pkg.user}
fi
if ! getent passwd ${pkg.user} >/dev/null; then
adduser --quiet \
--system \
--ingroup ${pkg.user} \
--quiet \
--disabled-login \
--disabled-password \
--home ${pkg.installFolder} \
--no-create-home \
-gecos "Priusisiot application" \
${pkg.user}
fi
#!/bin/sh
if [ -e /var/run/${pkg.name}/${pkg.name}.pid ]; then
service ${pkg.name} stop
fi
#!/bin/sh
chown -R ${pkg.user}: ${pkg.logFolder}
chown -R ${pkg.user}: ${pkg.installFolder}
if [ $1 -eq 1 ] ; then
# Initial installation
systemctl --no-reload enable ${pkg.name}.service >/dev/null 2>&1 || :
fi
#!/bin/sh
if [ $1 -ge 1 ] ; then
# Package upgrade, not uninstall
systemctl try-restart ${pkg.name}.service >/dev/null 2>&1 || :
fi
#!/bin/sh
getent group ${pkg.user} >/dev/null || groupadd -r ${pkg.user}
getent passwd ${pkg.user} >/dev/null || \
useradd -d ${pkg.installFolder} -g ${pkg.user} -M -r ${pkg.user} -s /sbin/nologin \
-c "Priusisiot application"
#!/bin/sh
if [ $1 -eq 0 ] ; then
# Package removal, not upgrade
systemctl --no-reload disable --now ${pkg.name}.service > /dev/null 2>&1 || :
fi
@ECHO OFF
setlocal ENABLEEXTENSIONS
@ECHO Detecting Java version installed.
:CHECK_JAVA_64
@ECHO Detecting if it is 64 bit machine
set KEY_NAME="HKEY_LOCAL_MACHINE\Software\Wow6432Node\JavaSoft\Java Runtime Environment"
set VALUE_NAME=CurrentVersion
FOR /F "usebackq skip=2 tokens=1-3" %%A IN (`REG QUERY %KEY_NAME% /v %VALUE_NAME% 2^>nul`) DO (
set ValueName=%%A
set ValueType=%%B
set ValueValue=%%C
)
@ECHO CurrentVersion %ValueValue%
SET KEY_NAME="%KEY_NAME:~1,-1%\%ValueValue%"
SET VALUE_NAME=JavaHome
if defined ValueName (
FOR /F "usebackq skip=2 tokens=1,2*" %%A IN (`REG QUERY %KEY_NAME% /v %VALUE_NAME% 2^>nul`) DO (
set ValueName2=%%A
set ValueType2=%%B
set JRE_PATH2=%%C
if defined ValueName2 (
set ValueName = %ValueName2%
set ValueType = %ValueType2%
set ValueValue = %JRE_PATH2%
)
)
)
IF NOT "%JRE_PATH2%" == "" GOTO JAVA_INSTALLED
:CHECK_JAVA_32
@ECHO Detecting if it is 32 bit machine
set KEY_NAME="HKEY_LOCAL_MACHINE\Software\JavaSoft\Java Runtime Environment"
set VALUE_NAME=CurrentVersion
FOR /F "usebackq skip=2 tokens=1-3" %%A IN (`REG QUERY %KEY_NAME% /v %VALUE_NAME% 2^>nul`) DO (
set ValueName=%%A
set ValueType=%%B
set ValueValue=%%C
)
@ECHO CurrentVersion %ValueValue%
SET KEY_NAME="%KEY_NAME:~1,-1%\%ValueValue%"
SET VALUE_NAME=JavaHome
if defined ValueName (
FOR /F "usebackq skip=2 tokens=1,2*" %%A IN (`REG QUERY %KEY_NAME% /v %VALUE_NAME% 2^>nul`) DO (
set ValueName2=%%A
set ValueType2=%%B
set JRE_PATH2=%%C
if defined ValueName2 (
set ValueName = %ValueName2%
set ValueType = %ValueType2%
set ValueValue = %JRE_PATH2%
)
)
)
IF "%JRE_PATH2%" == "" GOTO JAVA_NOT_INSTALLED
:JAVA_INSTALLED
@ECHO Java 1.8 found!
@ECHO Installing ${pkg.name} ...
%~dp0${pkg.name}.exe install
@ECHO DONE.
GOTO END
:JAVA_NOT_INSTALLED
@ECHO Java 1.8 or above is not installed
@ECHO Please go to https://java.com/ and install Java. Then retry installation.
PAUSE
GOTO END
:END
<service>
<id>${pkg.name}</id>
<name>${project.name}</name>
<description>${project.description}</description>
<workingdirectory>%BASE%\conf</workingdirectory>
<logpath>${pkg.winWrapperLogFolder}</logpath>
<logmode>rotate</logmode>
<env name="LOADER_PATH" value="%BASE%\conf" />
<executable>java</executable>
<startargument>-Dplatform=windows</startargument>
<startargument>-jar</startargument>
<startargument>%BASE%\lib\${pkg.name}.jar</startargument>
</service>
@ECHO OFF
@ECHO Stopping ${pkg.name} ...
net stop ${pkg.name}
@ECHO Uninstalling ${pkg.name} ...
%~dp0${pkg.name}.exe uninstall
@ECHO DONE.
\ No newline at end of file
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
<id>windows</id>
<formats>
<format>zip</format>
</formats>
<!-- Workaround to create logs directory -->
<fileSets>
<fileSet>
<directory>${pkg.win.dist}</directory>
<outputDirectory>logs</outputDirectory>
<excludes>
<exclude>*/**</exclude>
</excludes>
</fileSet>
<fileSet>
<directory>${pkg.win.dist}/conf</directory>
<outputDirectory>conf</outputDirectory>
<lineEnding>windows</lineEnding>
<excludes>
<exclude>*.der</exclude>
<exclude>*.cer</exclude>
<exclude>*.pfx</exclude>
</excludes>
</fileSet>
<fileSet>
<directory>${pkg.win.dist}/conf</directory>
<outputDirectory>conf</outputDirectory>
<includes>
<include>*.der</include>
<include>*.cer</include>
<include>*.pfx</include>
</includes>
</fileSet>
</fileSets>
<files>
<file>
<source>${project.build.directory}/${project.build.finalName}-boot.${project.packaging}</source>
<outputDirectory>lib</outputDirectory>
<destName>${pkg.name}.jar</destName>
</file>
<file>
<source>${pkg.win.dist}/service.exe</source>
<outputDirectory/>
<destName>${pkg.name}.exe</destName>
</file>
<file>
<source>${pkg.win.dist}/service.xml</source>
<outputDirectory/>
<destName>${pkg.name}.xml</destName>
<lineEnding>windows</lineEnding>
</file>
<file>
<source>${pkg.win.dist}/install.bat</source>
<outputDirectory/>
<lineEnding>windows</lineEnding>
</file>
<file>
<source>${pkg.win.dist}/uninstall.bat</source>
<outputDirectory/>
<lineEnding>windows</lineEnding>
</file>
</files>
</assembly>
export JAVA_OPTS="$JAVA_OPTS -Dplatform=@pkg.platform@"
export LOG_FILENAME=${pkg.name}.out
export LOADER_PATH=${pkg.installFolder}/conf
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration>
<configuration>
<appender name="fileLogAppender"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${pkg.logFolder}/${pkg.name}.log</file>
<rollingPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${pkg.logFolder}/${pkg.name}.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<maxFileSize>100MB</maxFileSize>
<maxHistory>30</maxHistory>
<totalSizeCap>3GB</totalSizeCap>
</rollingPolicy>
<encoder>
<pattern>%d{ISO8601} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<logger name="org.priusis" level="INFO" />
<logger name="org.eclipse.milo" level="INFO" />
<logger name="org.eclipse.paho" level="INFO" />
<root level="INFO">
<appender-ref ref="fileLogAppender"/>
</root>
</configuration>
pkg.logFolder=${pkg.unixLogFolder}
\ No newline at end of file
pkg.logFolder=${BASE}\\logs
pkg.winWrapperLogFolder=%BASE%\\logs
[Unit]
Description=${pkg.name}
After=syslog.target
[Service]
User=${pkg.user}
ExecStart=${pkg.installFolder}/bin/${pkg.name}.jar
SuccessExitStatus=143
[Install]
WantedBy=multi-user.target
#!/bin/sh
chown -R ${pkg.user}: ${pkg.logFolder}
chown -R ${pkg.user}: ${pkg.installFolder}
update-rc.d ${pkg.name} defaults
#!/bin/sh
update-rc.d -f ${pkg.name} remove
#!/bin/sh
if ! getent group ${pkg.user} >/dev/null; then
addgroup --system ${pkg.user}
fi
if ! getent passwd ${pkg.user} >/dev/null; then
adduser --quiet \
--system \
--ingroup ${pkg.user} \
--quiet \
--disabled-login \
--disabled-password \
--home ${pkg.installFolder} \
--no-create-home \
-gecos "Priusisiot application" \
${pkg.user}
fi
#!/bin/sh
if [ -e /var/run/${pkg.name}/${pkg.name}.pid ]; then
service ${pkg.name} stop
fi
#!/bin/sh
chown -R ${pkg.user}: ${pkg.logFolder}
chown -R ${pkg.user}: ${pkg.installFolder}
if [ $1 -eq 1 ] ; then
# Initial installation
systemctl --no-reload enable ${pkg.name}.service >/dev/null 2>&1 || :
fi
#!/bin/sh
if [ $1 -ge 1 ] ; then
# Package upgrade, not uninstall
systemctl try-restart ${pkg.name}.service >/dev/null 2>&1 || :
fi
#!/bin/sh
getent group ${pkg.user} >/dev/null || groupadd -r ${pkg.user}
getent passwd ${pkg.user} >/dev/null || \
useradd -d ${pkg.installFolder} -g ${pkg.user} -M -r ${pkg.user} -s /sbin/nologin \
-c "Priusisiot application"
#!/bin/sh
if [ $1 -eq 0 ] ; then
# Package removal, not upgrade
systemctl --no-reload disable --now ${pkg.name}.service > /dev/null 2>&1 || :
fi
@ECHO OFF
setlocal ENABLEEXTENSIONS
@ECHO Detecting Java version installed.
:CHECK_JAVA_64
@ECHO Detecting if it is 64 bit machine
set KEY_NAME="HKEY_LOCAL_MACHINE\Software\Wow6432Node\JavaSoft\Java Runtime Environment"
set VALUE_NAME=CurrentVersion
FOR /F "usebackq skip=2 tokens=1-3" %%A IN (`REG QUERY %KEY_NAME% /v %VALUE_NAME% 2^>nul`) DO (
set ValueName=%%A
set ValueType=%%B
set ValueValue=%%C
)
@ECHO CurrentVersion %ValueValue%
SET KEY_NAME="%KEY_NAME:~1,-1%\%ValueValue%"
SET VALUE_NAME=JavaHome
if defined ValueName (
FOR /F "usebackq skip=2 tokens=1,2*" %%A IN (`REG QUERY %KEY_NAME% /v %VALUE_NAME% 2^>nul`) DO (
set ValueName2=%%A
set ValueType2=%%B
set JRE_PATH2=%%C
if defined ValueName2 (
set ValueName = %ValueName2%
set ValueType = %ValueType2%
set ValueValue = %JRE_PATH2%
)
)
)
IF NOT "%JRE_PATH2%" == "" GOTO JAVA_INSTALLED
:CHECK_JAVA_32
@ECHO Detecting if it is 32 bit machine
set KEY_NAME="HKEY_LOCAL_MACHINE\Software\JavaSoft\Java Runtime Environment"
set VALUE_NAME=CurrentVersion
FOR /F "usebackq skip=2 tokens=1-3" %%A IN (`REG QUERY %KEY_NAME% /v %VALUE_NAME% 2^>nul`) DO (
set ValueName=%%A
set ValueType=%%B
set ValueValue=%%C
)
@ECHO CurrentVersion %ValueValue%
SET KEY_NAME="%KEY_NAME:~1,-1%\%ValueValue%"
SET VALUE_NAME=JavaHome
if defined ValueName (
FOR /F "usebackq skip=2 tokens=1,2*" %%A IN (`REG QUERY %KEY_NAME% /v %VALUE_NAME% 2^>nul`) DO (
set ValueName2=%%A
set ValueType2=%%B
set JRE_PATH2=%%C
if defined ValueName2 (
set ValueName = %ValueName2%
set ValueType = %ValueType2%
set ValueValue = %JRE_PATH2%
)
)
)
IF "%JRE_PATH2%" == "" GOTO JAVA_NOT_INSTALLED
:JAVA_INSTALLED
@ECHO Java 1.8 found!
@ECHO Installing ${pkg.name} ...
%~dp0${pkg.name}.exe install
@ECHO DONE.
GOTO END
:JAVA_NOT_INSTALLED
@ECHO Java 1.8 or above is not installed
@ECHO Please go to https://java.com/ and install Java. Then retry installation.
PAUSE
GOTO END
:END
<service>
<id>${pkg.name}</id>
<name>${project.name}</name>
<description>${project.description}</description>
<workingdirectory>%BASE%\conf</workingdirectory>
<logpath>${pkg.winWrapperLogFolder}</logpath>
<logmode>rotate</logmode>
<env name="LOADER_PATH" value="%BASE%\conf" />
<executable>java</executable>
<startargument>-Dplatform=windows</startargument>
<startargument>-jar</startargument>
<startargument>%BASE%\lib\${pkg.name}.jar</startargument>
</service>
@ECHO OFF
@ECHO Stopping ${pkg.name} ...
net stop ${pkg.name}
@ECHO Uninstalling ${pkg.name} ...
%~dp0${pkg.name}.exe uninstall
@ECHO DONE.
\ No newline at end of file
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
<id>windows</id>
<formats>
<format>zip</format>
</formats>
<!-- Workaround to create logs directory -->
<fileSets>
<fileSet>
<directory>${pkg.win.dist}</directory>
<outputDirectory>logs</outputDirectory>
<excludes>
<exclude>*/**</exclude>
</excludes>
</fileSet>
<fileSet>
<directory>${pkg.win.dist}/conf</directory>
<outputDirectory>conf</outputDirectory>
<lineEnding>windows</lineEnding>
<excludes>
<exclude>*.der</exclude>
<exclude>*.cer</exclude>
<exclude>*.pfx</exclude>
</excludes>
</fileSet>
<fileSet>
<directory>${pkg.win.dist}/conf</directory>
<outputDirectory>conf</outputDirectory>
<includes>
<include>*.der</include>
<include>*.cer</include>
<include>*.pfx</include>
</includes>
</fileSet>
</fileSets>
<files>
<file>
<source>${project.build.directory}/${project.build.finalName}-boot.${project.packaging}</source>
<outputDirectory>lib</outputDirectory>
<destName>${pkg.name}.jar</destName>
</file>
<file>
<source>${pkg.win.dist}/service.exe</source>
<outputDirectory/>
<destName>${pkg.name}.exe</destName>
</file>
<file>
<source>${pkg.win.dist}/service.xml</source>
<outputDirectory/>
<destName>${pkg.name}.xml</destName>
<lineEnding>windows</lineEnding>
</file>
<file>
<source>${pkg.win.dist}/install.bat</source>
<outputDirectory/>
<lineEnding>windows</lineEnding>
</file>
<file>
<source>${pkg.win.dist}/uninstall.bat</source>
<outputDirectory/>
<lineEnding>windows</lineEnding>
</file>
</files>
</assembly>
export JAVA_OPTS="$JAVA_OPTS -Dplatform=@pkg.platform@"
export LOG_FILENAME=${pkg.name}.out
export LOADER_PATH=${pkg.installFolder}/conf
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration>
<configuration>
<appender name="fileLogAppender"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${pkg.logFolder}/${pkg.name}.log</file>
<rollingPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${pkg.logFolder}/${pkg.name}.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<maxFileSize>100MB</maxFileSize>
<maxHistory>30</maxHistory>
<totalSizeCap>3GB</totalSizeCap>
</rollingPolicy>
<encoder>
<pattern>%d{ISO8601} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<logger name="org.priusis" level="INFO" />
<logger name="org.eclipse.milo" level="INFO" />
<logger name="org.eclipse.paho" level="INFO" />
<root level="INFO">
<appender-ref ref="fileLogAppender"/>
</root>
</configuration>
pkg.logFolder=${pkg.unixLogFolder}
\ No newline at end of file
pkg.logFolder=${BASE}\\logs
pkg.winWrapperLogFolder=%BASE%\\logs
[Unit]
Description=${pkg.name}
After=syslog.target
[Service]
User=${pkg.user}
ExecStart=${pkg.installFolder}/bin/${pkg.name}.jar
SuccessExitStatus=143
[Install]
WantedBy=multi-user.target
#!/bin/sh
chown -R ${pkg.user}: ${pkg.logFolder}
chown -R ${pkg.user}: ${pkg.installFolder}
update-rc.d ${pkg.name} defaults
#!/bin/sh
update-rc.d -f ${pkg.name} remove
#!/bin/sh
if ! getent group ${pkg.user} >/dev/null; then
addgroup --system ${pkg.user}
fi
if ! getent passwd ${pkg.user} >/dev/null; then
adduser --quiet \
--system \
--ingroup ${pkg.user} \
--quiet \
--disabled-login \
--disabled-password \
--home ${pkg.installFolder} \
--no-create-home \
-gecos "Priusisiot application" \
${pkg.user}
fi
#!/bin/sh
if [ -e /var/run/${pkg.name}/${pkg.name}.pid ]; then
service ${pkg.name} stop
fi
#!/bin/sh
chown -R ${pkg.user}: ${pkg.logFolder}
chown -R ${pkg.user}: ${pkg.installFolder}
if [ $1 -eq 1 ] ; then
# Initial installation
systemctl --no-reload enable ${pkg.name}.service >/dev/null 2>&1 || :
fi
#!/bin/sh
if [ $1 -ge 1 ] ; then
# Package upgrade, not uninstall
systemctl try-restart ${pkg.name}.service >/dev/null 2>&1 || :
fi
#!/bin/sh
getent group ${pkg.user} >/dev/null || groupadd -r ${pkg.user}
getent passwd ${pkg.user} >/dev/null || \
useradd -d ${pkg.installFolder} -g ${pkg.user} -M -r ${pkg.user} -s /sbin/nologin \
-c "Priusisiot application"
#!/bin/sh
if [ $1 -eq 0 ] ; then
# Package removal, not upgrade
systemctl --no-reload disable --now ${pkg.name}.service > /dev/null 2>&1 || :
fi
@ECHO OFF
setlocal ENABLEEXTENSIONS
@ECHO Detecting Java version installed.
:CHECK_JAVA_64
@ECHO Detecting if it is 64 bit machine
set KEY_NAME="HKEY_LOCAL_MACHINE\Software\Wow6432Node\JavaSoft\Java Runtime Environment"
set VALUE_NAME=CurrentVersion
FOR /F "usebackq skip=2 tokens=1-3" %%A IN (`REG QUERY %KEY_NAME% /v %VALUE_NAME% 2^>nul`) DO (
set ValueName=%%A
set ValueType=%%B
set ValueValue=%%C
)
@ECHO CurrentVersion %ValueValue%
SET KEY_NAME="%KEY_NAME:~1,-1%\%ValueValue%"
SET VALUE_NAME=JavaHome
if defined ValueName (
FOR /F "usebackq skip=2 tokens=1,2*" %%A IN (`REG QUERY %KEY_NAME% /v %VALUE_NAME% 2^>nul`) DO (
set ValueName2=%%A
set ValueType2=%%B
set JRE_PATH2=%%C
if defined ValueName2 (
set ValueName = %ValueName2%
set ValueType = %ValueType2%
set ValueValue = %JRE_PATH2%
)
)
)
IF NOT "%JRE_PATH2%" == "" GOTO JAVA_INSTALLED
:CHECK_JAVA_32
@ECHO Detecting if it is 32 bit machine
set KEY_NAME="HKEY_LOCAL_MACHINE\Software\JavaSoft\Java Runtime Environment"
set VALUE_NAME=CurrentVersion
FOR /F "usebackq skip=2 tokens=1-3" %%A IN (`REG QUERY %KEY_NAME% /v %VALUE_NAME% 2^>nul`) DO (
set ValueName=%%A
set ValueType=%%B
set ValueValue=%%C
)
@ECHO CurrentVersion %ValueValue%
SET KEY_NAME="%KEY_NAME:~1,-1%\%ValueValue%"
SET VALUE_NAME=JavaHome
if defined ValueName (
FOR /F "usebackq skip=2 tokens=1,2*" %%A IN (`REG QUERY %KEY_NAME% /v %VALUE_NAME% 2^>nul`) DO (
set ValueName2=%%A
set ValueType2=%%B
set JRE_PATH2=%%C
if defined ValueName2 (
set ValueName = %ValueName2%
set ValueType = %ValueType2%
set ValueValue = %JRE_PATH2%
)
)
)
IF "%JRE_PATH2%" == "" GOTO JAVA_NOT_INSTALLED
:JAVA_INSTALLED
@ECHO Java 1.8 found!
@ECHO Installing ${pkg.name} ...
%~dp0${pkg.name}.exe install
@ECHO DONE.
GOTO END
:JAVA_NOT_INSTALLED
@ECHO Java 1.8 or above is not installed
@ECHO Please go to https://java.com/ and install Java. Then retry installation.
PAUSE
GOTO END
:END
<service>
<id>${pkg.name}</id>
<name>${project.name}</name>
<description>${project.description}</description>
<workingdirectory>%BASE%\conf</workingdirectory>
<logpath>${pkg.winWrapperLogFolder}</logpath>
<logmode>rotate</logmode>
<env name="LOADER_PATH" value="%BASE%\conf" />
<executable>java</executable>
<startargument>-Dplatform=windows</startargument>
<startargument>-jar</startargument>
<startargument>%BASE%\lib\${pkg.name}.jar</startargument>
</service>
@ECHO OFF
@ECHO Stopping ${pkg.name} ...
net stop ${pkg.name}
@ECHO Uninstalling ${pkg.name} ...
%~dp0${pkg.name}.exe uninstall
@ECHO DONE.
\ No newline at end of file
......@@ -21,7 +21,7 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.build.timestamp.format>yyyyMMdd</maven.build.timestamp.format>
<maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
<jdk.version>1.8</jdk.version>
<java.version>1.8</java.version>
<netty.version>4.1.49.Final</netty.version>
<guava.version>28.2-jre</guava.version>
......@@ -50,6 +50,19 @@
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论