From 0214d4886beb5439e3783a0eb992528aa75aae16 Mon Sep 17 00:00:00 2001 From: leebj Date: Tue, 19 Nov 2024 13:43:17 +0900 Subject: [PATCH] =?UTF-8?q?nuri2=20=EC=8B=A4=ED=96=89=EC=8A=A4=ED=81=AC?= =?UTF-8?q?=EB=A6=BD=ED=8A=B8=20=ED=8C=8C=EC=9D=BC=20=EC=83=9D=EC=84=B1=20?= =?UTF-8?q?=EB=A9=94=EC=86=8C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 5 + .../cokr/xit/custom/boot/CommonConfig.java | 3 +- .../nuri2/service/bean/LinuxServiceBean.java | 138 ++++++++++++++++++ .../nuri2/service/bean/Nuri2ServiceBean.java | 16 ++ .../service/bean/WindowsServiceBean.java | 108 ++++++++++++++ .../nuri2/web/nuri2Controller.java | 80 ++++++++++ 6 files changed, 349 insertions(+), 1 deletion(-) create mode 100644 src/main/java/externalsystem/nuri2/service/bean/LinuxServiceBean.java create mode 100644 src/main/java/externalsystem/nuri2/service/bean/Nuri2ServiceBean.java create mode 100644 src/main/java/externalsystem/nuri2/service/bean/WindowsServiceBean.java create mode 100644 src/main/java/externalsystem/nuri2/web/nuri2Controller.java diff --git a/pom.xml b/pom.xml index 7dbf1d5e..c29c8b11 100644 --- a/pom.xml +++ b/pom.xml @@ -55,6 +55,11 @@ + + cokr.xit.base + xit-file + 23.04.01-SNAPSHOT + org.springframework.boot diff --git a/src/main/java/cokr/xit/custom/boot/CommonConfig.java b/src/main/java/cokr/xit/custom/boot/CommonConfig.java index f3b25d65..44e7b0fd 100644 --- a/src/main/java/cokr/xit/custom/boot/CommonConfig.java +++ b/src/main/java/cokr/xit/custom/boot/CommonConfig.java @@ -26,7 +26,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; "externalsystem.sinmungo", "externalsystem.nxrp", "externalsystem.piss", - "externalsystem.ino" + "externalsystem.ino", + "externalsystem.nuri2" }) public class CommonConfig { /**AntPathMatcher를 반환한다. diff --git a/src/main/java/externalsystem/nuri2/service/bean/LinuxServiceBean.java b/src/main/java/externalsystem/nuri2/service/bean/LinuxServiceBean.java new file mode 100644 index 00000000..946a45cb --- /dev/null +++ b/src/main/java/externalsystem/nuri2/service/bean/LinuxServiceBean.java @@ -0,0 +1,138 @@ +package externalsystem.nuri2.service.bean; + +import java.io.File; + +import javax.servlet.http.HttpServletRequest; + +import cokr.xit.TextFileMaker; + +public class LinuxServiceBean extends Nuri2ServiceBean { + + public String shFileName = "nuri2_launcher.sh"; + + @Override + public String makeScriptFile(HttpServletRequest req) { + String javaHomeSettingLine = ""; + String nuriHomeSettingLine = ""; + String nuriNameSettingLine = ""; + String nuriConfSettingLine = ""; + + String nuriHomeDir = req.getParameter("nuriHomeDir"); + + String jdkVendor = req.getParameter("jdkVendor"); + String jdkPath = ""; + String jdkBinPath = ""; + + TextFileMaker sh = new TextFileMaker(); + sh.setLineChange("\n"); + + + //주석1 + String comment1 = """ +#!/bin/bash + +# chmod 755 launcher.sh 권한을 주어야 합니다. +# JAVA_HOME 은 java 실행파일이 있는 전체 경로를 의미합니다. +# 실행이 안 될 땐 launcher.sh 파일에서 아랫부분의 java 실행 경로가 맞는지 확인하시기 바랍니다. + """; + + sh.addLine(comment1); + + javaHomeSettingLine = "JAVA_HOME=" + jdkBinPath; + sh.addLine(javaHomeSettingLine); + nuriHomeSettingLine = "NURI_HOME=" + nuriHomeDir; + sh.addLine(nuriHomeSettingLine); + nuriNameSettingLine = "NURI_NAMES=" + nuri2jarName; + sh.addLine(nuriNameSettingLine); + nuriConfSettingLine = "NURI_CONF="+ "./" + nuri2confName; + sh.addLine(nuriConfSettingLine); + + //명령어 입력 경고 + String commandRequireAlert = "if [ $# == 0 ]\n" + + " then echo \"Usage: launcher.sh [start | stop | list | version]\"; exit;\n" + + "fi"; + sh.addLine(commandRequireAlert); + + String comment2 = """ +################################################# +#* 필수 설정 한글(utf8 설정) +# [사용자 정의] 서버에 한글 인코딩 설정(locale -a|grep ko) +# 시스템에 맞는 locale 설정 필요(대소문자 식별) +################################################# +# Unix , Linux 계열 공통 서버에 locale 확인방법 +# System(user)/home/nuri2> locale -a|grep ko +# ko_KR +# ko_KR.euckr +# ko_KR.utf8 +# ...... +# csh 일 경우 setenv LANG ko_KR.utf8, AIX 의 경우 ko_KR.IBM-utf8 + + """; + sh.addLine(comment2); + + String languageSettingLine = "export LANG=ko_KR.utf8"; + sh.addLine(languageSettingLine); + + //명령어별 분기 + String caseLines = """ +case "$1" in + +[Vv]ersion) + echo "Nuri2 Solution v1.0" +;; + +[Ss]tart) + echo "START Nuri2 Process" + + nuri2_process=$(ps -ef | grep "$NURI2_NAMES" | grep -v grep | wc -l) + + if [ "$nuri2_process" -gt 0 ] + + then + echo "Nuri2 Alive." + else + { + cd "$NURI2_HOME" || exit + nohup "$JAVA_HOME/java" -Xms700m -Xmx1250m -jar "$NURI2_HOME/$NURI2_NAMES" "$NURI2_HOME/$NURI2_CONF" > /dev/null & + echo "Nuri2 Process Start-up." + } + fi + + cd "$NURI2_HOME" || exit +;; + +[Ss]top) + echo "STOP Nuri2 Process" + + nuri2_process=$(ps -ef | grep "$NURI2_HOME/$NURI2_NAMES" | grep -v grep | wc -l) + + if [ "$nuri2_process" -gt 0 ] + then + { + kill_pid=$(ps -ef | grep "$NURI2_HOME/$NURI2_NAMES" | grep -v grep | awk '{print $2}') + kill "$kill_pid"; + echo "Nuri2 Process Stop." + } + fi +;; + +[Ll]ist) + echo "PID PPID STIME COMMAND" + for nuri2_name in $NURI2_NAMES + do +# ps -ef | grep "$nuri2_name" | grep -v grep | grep -v awk | awk '{if(9==NF) printf "%s\t%s\t%s\t%s %s\n",$2,$3,$5,$8,$9; else printf "%s\t%s\t%s %4-s\t%s %s\n",$2,$3,$5,$6,$9,$10}' | sort + ps -ef | grep "$nuri2_name" | grep -v grep | grep -v awk | sort + done +;; + +esac + """; + + sh.addLine(caseLines); + String shFileContents = sh.getFileCn(); + + sh.makeTxtFile("C:\\Temp",shFileName,shFileContents); + + return "C:\\Temp" + File.separator + shFileName; + } +} diff --git a/src/main/java/externalsystem/nuri2/service/bean/Nuri2ServiceBean.java b/src/main/java/externalsystem/nuri2/service/bean/Nuri2ServiceBean.java new file mode 100644 index 00000000..ed604917 --- /dev/null +++ b/src/main/java/externalsystem/nuri2/service/bean/Nuri2ServiceBean.java @@ -0,0 +1,16 @@ +package externalsystem.nuri2.service.bean; + +import javax.servlet.http.HttpServletRequest; + +public abstract class Nuri2ServiceBean { + + + public String nuri2jarName = "nuri2.jar"; + public String nuri2confName = "nuri2.conf"; + + + public String sharps = "#############################################"; + + public abstract String makeScriptFile(HttpServletRequest req); + +} diff --git a/src/main/java/externalsystem/nuri2/service/bean/WindowsServiceBean.java b/src/main/java/externalsystem/nuri2/service/bean/WindowsServiceBean.java new file mode 100644 index 00000000..2565b427 --- /dev/null +++ b/src/main/java/externalsystem/nuri2/service/bean/WindowsServiceBean.java @@ -0,0 +1,108 @@ +package externalsystem.nuri2.service.bean; + +import java.io.File; + +import javax.servlet.http.HttpServletRequest; + +import cokr.xit.TextFileMaker; +import cokr.xit.base.file.ZIP; + +public class WindowsServiceBean extends Nuri2ServiceBean { + + public String ECHO_OFF = "@echo off"; + + public String cmdFileName = "nuri2_Windows_run.cmd"; + public String install_batFileName = "nuri2_Windows_Serviceinstall_32bit.bat"; + public String uninstall_batFileName = "nuri2_Windows_Serviceuninstall_32bit.bat"; + + public String nuri2serviceName = "00_Nuri2_MASTER"; + + @Override + public String makeScriptFile(HttpServletRequest req) { + String javaHomeSettingLine = ""; + String nuriHomeSettingLine = ""; + String nuriNameSettingLine = ""; + String nuriConfSettingLine = ""; + + String nuriHomeDir = req.getParameter("nuriHomeDir"); + + String jdkVendor = req.getParameter("jdkVendor"); + String jdkPath = ""; + String jdkBinPath = ""; + + String jdkType = (jdkVendor.equals("azul") ? "zulu" : "oracle"); + // + TextFileMaker install_bat = new TextFileMaker(); + install_bat.addLine(ECHO_OFF); + install_bat.REM("REM은 주석입니다. 현재 실행되지 않습니다."); + install_bat.REM("JAVA 홈경로"); + javaHomeSettingLine = "JAVA_HOME=" + jdkPath; + install_bat.SET(javaHomeSettingLine); + install_bat.REM("누리2 JAR 위치"); + nuriHomeSettingLine = "NURI_HOME=" + nuriHomeDir; + install_bat.SET(nuriHomeSettingLine); + install_bat.REM("누리2 서비스명"); + String nuriServiceSettingLine = "NURI_SERVICE_NAME="+nuri2serviceName; + install_bat.SET(nuriServiceSettingLine); + install_bat.REM("누리2 jar위치"); + nuriNameSettingLine = "NURI_NAME=" + nuri2jarName; + install_bat.SET(nuriNameSettingLine); + install_bat.REM("누리2 환경설정 파일"); + nuriConfSettingLine = "NURI_CONFING="+ nuri2confName; + install_bat.SET(nuriConfSettingLine); + String installParam = "-install \"%NURI_SERVICE_NAME%\" \"%JAVA_HOME%\\jre\\bin\\server\\jvm.dll\" -Djava.class.path=\"%NURI_HOME%\\%NURI_NAME%\" -start kr.co.iheart.Nuri2Main -params %NURI_CONFING% -current \"%NURI_HOME%\" -auto -description \"[Nuri2] %NURI_SERVICE_NAME% Java Service\""; + String install32bit = "\"%NURI_HOME%\\JavaService32.exe\" "+installParam; + install_bat.REM(install32bit); + String install64bit = "\"%NURI_HOME%\\JavaService64.exe\" "+installParam; + install_bat.addLine(install64bit); + + String install_batFileContents = install_bat.getFileCn(); + install_bat.makeTxtFile("C:\\Temp",install_batFileName,install_batFileContents); + + // + TextFileMaker uninstall_bat = new TextFileMaker(); + uninstall_bat.addLine("NET STOP "+nuri2serviceName); + uninstall_bat.SET(nuriHomeSettingLine); + uninstall_bat.SET(nuriServiceSettingLine); + String uninstall32bit = "\"%NURI_HOME%\\JavaService32.exe\" -uninstall \"%NURI_SERVICE_NAME%\""; + String uninstall64bit = "\"%NURI_HOME%\\JavaService64.exe\" -uninstall \"%NURI_SERVICE_NAME%\""; + uninstall_bat.REM(uninstall32bit); + uninstall_bat.addLine(uninstall64bit); + String uninstall_batFileContents = uninstall_bat.getFileCn(); + uninstall_bat.makeTxtFile("C:\\Temp",uninstall_batFileName,uninstall_batFileContents); + + // + TextFileMaker cmd = new TextFileMaker(); + + cmd.addLine(ECHO_OFF); + String remLine1 = jdkType+" jre"; + cmd.REM(remLine1); + + String pathSettingLine = "PATH=" + jdkPath +";"+jdkBinPath+";%PATH%;"; + cmd.addLine(pathSettingLine); + + cmd.REM("REM 한글 EUCK-KR(949) 또는 UTF8(65001) 설정"); + cmd.REM("REM EUCKR(MS949)"); + cmd.REM("REM chcp 949"); + cmd.REM("REM UTF8"); + cmd.REM("REM chcp 65001"); + + String echo1 = "Nuri2 Client Master Start"; + cmd.ECHO(echo1); + String javaCommandLine = "java -jar "+nuri2jarName+ " " +nuri2confName; + cmd.addLine(javaCommandLine); + cmd.addLine("pause"); + String cmdFileContents = cmd.getFileCn(); + cmd.makeTxtFile("C:\\Temp",cmdFileName,cmdFileContents); + + //ZIP 파일 생성(cmd 1, bat 2) + ZIP zip = new ZIP(); + zip.compress("C:\\Temp" + File.separator + "script.zip", + "C:\\Temp" + File.separator + cmdFileName, + "C:\\Temp" + File.separator + install_batFileName, + "C:\\Temp" + File.separator + uninstall_batFileName); + + return "C:\\Temp" + File.separator + "script.zip"; + } + +} diff --git a/src/main/java/externalsystem/nuri2/web/nuri2Controller.java b/src/main/java/externalsystem/nuri2/web/nuri2Controller.java new file mode 100644 index 00000000..374f0200 --- /dev/null +++ b/src/main/java/externalsystem/nuri2/web/nuri2Controller.java @@ -0,0 +1,80 @@ +package externalsystem.nuri2.web; + +import java.io.File; +import java.io.IOException; +import java.io.OutputStream; +import java.nio.file.Files; +import java.util.function.Consumer; + +import javax.servlet.http.HttpServletRequest; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.ModelAndView; + +import cokr.xit.foundation.Downloadable; +import cokr.xit.foundation.web.AbstractController; +import externalsystem.nuri2.service.bean.LinuxServiceBean; +import externalsystem.nuri2.service.bean.WindowsServiceBean; +@Controller +@RequestMapping(name="모바일 메시지 컨트롤러", value="/mms") +public class nuri2Controller extends AbstractController { + + + @RequestMapping(name="모듈 실행 스크립트 파일 생성", value="/createScript.do") + public ModelAndView createScript(HttpServletRequest req) { + ModelAndView mav = new ModelAndView("downloadView"); + + String os = req.getParameter("os"); + + String filePath = ""; + String fileName = ""; + String mimeType = ""; + if(os.equals("windows")) { + + WindowsServiceBean windows = new WindowsServiceBean(); + filePath = windows.makeScriptFile(req); + fileName = "script.zip"; + mimeType = "application/zip"; + } else if(os.equals("linux")) { + LinuxServiceBean linux = new LinuxServiceBean(); + filePath = linux.makeScriptFile(req); + fileName = linux.shFileName; + mimeType = "application/x-sh"; + } + + + //다운로드 + File file = new File(filePath); + + try { + byte[] bytes = Files.readAllBytes(file.toPath()); + + Consumer writer = new Consumer() { + @Override + public void accept(OutputStream os) { + try { + os.write(bytes); + } catch (IOException e) { + e.printStackTrace(); + } + } + }; + + mav.addObject("download", + new Downloadable() + .setContentType(mimeType) + .setWriter(writer) + .setFilename(fileName) + ); + } catch (IOException e) { + e.printStackTrace(); + } + + return mav; + } + + + + +}