增加关闭服务接口以及在linux上安装为服务的脚本
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -431,6 +431,7 @@
|
|||||||
<exclude>**/application.yml</exclude>
|
<exclude>**/application.yml</exclude>
|
||||||
<exclude>**/application-*.yml</exclude>
|
<exclude>**/application-*.yml</exclude>
|
||||||
<exclude>**/local.jks</exclude>
|
<exclude>**/local.jks</exclude>
|
||||||
|
<exclude>**/install.sh</exclude>
|
||||||
</excludes>
|
</excludes>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
@@ -450,6 +451,7 @@
|
|||||||
<includes>
|
<includes>
|
||||||
<include>application.yml</include>
|
<include>application.yml</include>
|
||||||
<include>application-*.yml</include>
|
<include>application-*.yml</include>
|
||||||
|
<include>install.sh</include>
|
||||||
</includes>
|
</includes>
|
||||||
</resource>
|
</resource>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import io.swagger.v3.oas.annotations.Operation;
|
|||||||
import io.swagger.v3.oas.annotations.Parameter;
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
@@ -47,7 +48,7 @@ import java.util.*;
|
|||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
@Tag(name = "服务控制")
|
@Tag(name = "服务控制")
|
||||||
|
@Slf4j
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/server")
|
@RequestMapping("/api/server")
|
||||||
public class ServerController {
|
public class ServerController {
|
||||||
@@ -176,33 +177,14 @@ public class ServerController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Operation(summary = "重启服务", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
@Operation(summary = "关闭服务", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||||
@GetMapping(value = "/restart")
|
@GetMapping(value = "/shutdown")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public void restart() {
|
public void shutdown() {
|
||||||
// taskExecutor.execute(()-> {
|
log.info("正在关闭服务。。。");
|
||||||
// try {
|
System.exit(1);
|
||||||
// Thread.sleep(3000);
|
|
||||||
// SipProvider up = (SipProvider) SpringBeanFactory.getBean("udpSipProvider");
|
|
||||||
// SipStackImpl stack = (SipStackImpl) up.getSipStack();
|
|
||||||
// stack.stop();
|
|
||||||
// Iterator listener = stack.getListeningPoints();
|
|
||||||
// while (listener.hasNext()) {
|
|
||||||
// stack.deleteListeningPoint((ListeningPoint) listener.next());
|
|
||||||
// }
|
|
||||||
// Iterator providers = stack.getSipProviders();
|
|
||||||
// while (providers.hasNext()) {
|
|
||||||
// stack.deleteSipProvider((SipProvider) providers.next());
|
|
||||||
// }
|
|
||||||
// VManageBootstrap.restart();
|
|
||||||
// } catch (InterruptedException | ObjectInUseException e) {
|
|
||||||
// throw new ControllerException(ErrorCode.ERROR100.getCode(), e.getMessage());
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
;
|
|
||||||
|
|
||||||
@Operation(summary = "获取系统配置信息", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
@Operation(summary = "获取系统配置信息", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||||
@GetMapping(value = "/system/configInfo")
|
@GetMapping(value = "/system/configInfo")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
|
|||||||
57
src/main/resources/install.sh
Executable file
57
src/main/resources/install.sh
Executable file
@@ -0,0 +1,57 @@
|
|||||||
|
#! /bin/sh
|
||||||
|
|
||||||
|
WORD_DIR=$(cd $(dirname $0); pwd)
|
||||||
|
SERVICE_NAME="wvp"
|
||||||
|
|
||||||
|
# 检查是否为 root 用户
|
||||||
|
if [ "$(id -u)" -ne 0 ]; then
|
||||||
|
echo "提示: 建议使用 root 用户执行此脚本,否则可能权限不足!"
|
||||||
|
read -p "继续?(y/n) " -n 1 -r
|
||||||
|
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 当前目录直接搜索(不含子目录)
|
||||||
|
jar_files=(*.jar)
|
||||||
|
|
||||||
|
if [ ${#jar_files[@]} -eq 0 ]; then
|
||||||
|
echo "当前目录无 JAR 文件!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 遍历结果
|
||||||
|
for jar in "${jar_files[@]}"; do
|
||||||
|
echo "找到 JAR 文件: $jar"
|
||||||
|
done
|
||||||
|
|
||||||
|
# 写文件
|
||||||
|
# 生成 Systemd 服务文件内容
|
||||||
|
SERVICE_FILE="/etc/systemd/system/${SERVICE_NAME}.service"
|
||||||
|
cat << EOF | sudo tee "$SERVICE_FILE" > /dev/null
|
||||||
|
[Unit]
|
||||||
|
Description=${SERVICE_NAME}
|
||||||
|
After=syslog.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
User=$USER
|
||||||
|
WorkingDirectory=${WORD_DIR}
|
||||||
|
ExecStart=java -jar ${jar_files}
|
||||||
|
SuccessExitStatus=143
|
||||||
|
Restart=on-failure
|
||||||
|
RestartSec=10s
|
||||||
|
Environment=SPRING_PROFILES_ACTIVE=prod
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# 重载 Systemd 并启动服务
|
||||||
|
sudo systemctl daemon-reload
|
||||||
|
sudo systemctl enable "$SERVICE_NAME"
|
||||||
|
sudo systemctl start "$SERVICE_NAME"
|
||||||
|
|
||||||
|
# 验证服务状态
|
||||||
|
echo "服务已安装!执行以下命令查看状态:"
|
||||||
|
echo "sudo systemctl status $SERVICE_NAME"
|
||||||
Reference in New Issue
Block a user