Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
chain33-pai
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
szh
chain33-pai
Commits
492bf342
Commit
492bf342
authored
Apr 17, 2020
by
szh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
autossh 定期清理链接
parent
31b938c8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
92 additions
and
27 deletions
+92
-27
main.go
main.go
+4
-4
process.go
pkg/app/process.go
+88
-23
No files found.
main.go
View file @
492bf342
...
...
@@ -37,10 +37,10 @@ func main() {
gin
.
SetMode
(
setting
.
ServerSetting
.
RunMode
)
//区域网广播设备
go
broadcast
()
//
定时监控节点
go
app
.
CornProcess
Job
(
time
.
NewTicker
(
time
.
Second
*
30
))
//
定时自动更新树莓派内置程序
go
app
.
AutoUpdate
(
time
.
NewTicker
(
time
.
Second
*
50
))
//
节点操作
go
app
.
Bityuan
Job
(
time
.
NewTicker
(
time
.
Second
*
30
))
//
树莓派内置程序操作
go
app
.
PaiJob
(
time
.
NewTicker
(
time
.
Second
*
50
))
//go app.ClearLog(time.NewTicker(time.Hour*1))
//上传统计树莓派信息
...
...
pkg/app/process.go
View file @
492bf342
...
...
@@ -23,6 +23,7 @@ import (
"encoding/json"
"chain33-pai/pkg/chain33"
types2
"github.com/33cn/plugin/plugin/dapp/ticket/types"
"strconv"
)
var
tlog
=
log
.
New
(
"pkg"
,
"app"
)
...
...
@@ -138,7 +139,7 @@ func StrFilter(str []string,filter string)(res []string){
}
//corn job for collecting chain33 process info
func
CornProcess
Job
(
ticker
*
time
.
Ticker
){
func
Bityuan
Job
(
ticker
*
time
.
Ticker
){
NodeError
=
getWalletInfo
()
for
{
...
...
@@ -547,35 +548,99 @@ func GetWalletStatus() (*types.WalletStatus,error) {
return
p
.
GetWalletStatus
()
}
func
AutoUpdate
(
tick
*
time
.
Ticker
)
{
func
PaiJob
(
tick
*
time
.
Ticker
)
{
for
{
select
{
case
<-
tick
.
C
:
if
RebootP
{
//重启pai
err
:=
KillPai
()
if
err
!=
nil
{
tlog
.
Error
(
"kill pai"
,
"err"
,
err
)
}
else
{
err
:=
StartProcess
(
setting
.
Chain33Pai
.
Start
)
if
err
!=
nil
{
tlog
.
Error
(
"restart pai fail"
,
"err"
,
err
)
}
else
{
tlog
.
Info
(
"kill restart pai success "
)
}
}
AutoUpdate
()
AutoSSHClean
()
}
}
}
type
PaiProcessInfo
struct
{
Pid
int32
Stime
int64
Cmd
string
}
func
AutoSSHClean
()
error
{
pai
,
err
:=
getPaiProcessInfo
()
tlog
.
Info
(
"getPaiProcessInfo"
,
"pai"
,
*
pai
)
if
err
!=
nil
{
tlog
.
Error
(
"getPaiProcessInfo"
,
"err"
,
err
)
return
err
}
if
pai
.
Stime
>
0
&&
(
time
.
Now
()
.
Unix
()
-
pai
.
Stime
)
>
72
*
3600
&&
pai
.
Pid
>
0
{
err
:=
KillAutoSsh
(
pai
.
Pid
)
if
err
!=
nil
{
tlog
.
Error
(
"KillAutoSsh"
,
"err"
,
err
)
}
tlog
.
Info
(
"KillAutoSsh Success"
,
"pid"
,
pai
.
Pid
)
}
return
nil
}
func
KillAutoSsh
(
pid
int32
)
error
{
ps
:=
fmt
.
Sprintf
(
"%d"
,
pid
)
cmd
:=
exec
.
Command
(
"kill"
,
"-9"
,
ps
)
return
cmd
.
Run
()
}
func
getPaiProcessInfo
()
(
*
PaiProcessInfo
,
error
)
{
var
pai
PaiProcessInfo
var
buf
bytes
.
Buffer
cmd
:=
exec
.
Command
(
"bash"
,
"-c"
,
"ps -eo pid,lstart,cmd |grep autossh | grep -v grep"
)
cmd
.
Stdout
=
&
buf
err
:=
cmd
.
Run
()
if
err
!=
nil
{
tlog
.
Error
(
"getPaiProcessInfo"
,
"err"
,
err
)
return
nil
,
err
}
list
:=
strings
.
Split
(
buf
.
String
(),
" "
)
if
len
(
list
)
<
7
{
return
nil
,
errors
.
New
(
"ps return exception"
)
}
lstart
:=
list
[
1
]
+
" "
+
list
[
2
]
+
" "
+
list
[
3
]
+
" "
+
list
[
4
]
+
" "
+
list
[
5
]
location
,
_
:=
time
.
LoadLocation
(
"Local"
)
tt
,
err
:=
time
.
ParseInLocation
(
time
.
ANSIC
,
lstart
,
location
)
if
err
!=
nil
{
tlog
.
Error
(
"getPaiProcessInfo"
,
"err"
,
err
)
return
nil
,
err
}
start
:=
tt
.
Unix
()
p
,
_
:=
strconv
.
Atoi
(
list
[
0
])
pai
.
Pid
=
int32
(
p
)
pai
.
Stime
=
start
return
&
pai
,
nil
}
func
AutoUpdate
()
{
if
RebootP
{
//重启pai
err
:=
KillPai
()
if
err
!=
nil
{
tlog
.
Error
(
"kill pai"
,
"err"
,
err
)
}
else
{
err
:=
StartProcess
(
setting
.
Chain33Pai
.
Start
)
if
err
!=
nil
{
tlog
.
Error
(
"restart pai fail"
,
"err"
,
err
)
}
else
{
if
!
DPercent
.
Flag
{
//没有其他任务占用
DPercent
.
Flag
=
true
err
:=
AutoUpdatePai
()
if
err
!=
nil
{
tlog
.
Error
(
"autoupdatepai"
,
"err"
,
err
)
}
tlog
.
Info
(
"autoupdatepai"
,
"err"
,
GetVersion
())
DPercent
.
Flag
=
false
}
tlog
.
Info
(
"kill restart pai success "
)
}
}
}
else
{
if
!
DPercent
.
Flag
{
//没有其他任务占用
DPercent
.
Flag
=
true
err
:=
AutoUpdatePai
()
if
err
!=
nil
{
tlog
.
Error
(
"autoupdatepai"
,
"err"
,
err
)
}
tlog
.
Info
(
"autoupdatepai"
,
"err"
,
GetVersion
())
DPercent
.
Flag
=
false
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment