优化代码。
This commit is contained in:
parent
f6090022de
commit
7d42314d01
Binary file not shown.
|
|
@ -126,7 +126,7 @@ class InstallMariaDb:
|
||||||
self.__set_java_env()
|
self.__set_java_env()
|
||||||
# logger.info("生成脚本文件")
|
# logger.info("生成脚本文件")
|
||||||
# self.__set_bat()
|
# self.__set_bat()
|
||||||
logger.info("安装完成,10秒后自动退出")
|
logger.info("安装完成,10秒后进行数据库服务安装")
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
@ -202,6 +202,8 @@ class InstallComacDb:
|
||||||
self.__delete_old_files(self.app_log_dir)
|
self.__delete_old_files(self.app_log_dir)
|
||||||
self.__remove_pre_service()
|
self.__remove_pre_service()
|
||||||
self.__register_and_start_service()
|
self.__register_and_start_service()
|
||||||
|
logger.info("运行完成,10秒钟后自动退出")
|
||||||
|
time.sleep(10)
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def __delete_old_files(self, directory, days=2):
|
def __delete_old_files(self, directory, days=2):
|
||||||
|
|
@ -245,15 +247,15 @@ class InstallComacDb:
|
||||||
]
|
]
|
||||||
|
|
||||||
# 执行安装命令
|
# 执行安装命令
|
||||||
print("Installing service...")
|
logger.info("Installing service...")
|
||||||
result = subprocess.run(cmd, capture_output=True, text=True)
|
result = subprocess.run(cmd, capture_output=True, text=True)
|
||||||
|
|
||||||
if result.returncode != 0:
|
if result.returncode != 0:
|
||||||
print("Error installing service:")
|
logger.info("Error installing service:")
|
||||||
print(result.stderr)
|
logger.info(result.stderr)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
print("Service installed successfully!")
|
logger.info("Service installed successfully!")
|
||||||
|
|
||||||
# 设置服务显示名称和描述
|
# 设置服务显示名称和描述
|
||||||
subprocess.run([str(self.nssm_exe), "set", self.service_name, "DisplayName", self.service_name])
|
subprocess.run([str(self.nssm_exe), "set", self.service_name, "DisplayName", self.service_name])
|
||||||
|
|
@ -265,16 +267,17 @@ class InstallComacDb:
|
||||||
# 设置启动类型为自动(可选)
|
# 设置启动类型为自动(可选)
|
||||||
subprocess.run([str(self.nssm_exe), "set", self.service_name, "Start", "SERVICE_AUTO_START"])
|
subprocess.run([str(self.nssm_exe), "set", self.service_name, "Start", "SERVICE_AUTO_START"])
|
||||||
|
|
||||||
print("Service configuration completed.")
|
logger.info("Service configuration completed.")
|
||||||
print(f"You can now start the service with: net start {self.service_name}")
|
|
||||||
subprocess.run(rf"net start {self.service_name}")
|
subprocess.run(rf"net start {self.service_name}")
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
|
|
||||||
def __remove_pre_service(self):
|
def __remove_pre_service(self):
|
||||||
|
logger.info("清理历史服务")
|
||||||
stop_command = ["sc", "stop", self.service_name]
|
stop_command = ["sc", "stop", self.service_name]
|
||||||
delete_command = ["sc", "delete", self.service_name]
|
delete_command = ["sc", "delete", self.service_name]
|
||||||
subprocess.run(stop_command, capture_output=True, text=True)
|
subprocess.run(stop_command, capture_output=True, text=True)
|
||||||
subprocess.run(delete_command, capture_output=True, text=True)
|
subprocess.run(delete_command, capture_output=True, text=True)
|
||||||
|
time.sleep(5)
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,14 @@
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
|
import shutil
|
||||||
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import zipfile
|
import zipfile
|
||||||
import subprocess
|
|
||||||
import loguru
|
|
||||||
import elevate
|
import elevate
|
||||||
import shutil
|
import loguru
|
||||||
import psutil
|
import psutil
|
||||||
import re
|
|
||||||
|
|
||||||
root_path = r'D:\database'
|
root_path = r'D:\database'
|
||||||
service_name = 'ComacMariaDB'
|
service_name = 'ComacMariaDB'
|
||||||
|
|
|
||||||
11
src/start.py
11
src/start.py
|
|
@ -1,14 +1,13 @@
|
||||||
|
import argparse
|
||||||
import os
|
import os
|
||||||
import time
|
import re
|
||||||
|
|
||||||
from loguru import logger
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
import time
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import re
|
|
||||||
import webview
|
|
||||||
|
|
||||||
import argparse
|
import webview
|
||||||
|
from loguru import logger
|
||||||
|
|
||||||
# 获取当前脚本所在的目录
|
# 获取当前脚本所在的目录
|
||||||
new_java_path = 'D:/database/jdk/bin/java.exe'
|
new_java_path = 'D:/database/jdk/bin/java.exe'
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue