Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Lei Li
agent
Commits
2ee5c9f8
Commit
2ee5c9f8
authored
Oct 18, 2024
by
Lei Li
Browse files
fix: 修改工作目錄路徑
parent
7584cff0
Changes
6
Hide whitespace changes
Inline
Side-by-side
cmd/agent/config/config.go
View file @
2ee5c9f8
...
...
@@ -3,8 +3,8 @@ package config
import
"time"
var
(
WorkDir
=
"/linkfog/agent/
"
RootDir
=
"
"
WorkDir
=
""
BackupDir
=
"backup"
PluginDir
=
"plugin"
LogDir
=
"log"
...
...
cmd/agent/core/agent.go
View file @
2ee5c9f8
...
...
@@ -33,6 +33,10 @@ type Agent struct {
func
(
a
*
Agent
)
Init
(
env
svc
.
Environment
)
error
{
option
.
Parse
()
if
option
.
Opt
.
PrintVersion
{
fmt
.
Println
(
genVersion
())
os
.
Exit
(
0
)
}
// 获取平台和内核版本
global
.
GetPlatformInfo
()
...
...
@@ -48,7 +52,7 @@ func (a *Agent) Init(env svc.Environment) error {
if
option
.
Opt
.
EnableMonitorDaemon
{
config
.
LogFileName
=
config
.
DaemonLogFileName
}
else
{
a
.
cmdline0
=
os
.
Args
[
0
]
a
.
cmdline0
=
filepath
.
Join
(
config
.
RootDir
,
filepath
.
Base
(
os
.
Args
[
0
]
))
}
// 日志设置
...
...
@@ -67,11 +71,6 @@ func (a *Agent) Init(env svc.Environment) error {
}
func
(
a
*
Agent
)
Start
()
error
{
if
option
.
Opt
.
PrintVersion
{
fmt
.
Println
(
genVersion
())
os
.
Exit
(
0
)
}
if
option
.
Opt
.
EnableMonitorDaemon
{
l
.
Info
(
"======start monitor_daemon======"
)
param
:=
fmt
.
Sprintf
(
"-%s=false"
,
option
.
ArgEnableMonitorDaemon
)
...
...
@@ -160,10 +159,6 @@ func initSvcCfg() error {
}
global
.
SubscribePrefixInfo
=
global
.
DeviceSerialNumber
+
"/publish/"
// NOTE: 自测使用
if
config
.
Edition
==
"dev"
{
config
.
WorkDir
=
option
.
Opt
.
WorkDir
}
// 时间修正
if
!
iTime
.
SynchronizeSystemTime
()
{
return
fmt
.
Errorf
(
"synchronization system time failed"
)
...
...
cmd/agent/core/chat_msg.go
View file @
2ee5c9f8
...
...
@@ -4,7 +4,6 @@ import (
"agent/pkg/file"
"os"
"path/filepath"
"strings"
"syscall"
"time"
...
...
@@ -51,22 +50,22 @@ func (a *Agent) chatMsgProcess(msg *global.Message) {
}
func
(
a
*
Agent
)
SelfUpgradeProcess
()
{
execFile
:=
a
.
cmdline0
[
strings
.
LastIndex
(
a
.
cmdline0
,
"/"
)
+
1
:
]
execFile
:=
filepath
.
Base
(
a
.
cmdline0
)
// 备份
err
:=
os
.
Rename
(
a
.
cmdline0
,
config
.
BackupDir
+
"/"
+
execFile
)
if
err
!=
nil
{
l
.
Error
(
err
)
return
}
// 下载
err
=
global
.
DownloadFile
(
option
.
Opt
.
DownloadURL
+
"/"
+
execFile
,
config
.
Work
Dir
,
execFile
)
// 下载
到xxx/agent
err
=
global
.
DownloadFile
(
option
.
Opt
.
DownloadURL
+
"/"
+
execFile
,
config
.
Root
Dir
,
execFile
)
if
err
!=
nil
{
l
.
Errorf
(
"download file err:%v"
,
err
)
return
}
// 增加执行权限
err
=
file
.
SetFileExecPerm
(
filepath
.
Join
(
config
.
Work
Dir
,
execFile
))
err
=
file
.
SetFileExecPerm
(
filepath
.
Join
(
config
.
Root
Dir
,
execFile
))
if
err
!=
nil
{
l
.
Error
(
err
)
}
...
...
cmd/agent/global/global.go
View file @
2ee5c9f8
package
global
import
(
"agent/cmd/agent/option"
"os"
"os/exec"
"os/user"
...
...
@@ -71,14 +72,24 @@ func SetWorkDir() error {
if
strings
.
Contains
(
runtime
.
GOARCH
,
"amd64"
)
||
strings
.
Contains
(
runtime
.
GOARCH
,
"arm64"
)
||
strings
.
Contains
(
runtime
.
GOARCH
,
"aarch64"
)
{
config
.
RootDir
=
"/linkfog/agent/"
config
.
WorkDir
=
"/linkfog/agent/"
}
else
if
strings
.
Contains
(
runtime
.
GOARCH
,
"android"
)
||
strings
.
Contains
(
runtime
.
GOARCH
,
"arm"
)
{
}
else
{
// GOARCH == "android"|| "arm" || xxx
dir
,
err
:=
filepath
.
Abs
(
filepath
.
Dir
(
os
.
Args
[
0
]))
if
err
==
nil
{
config
.
WorkDir
=
filepath
.
Join
(
strings
.
Replace
(
dir
,
"
\\
"
,
"/"
,
-
1
),
"lw_agent"
)
config
.
RootDir
=
strings
.
Replace
(
dir
,
"
\\
"
,
"/"
,
-
1
)
config
.
WorkDir
=
filepath
.
Join
(
config
.
RootDir
,
"lw_agent"
)
}
}
err
:=
os
.
MkdirAll
(
path
.
Join
(
config
.
WorkDir
),
0777
)
// NOTE: 自测使用
if
config
.
WorkDir
==
"/linkfog/agent/"
&&
config
.
Edition
==
"dev"
{
config
.
RootDir
=
option
.
Opt
.
RootDir
config
.
WorkDir
=
filepath
.
Join
(
config
.
RootDir
,
"lw_agent"
)
}
err
:=
os
.
MkdirAll
(
config
.
WorkDir
,
0777
)
if
err
!=
nil
{
return
err
}
...
...
cmd/agent/option/option.go
View file @
2ee5c9f8
...
...
@@ -44,7 +44,7 @@ type options struct {
MQTTBrokerURL
string
MQTTBrokerPort
int
DownloadURL
string
Work
Dir
string
Root
Dir
string
}
const
(
...
...
@@ -79,7 +79,7 @@ func flagSet() {
flag
.
StringVar
(
&
Opt
.
MQTTBrokerURL
,
"mqtt-url"
,
"tcp://broker.hivemq.com"
,
"MQTT broker url"
)
flag
.
IntVar
(
&
Opt
.
MQTTBrokerPort
,
"mqtt-port"
,
1883
,
"MQTT broker port"
)
flag
.
StringVar
(
&
Opt
.
DownloadURL
,
"download-url"
,
"http://fae-cdn.linkfog.cn/tmp"
,
"download url"
)
flag
.
StringVar
(
&
Opt
.
Work
Dir
,
"
work
-dir"
,
""
,
"
work
dir"
)
flag
.
StringVar
(
&
Opt
.
Root
Dir
,
"
root
-dir"
,
""
,
"
root
dir"
)
}
flag
.
BoolVar
(
&
Opt
.
Usage
,
ArgUsage
,
false
,
"custom format usage"
)
flag
.
BoolVar
(
&
Opt
.
PrintVersion
,
ArgVersion
,
false
,
"print version and exit"
)
...
...
module/backend/backend.go
View file @
2ee5c9f8
...
...
@@ -102,6 +102,7 @@ func (b *Backend) Start() error {
b
.
client
.
Publish
(
topic
,
1
,
false
,
[]
byte
(
msg
.
Payload
))
}
case
<-
b
.
signal
:
b
.
client
.
Disconnect
(
250
)
l
.
Info
(
"MQTT exit"
)
return
}
...
...
@@ -114,8 +115,6 @@ func (b *Backend) Stop() {
if
b
.
IsRunning
()
{
b
.
isRunning
=
false
b
.
signal
<-
struct
{}{}
b
.
client
.
Disconnect
(
250
)
}
}
...
...
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