Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
易企天创
zendata
提交
1a37bebf
Z
zendata
项目概览
易企天创
/
zendata
10 个月 前同步成功
通知
17
Star
2
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Z
zendata
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
1a37bebf
编写于
1月 12, 2021
作者:
aaronchen2k2k
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
move upgrade function to zmanager
上级
b53923b6
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
2 addition
and
162 deletion
+2
-162
src/server/service/cron.go
src/server/service/cron.go
+0
-26
src/server/service/upgrade.go
src/server/service/upgrade.go
+0
-128
src/zd.go
src/zd.go
+2
-8
未找到文件。
src/server/service/cron.go
已删除
100644 → 0
浏览文件 @
b53923b6
package
serverService
import
(
"fmt"
serverUtils
"github.com/easysoft/zendata/src/server/utils"
serverConst
"github.com/easysoft/zendata/src/server/utils/const"
i118Utils
"github.com/easysoft/zendata/src/utils/i118"
)
type
CronService
struct
{
upgradeService
*
UpgradeService
}
func
NewCronService
(
upgradeService
*
UpgradeService
)
*
CronService
{
return
&
CronService
{
upgradeService
:
upgradeService
}
}
func
(
s
*
CronService
)
Init
()
{
serverUtils
.
AddTaskFuc
(
i118Utils
.
I118Prt
.
Sprintf
(
"check_update"
),
fmt
.
Sprintf
(
"@every %ds"
,
serverConst
.
CheckUpgradeInterval
),
func
()
{
s
.
upgradeService
.
CheckUpgrade
()
},
)
}
src/server/service/upgrade.go
已删除
100644 → 0
浏览文件 @
b53923b6
package
serverService
import
(
"errors"
"fmt"
serverUtils
"github.com/easysoft/zendata/src/server/utils"
serverConst
"github.com/easysoft/zendata/src/server/utils/const"
commonUtils
"github.com/easysoft/zendata/src/utils/common"
configUtils
"github.com/easysoft/zendata/src/utils/config"
constant
"github.com/easysoft/zendata/src/utils/const"
fileUtils
"github.com/easysoft/zendata/src/utils/file"
i118Utils
"github.com/easysoft/zendata/src/utils/i118"
logUtils
"github.com/easysoft/zendata/src/utils/log"
shellUtils
"github.com/easysoft/zendata/src/utils/shell"
"github.com/easysoft/zendata/src/utils/vari"
"github.com/fatih/color"
"github.com/inconshreveable/go-update"
"github.com/mholt/archiver/v3"
"os"
"strconv"
"strings"
)
type
UpgradeService
struct
{
}
func
NewUpgradeService
()
*
UpgradeService
{
return
&
UpgradeService
{}
}
func
(
s
*
UpgradeService
)
CheckUpgrade
()
{
pth
:=
vari
.
AgentLogDir
+
"version.txt"
serverUtils
.
Download
(
serverConst
.
AgentVersionURL
,
pth
)
content
:=
strings
.
TrimSpace
(
fileUtils
.
ReadFile
(
pth
))
version
,
_
:=
strconv
.
ParseFloat
(
content
,
64
)
if
vari
.
Config
.
Version
<
version
{
logUtils
.
PrintToWithColor
(
i118Utils
.
I118Prt
.
Sprintf
(
"find_new_ver"
,
content
),
color
.
FgCyan
)
versionStr
:=
fmt
.
Sprintf
(
"%.1f"
,
version
)
pass
,
err
:=
s
.
DownloadFile
(
versionStr
)
if
pass
&&
err
==
nil
{
s
.
RestartVersion
(
versionStr
)
}
}
else
{
logUtils
.
PrintToWithColor
(
i118Utils
.
I118Prt
.
Sprintf
(
"no_new_ver"
,
content
),
color
.
FgCyan
)
}
}
func
(
s
*
UpgradeService
)
DownloadFile
(
version
string
)
(
pass
bool
,
err
error
)
{
os
:=
commonUtils
.
GetOs
()
if
commonUtils
.
IsWin
()
{
os
=
fmt
.
Sprintf
(
"%s%d"
,
os
,
strconv
.
IntSize
)
}
url
:=
fmt
.
Sprintf
(
serverConst
.
AgentDownloadURL
,
version
,
os
)
dir
:=
vari
.
AgentLogDir
+
version
pth
:=
dir
+
".zip"
err
=
serverUtils
.
Download
(
url
,
pth
)
if
err
!=
nil
{
return
}
md5Url
:=
url
+
".md5"
md5Pth
:=
pth
+
".md5"
err
=
serverUtils
.
Download
(
md5Url
,
md5Pth
)
if
err
!=
nil
{
return
}
pass
=
s
.
checkMd5
(
pth
,
md5Pth
)
if
!
pass
{
msg
:=
i118Utils
.
I118Prt
.
Sprintf
(
"fail_md5_check"
,
pth
)
logUtils
.
PrintToWithColor
(
msg
,
color
.
FgCyan
)
err
=
errors
.
New
(
msg
)
return
}
fileUtils
.
RmDir
(
dir
)
fileUtils
.
MkDirIfNeeded
(
dir
)
err
=
archiver
.
Unarchive
(
pth
,
dir
)
if
err
!=
nil
{
logUtils
.
PrintToWithColor
(
i118Utils
.
I118Prt
.
Sprintf
(
"fail_unzip"
,
pth
),
color
.
FgCyan
)
return
}
return
}
func
(
s
*
UpgradeService
)
RestartVersion
(
version
string
)
(
err
error
)
{
currExePath
:=
vari
.
ExeDir
+
constant
.
AppName
bakExePath
:=
currExePath
+
"_bak"
newExePath
:=
vari
.
AgentLogDir
+
version
+
constant
.
PthSep
+
constant
.
AppName
+
constant
.
PthSep
+
constant
.
AppName
if
commonUtils
.
IsWin
()
{
currExePath
+=
".exe"
bakExePath
+=
".exe"
newExePath
+=
".exe"
}
logUtils
.
PrintTo
(
currExePath
)
rd
,
_
:=
os
.
Open
(
newExePath
)
err
=
update
.
Apply
(
rd
,
update
.
Options
{
OldSavePath
:
bakExePath
})
if
err
!=
nil
{
logUtils
.
PrintToWithColor
(
i118Utils
.
I118Prt
.
Sprintf
(
"fail_upgrade"
,
vari
.
Config
.
Version
,
version
,
err
.
Error
()),
color
.
FgRed
)
}
else
{
logUtils
.
PrintToWithColor
(
i118Utils
.
I118Prt
.
Sprintf
(
"success_upgrade"
,
vari
.
Config
.
Version
,
version
),
color
.
FgCyan
)
// update config file
vari
.
Config
.
Version
,
_
=
strconv
.
ParseFloat
(
version
,
64
)
configUtils
.
SaveConfig
(
vari
.
Config
)
// set update tag
fileUtils
.
WriteFile
(
vari
.
ExeDir
+
".upgraded"
,
"upgraded"
)
}
return
}
func
(
s
*
UpgradeService
)
checkMd5
(
filePth
,
md5Pth
string
)
(
pass
bool
)
{
expectVal
:=
fileUtils
.
ReadFile
(
md5Pth
)
actualVal
:=
shellUtils
.
ExeShellWithOutput
(
"md5sum "
+
filePth
+
" | awk '{print $1}'"
)[
0
]
return
strings
.
TrimSpace
(
actualVal
)
==
strings
.
TrimSpace
(
expectVal
)
}
src/zd.go
浏览文件 @
1a37bebf
...
...
@@ -302,7 +302,6 @@ type Server struct {
textService
*
serverService
.
TextService
excelService
*
serverService
.
ExcelService
configService
*
serverService
.
ConfigService
cronService
*
serverService
.
CronService
}
func
InitServer
()
(
err
error
)
{
...
...
@@ -340,13 +339,9 @@ func InitServer() (err error) {
referService
,
resService
)
previewService
:=
serverService
.
NewPreviewService
(
defRepo
,
fieldRepo
,
instancesRepo
)
upgradeService
:=
serverService
.
NewUpgradeService
()
cronService
:=
serverService
.
NewCronService
(
upgradeService
)
cronService
.
Init
()
server
:=
NewServer
(
config
,
defService
,
fieldService
,
sectionService
,
referService
,
rangesService
,
instancesService
,
textService
,
excelService
,
configService
,
resService
,
syncService
,
previewService
,
cronService
)
syncService
,
previewService
)
server
.
Run
()
return
...
...
@@ -590,7 +585,7 @@ func NewServer(config *serverConfig.Config, defService *serverService.DefService
instancesService
*
serverService
.
InstancesService
,
textService
*
serverService
.
TextService
,
excelService
*
serverService
.
ExcelService
,
configService
*
serverService
.
ConfigService
,
resService
*
serverService
.
ResService
,
syncService
*
serverService
.
SyncService
,
previewService
*
serverService
.
PreviewService
,
cronService
*
serverService
.
CronService
)
*
Server
{
previewService
*
serverService
.
PreviewService
)
*
Server
{
return
&
Server
{
config
:
config
,
defService
:
defService
,
...
...
@@ -605,7 +600,6 @@ func NewServer(config *serverConfig.Config, defService *serverService.DefService
resService
:
resService
,
syncService
:
syncService
,
previewService
:
previewService
,
cronService
:
cronService
,
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录