nuri2 실행스크립트 파일 생성 메소드 추가
parent
3cafe1b9e2
commit
0214d4886b
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -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);
|
||||||
|
|
||||||
|
}
|
||||||
@ -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";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -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<OutputStream> writer = new Consumer<OutputStream>() {
|
||||||
|
@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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue