|
|
@ -5,6 +5,7 @@ package main |
|
|
|
|
|
|
|
import ( |
|
|
|
"archive/zip" |
|
|
|
"bufio" |
|
|
|
"fmt" |
|
|
|
"github.com/lxn/walk" |
|
|
|
. "github.com/lxn/walk/declarative" |
|
|
@ -12,6 +13,7 @@ import ( |
|
|
|
"golang.org/x/sys/windows" |
|
|
|
"golang.org/x/sys/windows/registry" |
|
|
|
"io" |
|
|
|
"log" |
|
|
|
"os" |
|
|
|
"os/exec" |
|
|
|
"path/filepath" |
|
|
@ -56,11 +58,11 @@ var path string |
|
|
|
func init() { |
|
|
|
app.title = "公务员管理系统-运行监控" |
|
|
|
service1 = myService{ |
|
|
|
text: "数据存储库", |
|
|
|
text: "⚡数据存储库", |
|
|
|
serviceName: "GWY20_Mysql", |
|
|
|
} |
|
|
|
service3 = myService{ |
|
|
|
text: "公务员系统", |
|
|
|
text: "⚡公务员系统", |
|
|
|
serviceName: "GWY20_Tomcat", |
|
|
|
} |
|
|
|
path, _ = os.Getwd() |
|
|
@ -103,6 +105,170 @@ func main() { |
|
|
|
app.mw.Run() |
|
|
|
} |
|
|
|
|
|
|
|
// 初始始化窗体
|
|
|
|
func getWindows() error { |
|
|
|
icon, _ := walk.NewIconFromResourceId(3) |
|
|
|
err := MainWindow{ |
|
|
|
Visible: false, |
|
|
|
AssignTo: &app.mw, |
|
|
|
Title: app.title, |
|
|
|
Size: Size{Width: 500, Height: 360}, |
|
|
|
Font: Font{Family: "微软雅黑", PointSize: 9}, |
|
|
|
Icon: icon, |
|
|
|
Layout: VBox{}, |
|
|
|
MenuItems: []MenuItem{ |
|
|
|
Menu{ |
|
|
|
Text: "&编辑", |
|
|
|
// Image: "./image//media.png",
|
|
|
|
Items: []MenuItem{ |
|
|
|
Separator{}, |
|
|
|
Action{ |
|
|
|
// Image: "./image//qinghuancun.png",
|
|
|
|
Text: "清除缓存", |
|
|
|
OnTriggered: clearAll, |
|
|
|
}, |
|
|
|
Action{ |
|
|
|
// Image: "./image//beifen.png",
|
|
|
|
Text: "数据备份", |
|
|
|
OnTriggered: dbBak, |
|
|
|
}, |
|
|
|
Action{ |
|
|
|
// Image: "./image//huanyuan.png",
|
|
|
|
Text: "数据还原", |
|
|
|
OnTriggered: reDbBak, |
|
|
|
}, |
|
|
|
Action{ |
|
|
|
// Image: "./image//tuichu.png",
|
|
|
|
Text: "退出", |
|
|
|
OnTriggered: func() { |
|
|
|
walk.App().Exit(0) |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
Menu{ |
|
|
|
Text: "&设置", |
|
|
|
// Image: "./image//shezhi.png",
|
|
|
|
Items: []MenuItem{ |
|
|
|
Separator{}, |
|
|
|
Action{ |
|
|
|
// Image: "./image//shujuku.png",
|
|
|
|
Text: "设置数据库内存", |
|
|
|
OnTriggered: setDbSize, |
|
|
|
}, |
|
|
|
Action{ |
|
|
|
// Image: "./image//yingyong.png",
|
|
|
|
Text: "设置应用内存", |
|
|
|
OnTriggered: setServerSize, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
Menu{ |
|
|
|
Text: "&帮助", |
|
|
|
// Image: "./image//bangzhu.png",
|
|
|
|
Items: []MenuItem{ |
|
|
|
Action{ |
|
|
|
// Image: "./image//guanyu.png",
|
|
|
|
Text: "关于", |
|
|
|
OnTriggered: app.aboutactionTriggered, |
|
|
|
}, |
|
|
|
Action{ |
|
|
|
// Image: "./image//yaoqiu.png",
|
|
|
|
Text: "要求", |
|
|
|
OnTriggered: app.aboutactionTriggered, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
Children: []Widget{GroupBox{ |
|
|
|
Title: "基础服务状态", |
|
|
|
Layout: Grid{Columns: 3}, |
|
|
|
Children: []Widget{ |
|
|
|
Label{Text: service1.text, MinSize: Size{Width: 220, Height: 30}, TextColor: walk.RGB(255, 255, 0)}, |
|
|
|
Label{AssignTo: &service1.labelState, Text: "正在运行", MinSize: Size{Width: 80, Height: 30}}, |
|
|
|
Composite{ |
|
|
|
Layout: HBox{}, |
|
|
|
MaxSize: Size{Width: 198, Height: 30}, |
|
|
|
Children: []Widget{ |
|
|
|
PushButton{ |
|
|
|
AssignTo: &service1.btnRegister, |
|
|
|
MaxSize: Size{Width: 60, Height: 30}, |
|
|
|
Text: "注册表", |
|
|
|
}, |
|
|
|
PushButton{ |
|
|
|
AssignTo: &service1.btnStop, |
|
|
|
MaxSize: Size{Width: 60, Height: 30}, |
|
|
|
Text: "停止", |
|
|
|
}, |
|
|
|
PushButton{ |
|
|
|
AssignTo: &service1.btnStart, |
|
|
|
MaxSize: Size{Width: 60, Height: 30}, |
|
|
|
Text: "启动", |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, GroupBox{ |
|
|
|
Title: "业务服务状态", |
|
|
|
Layout: Grid{Columns: 3}, |
|
|
|
Children: []Widget{ |
|
|
|
Label{Text: service3.text, MinSize: Size{Width: 220, Height: 30}}, |
|
|
|
Label{AssignTo: &service3.labelState, Text: "正在运行", MinSize: Size{Width: 80, Height: 30}}, |
|
|
|
Composite{ |
|
|
|
Layout: HBox{}, |
|
|
|
MaxSize: Size{Width: 198, Height: 30}, |
|
|
|
Children: []Widget{ |
|
|
|
PushButton{ |
|
|
|
AssignTo: &service3.btnRegister, |
|
|
|
MaxSize: Size{Width: 60, Height: 30}, |
|
|
|
Text: "注册表", |
|
|
|
}, |
|
|
|
PushButton{ |
|
|
|
AssignTo: &service3.btnStop, |
|
|
|
MaxSize: Size{Width: 60, Height: 30}, |
|
|
|
Text: "停止", |
|
|
|
}, |
|
|
|
PushButton{ |
|
|
|
AssignTo: &service3.btnStart, |
|
|
|
MaxSize: Size{Width: 60, Height: 30}, |
|
|
|
Text: "启动", |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, TextEdit{AssignTo: &app.msg, VScroll: true, ReadOnly: true}, Composite{ |
|
|
|
Layout: HBox{}, |
|
|
|
Children: []Widget{ |
|
|
|
PushButton{ |
|
|
|
MinSize: Size{Width: 200, Height: 30}, |
|
|
|
Text: "打开windows服务管理程序", |
|
|
|
OnClicked: openServices, |
|
|
|
}, |
|
|
|
HSpacer{}, |
|
|
|
PushButton{ |
|
|
|
MinSize: Size{Width: 140, Height: 30}, |
|
|
|
Text: "关闭本监控窗口", |
|
|
|
OnClicked: func() { |
|
|
|
walk.App().Exit(0) |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}}, |
|
|
|
OnSizeChanged: func() { |
|
|
|
_ = app.mw.SetSize(walk.Size(Size{Width: 500, Height: 360})) |
|
|
|
}, |
|
|
|
}.Create() |
|
|
|
winLong := win.GetWindowLong(app.mw.Handle(), win.GWL_STYLE) |
|
|
|
// 不能调整窗口大小,禁用最大化按钮
|
|
|
|
win.SetWindowLong(app.mw.Handle(), win.GWL_STYLE, winLong & ^win.WS_SIZEBOX & ^win.WS_MAXIMIZEBOX & ^win.WS_SIZEBOX) |
|
|
|
// 设置窗体生成在屏幕的正中间,并处理高分屏的情况
|
|
|
|
// 窗体横坐标 = ( 屏幕宽度 - 窗体宽度 ) / 2
|
|
|
|
// 窗体纵坐标 = ( 屏幕高度 - 窗体高度 ) / 2
|
|
|
|
_ = app.mw.SetX((int(win.GetSystemMetrics(0)) - app.mw.Width()) / 2 / app.mw.DPI() * 96) |
|
|
|
_ = app.mw.SetY((int(win.GetSystemMetrics(1)) - app.mw.Height()) / 2 / app.mw.DPI() * 96) |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
// setServiceState 设置 服务状态描述和按钮状态
|
|
|
|
func setServiceState(service myService, msg string, btnStartStatus, btnStopStatus, btnRegisterStatus bool) { |
|
|
|
_ = service.labelState.SetText(msg) |
|
|
@ -158,7 +324,7 @@ func registerService(service myService) { |
|
|
|
`NT Authority\LocalService`, |
|
|
|
`GWY20_Tomcat`, |
|
|
|
fmt.Sprintf(`%s\tomcat8\bin\Tomcat8.exe //RS//GWY20_Tomcat`, path)) |
|
|
|
registerJava(service.serviceName, path) |
|
|
|
registerJava(service.serviceName, path, 128, 256, 512, 512) |
|
|
|
registerLog(service.serviceName, path) |
|
|
|
registerState(service.serviceName, |
|
|
|
`SOFTWARE\WOW6432Node\Apache Software Foundation\Procrun 2.0\GWY20_Tomcat\Parameters\Start`, |
|
|
@ -179,7 +345,7 @@ func startService(service myService) { |
|
|
|
} |
|
|
|
showMsg(service.serviceName + " 服务开始启动......") |
|
|
|
err = s.StartService() |
|
|
|
time.Sleep(40 * time.Second) |
|
|
|
time.Sleep(15 * time.Second) |
|
|
|
if err != nil { |
|
|
|
showMsg(service.serviceName + " 服务启动失败!") |
|
|
|
} else { |
|
|
@ -209,152 +375,6 @@ func showMsg(msg string) { |
|
|
|
app.msg.AppendText("\r\n") |
|
|
|
} |
|
|
|
|
|
|
|
// 初始始化窗体
|
|
|
|
func getWindows() error { |
|
|
|
icon, _ := walk.NewIconFromResourceId(3) |
|
|
|
err := MainWindow{ |
|
|
|
Visible: false, |
|
|
|
AssignTo: &app.mw, |
|
|
|
Title: app.title, |
|
|
|
Size: Size{Width: 500, Height: 360}, |
|
|
|
Font: Font{Family: "微软雅黑", PointSize: 9}, |
|
|
|
Icon: icon, |
|
|
|
Layout: VBox{}, |
|
|
|
MenuItems: []MenuItem{ |
|
|
|
Menu{ |
|
|
|
Text: "&编辑", |
|
|
|
Items: []MenuItem{ |
|
|
|
Separator{}, |
|
|
|
Action{ |
|
|
|
Text: "清除缓存", |
|
|
|
OnTriggered: clearAll, |
|
|
|
}, |
|
|
|
Action{ |
|
|
|
Text: "退出", |
|
|
|
OnTriggered: func() { |
|
|
|
walk.App().Exit(0) |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
Menu{ |
|
|
|
Text: "&设置", |
|
|
|
Items: []MenuItem{ |
|
|
|
Separator{}, |
|
|
|
Action{ |
|
|
|
Text: "设置数据库内存", |
|
|
|
OnTriggered: setDbSize, |
|
|
|
}, |
|
|
|
Action{ |
|
|
|
Text: "设置应用内存", |
|
|
|
OnTriggered: setServerSize, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
Menu{ |
|
|
|
Text: "&帮助", |
|
|
|
Items: []MenuItem{ |
|
|
|
Action{ |
|
|
|
Text: "关于", |
|
|
|
OnTriggered: app.aboutactionTriggered, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
Children: []Widget{ |
|
|
|
GroupBox{ |
|
|
|
Title: "基础服务状态", |
|
|
|
Layout: Grid{Columns: 3}, |
|
|
|
Children: []Widget{ |
|
|
|
Label{Text: service1.text, MinSize: Size{Width: 220, Height: 30}, TextColor: walk.RGB(255, 255, 0)}, |
|
|
|
Label{AssignTo: &service1.labelState, Text: "正在运行", MinSize: Size{Width: 80, Height: 30}}, |
|
|
|
Composite{ |
|
|
|
Layout: HBox{}, |
|
|
|
MaxSize: Size{Width: 198, Height: 30}, |
|
|
|
Children: []Widget{ |
|
|
|
PushButton{ |
|
|
|
AssignTo: &service1.btnRegister, |
|
|
|
MaxSize: Size{Width: 60, Height: 30}, |
|
|
|
Text: "注册表", |
|
|
|
}, |
|
|
|
PushButton{ |
|
|
|
AssignTo: &service1.btnStop, |
|
|
|
MaxSize: Size{Width: 60, Height: 30}, |
|
|
|
Text: "停止", |
|
|
|
}, |
|
|
|
PushButton{ |
|
|
|
AssignTo: &service1.btnStart, |
|
|
|
MaxSize: Size{Width: 60, Height: 30}, |
|
|
|
Text: "启动", |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
GroupBox{ |
|
|
|
Title: "业务服务状态", |
|
|
|
Layout: Grid{Columns: 3}, |
|
|
|
Children: []Widget{ |
|
|
|
Label{Text: service3.text, MinSize: Size{Width: 220, Height: 30}}, |
|
|
|
Label{AssignTo: &service3.labelState, Text: "正在运行", MinSize: Size{Width: 80, Height: 30}}, |
|
|
|
Composite{ |
|
|
|
Layout: HBox{}, |
|
|
|
MaxSize: Size{Width: 198, Height: 30}, |
|
|
|
Children: []Widget{ |
|
|
|
PushButton{ |
|
|
|
AssignTo: &service3.btnRegister, |
|
|
|
MaxSize: Size{Width: 60, Height: 30}, |
|
|
|
Text: "注册表", |
|
|
|
}, |
|
|
|
PushButton{ |
|
|
|
AssignTo: &service3.btnStop, |
|
|
|
MaxSize: Size{Width: 60, Height: 30}, |
|
|
|
Text: "停止", |
|
|
|
}, |
|
|
|
PushButton{ |
|
|
|
AssignTo: &service3.btnStart, |
|
|
|
MaxSize: Size{Width: 60, Height: 30}, |
|
|
|
Text: "启动", |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
TextEdit{AssignTo: &app.msg, VScroll: true, ReadOnly: true}, |
|
|
|
Composite{ |
|
|
|
Layout: HBox{}, |
|
|
|
Children: []Widget{ |
|
|
|
PushButton{ |
|
|
|
MinSize: Size{Width: 200, Height: 30}, |
|
|
|
Text: "打开windows服务管理程序", |
|
|
|
OnClicked: openServices, |
|
|
|
}, |
|
|
|
HSpacer{}, |
|
|
|
PushButton{ |
|
|
|
MinSize: Size{Width: 140, Height: 30}, |
|
|
|
Text: "关闭本监控窗口", |
|
|
|
OnClicked: func() { |
|
|
|
walk.App().Exit(0) |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
OnSizeChanged: func() { |
|
|
|
_ = app.mw.SetSize(walk.Size(Size{Width: 500, Height: 360})) |
|
|
|
}, |
|
|
|
}.Create() |
|
|
|
winLong := win.GetWindowLong(app.mw.Handle(), win.GWL_STYLE) |
|
|
|
// 不能调整窗口大小,禁用最大化按钮
|
|
|
|
win.SetWindowLong(app.mw.Handle(), win.GWL_STYLE, winLong & ^win.WS_SIZEBOX & ^win.WS_MAXIMIZEBOX & ^win.WS_SIZEBOX) |
|
|
|
// 设置窗体生成在屏幕的正中间,并处理高分屏的情况
|
|
|
|
// 窗体横坐标 = ( 屏幕宽度 - 窗体宽度 ) / 2
|
|
|
|
// 窗体纵坐标 = ( 屏幕高度 - 窗体高度 ) / 2
|
|
|
|
_ = app.mw.SetX((int(win.GetSystemMetrics(0)) - app.mw.Width()) / 2 / app.mw.DPI() * 96) |
|
|
|
_ = app.mw.SetY((int(win.GetSystemMetrics(1)) - app.mw.Height()) / 2 / app.mw.DPI() * 96) |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
/* 注册服务部分 */ |
|
|
|
// registerWindows 【1】修改注册表
|
|
|
|
func registerWindows(serviceName, regStr, objectName, displayName, imagePath string) { |
|
|
@ -382,7 +402,7 @@ func registerWindows(serviceName, regStr, objectName, displayName, imagePath str |
|
|
|
} |
|
|
|
|
|
|
|
// registerJava 【2】修改注册表
|
|
|
|
func registerJava(serviceName, path string) { |
|
|
|
func registerJava(serviceName, path string, permSize, maxPermSize, xms, xmx int) { |
|
|
|
key, exists, _ := registry.CreateKey(registry.LOCAL_MACHINE, `SOFTWARE\WOW6432Node\Apache Software Foundation\Procrun 2.0\GWY20_Tomcat\Parameters\Java`, registry.ALL_ACCESS) |
|
|
|
defer key.Close() |
|
|
|
|
|
|
@ -398,12 +418,12 @@ func registerJava(serviceName, path string) { |
|
|
|
`-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager`, |
|
|
|
fmt.Sprintf(`-Djava.util.logging.config.file=%s\tomcat8\conf\logging.properties`, path), |
|
|
|
`-Dfile.encoding=GBK`, |
|
|
|
`-XX:PermSize=128m`, |
|
|
|
`-XX:MaxPermSize=256m`, |
|
|
|
fmt.Sprintf(`-XX:PermSize=%dm`, permSize), |
|
|
|
fmt.Sprintf(`-XX:MaxPermSize=%dm`, maxPermSize), |
|
|
|
}) |
|
|
|
_ = key.SetStringValue(`Classpath`, fmt.Sprintf(`%s\tomcat8\bin\bootstrap.jar;%s\tomcat8\bin\tomcat-juli.jar`, path, path)) |
|
|
|
_ = key.SetDWordValue(`JvmMs`, uint32(512)) |
|
|
|
_ = key.SetDWordValue(`JvmMx`, uint32(512)) |
|
|
|
_ = key.SetDWordValue(`JvmMs`, uint32(xms)) |
|
|
|
_ = key.SetDWordValue(`JvmMx`, uint32(xmx)) |
|
|
|
} |
|
|
|
|
|
|
|
// registerLog 【3】修改注册表
|
|
|
@ -448,29 +468,31 @@ func Unzip(zipFile string, destDir string) error { |
|
|
|
if f.FileInfo().IsDir() { |
|
|
|
_ = os.MkdirAll(fpath, os.ModePerm) |
|
|
|
} else { |
|
|
|
if err = os.MkdirAll(filepath.Dir(fpath), os.ModePerm); err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
return runUnzip(fpath, f) |
|
|
|
} |
|
|
|
} |
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
inFile, err := f.Open() |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
defer inFile.Close() |
|
|
|
func runUnzip(fpath string, f *zip.File) error { |
|
|
|
if err := os.MkdirAll(filepath.Dir(fpath), os.ModePerm); err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
outFile, err := os.OpenFile(fpath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, f.Mode()) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
defer outFile.Close() |
|
|
|
inFile, err := f.Open() |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
defer inFile.Close() |
|
|
|
|
|
|
|
_, err = io.Copy(outFile, inFile) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
outFile, err := os.OpenFile(fpath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, f.Mode()) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
return nil |
|
|
|
defer outFile.Close() |
|
|
|
|
|
|
|
_, err = io.Copy(outFile, inFile) |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
// openServices 打开本地 服务
|
|
|
@ -509,21 +531,237 @@ func clearAll() { |
|
|
|
|
|
|
|
// setDbSize 显示设置数据库内存大小界面,等待保存
|
|
|
|
func setDbSize() { |
|
|
|
|
|
|
|
app.RunDbSetingDialog(app.mw, func(setings *DbSetings) { |
|
|
|
// 停服务
|
|
|
|
stopService(service1) |
|
|
|
// 设置修改参数
|
|
|
|
setDbIni(setings.InnodbBufferPoolSize) |
|
|
|
// 起服务
|
|
|
|
startService(service1) |
|
|
|
showMsg("数据库内存调整完毕!") |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
// doSetDbSize 设置数据库内存大小,重启MySQL服务
|
|
|
|
func doSetDbSize() { |
|
|
|
stopService(service1) |
|
|
|
func setDbIni(innodbBufferPoolSize int) { |
|
|
|
//读写方式打开文件
|
|
|
|
myIniFile := fmt.Sprintf(`%s/mysql/my.ini`, path) |
|
|
|
file, err := os.OpenFile(myIniFile, os.O_RDWR, 0666) |
|
|
|
if err != nil { |
|
|
|
showMsg("【异常】打开文件发生错误!" + myIniFile) |
|
|
|
log.Fatal("打开文件异常:", err) |
|
|
|
return |
|
|
|
} |
|
|
|
//defer关闭文件
|
|
|
|
defer file.Close() |
|
|
|
|
|
|
|
//读取文件内容到io中
|
|
|
|
reader := bufio.NewReader(file) |
|
|
|
pos := int64(0) |
|
|
|
innodbBufferPoolSizeStr := []byte(fmt.Sprintf(`innodb_buffer_pool_size=%dM`, innodbBufferPoolSize)) |
|
|
|
for { |
|
|
|
//读取每一行内容
|
|
|
|
line, err := reader.ReadString('\n') |
|
|
|
if err != nil { |
|
|
|
//读到末尾
|
|
|
|
if err == io.EOF { |
|
|
|
showMsg("打开读取文件完毕!") |
|
|
|
break |
|
|
|
} else { |
|
|
|
showMsg("【异常】读取文件发生错误:" + line) |
|
|
|
log.Fatal("读取文件异常:", err) |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//根据关键词覆盖当前行
|
|
|
|
if strings.Contains(line, "innodb_buffer_pool_size") { |
|
|
|
_, _ = file.WriteAt(innodbBufferPoolSizeStr, pos) |
|
|
|
} |
|
|
|
|
|
|
|
//每一行读取完后记录位置
|
|
|
|
pos += int64(len(line)) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// setServerSize 显示设置应用内存大小界面,等待保存
|
|
|
|
func setServerSize() { |
|
|
|
app.RunAppSetingDialog(app.mw, func(setings *AppSetings) { |
|
|
|
// 停服务
|
|
|
|
stopService(service3) |
|
|
|
// 设置数据库内存大小
|
|
|
|
//registerJava(service3.serviceName, path, 129, 259, 500, 500)
|
|
|
|
registerJava(service3.serviceName, path, setings.PermSize, setings.MaxPermSize, setings.Xms, setings.Xmx) |
|
|
|
// 起服务
|
|
|
|
startService(service3) |
|
|
|
showMsg("应用内存调整完毕!") |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
// dbBak 数据备份功能
|
|
|
|
func dbBak() { |
|
|
|
showMsg("【待完善】数据备份!") |
|
|
|
} |
|
|
|
|
|
|
|
// doSetServerSize 设置应用内存大小,重启应用服务
|
|
|
|
func doSetServerSize() { |
|
|
|
stopService(service3) |
|
|
|
// reDbBak 备份数据还原
|
|
|
|
func reDbBak() { |
|
|
|
showMsg("【待完善】备份数据还原!") |
|
|
|
} |
|
|
|
|
|
|
|
//数据库配置结构
|
|
|
|
type DbSetings struct { |
|
|
|
InnodbBufferPoolSize int // 数据库缓存大小
|
|
|
|
} |
|
|
|
|
|
|
|
// 运行 数据库设置 Dialog
|
|
|
|
func (mw *myApp) RunDbSetingDialog(owner walk.Form, confirmCall func(*DbSetings)) { |
|
|
|
var seting *DbSetings |
|
|
|
var dlg *walk.Dialog |
|
|
|
var db *walk.DataBinder |
|
|
|
var acceptPB, cancelPB *walk.PushButton |
|
|
|
|
|
|
|
seting = new(DbSetings) |
|
|
|
// 设置预定值
|
|
|
|
seting.InnodbBufferPoolSize = 512 |
|
|
|
|
|
|
|
_, _ = Dialog{ |
|
|
|
AssignTo: &dlg, |
|
|
|
Title: "数据源内存设置", |
|
|
|
Font: Font{Family: "微软雅黑", PointSize: 9}, |
|
|
|
DefaultButton: &acceptPB, |
|
|
|
CancelButton: &cancelPB, |
|
|
|
DataBinder: DataBinder{ |
|
|
|
AssignTo: &db, |
|
|
|
Name: "setings", |
|
|
|
DataSource: seting, |
|
|
|
ErrorPresenter: ToolTipErrorPresenter{}, |
|
|
|
}, |
|
|
|
MinSize: Size{Width: 450, Height: 220}, |
|
|
|
Layout: VBox{}, |
|
|
|
Children: []Widget{ |
|
|
|
Composite{ |
|
|
|
Layout: Grid{Columns: 2}, |
|
|
|
Children: []Widget{ |
|
|
|
Label{Text: ` 数据库内存:`}, |
|
|
|
NumberEdit{Value: Bind("InnodbBufferPoolSize", Range{Min: 64, Max: 10240}), Suffix: " M", Decimals: 0}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
Composite{ |
|
|
|
Layout: HBox{}, |
|
|
|
Children: []Widget{ |
|
|
|
HSpacer{}, |
|
|
|
PushButton{ |
|
|
|
AssignTo: &acceptPB, |
|
|
|
Text: "保存", |
|
|
|
OnClicked: func() { |
|
|
|
if err := db.Submit(); err != nil { |
|
|
|
showMsg("【异常】处理设置数据库内存时,发生异常!") |
|
|
|
log.Fatal(err) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
// 关闭页面
|
|
|
|
dlg.Cancel() |
|
|
|
|
|
|
|
// 应用 回调函数
|
|
|
|
confirmCall(seting) |
|
|
|
}, |
|
|
|
}, |
|
|
|
PushButton{ |
|
|
|
AssignTo: &cancelPB, |
|
|
|
Text: "取消", |
|
|
|
OnClicked: func() { |
|
|
|
dlg.Cancel() |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}.Run(owner) |
|
|
|
} |
|
|
|
|
|
|
|
//应用配置结构
|
|
|
|
type AppSetings struct { |
|
|
|
PermSize int // 非堆区初始内存分配大小
|
|
|
|
MaxPermSize int // 非堆区分配的内存的最大上限
|
|
|
|
Xms int // 堆区内存初始内存分配的大小
|
|
|
|
Xmx int // 堆区内存可被分配的最大上限
|
|
|
|
} |
|
|
|
|
|
|
|
// 运行 应用设置 Dialog
|
|
|
|
func (mw *myApp) RunAppSetingDialog(owner walk.Form, confirmCall func(*AppSetings)) { |
|
|
|
var seting *AppSetings |
|
|
|
var dlg *walk.Dialog |
|
|
|
var db *walk.DataBinder |
|
|
|
var acceptPB, cancelPB *walk.PushButton |
|
|
|
|
|
|
|
seting = new(AppSetings) |
|
|
|
// 设置预定值
|
|
|
|
seting.PermSize = 128 |
|
|
|
seting.MaxPermSize = 256 |
|
|
|
seting.Xmx = 512 |
|
|
|
seting.Xms = 512 |
|
|
|
|
|
|
|
_, _ = Dialog{ |
|
|
|
AssignTo: &dlg, |
|
|
|
Title: "应用内存设置", |
|
|
|
Font: Font{Family: "微软雅黑", PointSize: 9}, |
|
|
|
DefaultButton: &acceptPB, |
|
|
|
CancelButton: &cancelPB, |
|
|
|
DataBinder: DataBinder{ |
|
|
|
AssignTo: &db, |
|
|
|
Name: "setings", |
|
|
|
DataSource: seting, |
|
|
|
ErrorPresenter: ToolTipErrorPresenter{}, |
|
|
|
}, |
|
|
|
MinSize: Size{Width: 450, Height: 320}, |
|
|
|
Layout: VBox{}, |
|
|
|
Children: []Widget{ |
|
|
|
Composite{ |
|
|
|
Layout: Grid{Columns: 2}, |
|
|
|
Children: []Widget{ |
|
|
|
Label{Text: ` PermSize(非堆区)初始内存分配大小:`}, |
|
|
|
NumberEdit{Value: Bind("PermSize", Range{Min: 64, Max: 10240}), Suffix: " m", Decimals: 0}, |
|
|
|
|
|
|
|
Label{Text: `MaxPermSize(非堆区)最大内存分配上限:`}, |
|
|
|
NumberEdit{Value: Bind("MaxPermSize", Range{Min: 64, Max: 10240}), Suffix: " m", Decimals: 0}, |
|
|
|
|
|
|
|
Label{Text: ` Xms(堆区)初始内存分配大小:`}, |
|
|
|
NumberEdit{Value: Bind("Xms", Range{Min: 64, Max: 10240}), Suffix: " m", Decimals: 0}, |
|
|
|
|
|
|
|
Label{Text: ` Xmx(堆区)最大内存分配上限:`}, |
|
|
|
NumberEdit{Value: Bind("Xmx", Range{Min: 64, Max: 10240}), Suffix: " m", Decimals: 0}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
Composite{ |
|
|
|
Layout: HBox{}, |
|
|
|
Children: []Widget{ |
|
|
|
HSpacer{}, |
|
|
|
PushButton{ |
|
|
|
AssignTo: &acceptPB, |
|
|
|
Text: "保存", |
|
|
|
OnClicked: func() { |
|
|
|
if err := db.Submit(); err != nil { |
|
|
|
showMsg("【异常】处理设置数据库内存时,发生异常!") |
|
|
|
log.Fatal(err) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
// 关闭页面
|
|
|
|
dlg.Cancel() |
|
|
|
|
|
|
|
// DB 回调函数
|
|
|
|
confirmCall(seting) |
|
|
|
}, |
|
|
|
}, |
|
|
|
PushButton{ |
|
|
|
AssignTo: &cancelPB, |
|
|
|
Text: "取消", |
|
|
|
OnClicked: func() { |
|
|
|
dlg.Cancel() |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}.Run(owner) |
|
|
|
} |
|
|
|