Skip to content

Commit

Permalink
simplify -update URL format
Browse files Browse the repository at this point in the history
  • Loading branch information
Bai-Yingjie committed Aug 17, 2023
1 parent fcb15ed commit ffa76d2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
10 changes: 5 additions & 5 deletions daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,8 +575,8 @@ var daemonKnownMsgs = []as.KnownMessage{
}

type updater struct {
urlFmt string
lg *log.Logger
url string
lg *log.Logger
}

type gshellBin struct {
Expand All @@ -594,7 +594,7 @@ func (msg tryUpdate) Handle(stream as.ContextStream) (reply interface{}) {
updtr := stream.GetContext().(*updater)
updtr.lg.Debugf("tryUpdate: %v", msg)

rev, err := httpOp.readFile(fmt.Sprintf(updtr.urlFmt, "rev"))
rev, err := httpOp.readFile(updtr.url + "/rev")
if err != nil {
return err
}
Expand All @@ -610,7 +610,7 @@ func (msg tryUpdate) Handle(stream as.ContextStream) (reply interface{}) {
return ErrNoUpdate
}

checksum, err := httpOp.readFile(fmt.Sprintf(updtr.urlFmt, "md5sum"))
checksum, err := httpOp.readFile(updtr.url + "/md5sum")
if err != nil {
return err
}
Expand All @@ -631,7 +631,7 @@ func (msg tryUpdate) Handle(stream as.ContextStream) (reply interface{}) {
return fmt.Errorf("arch %s not supported", msg.arch)
}

bin, err := httpOp.readFile(fmt.Sprintf(updtr.urlFmt, "gshell."+msg.arch))
bin, err := httpOp.readFile(updtr.url + "/gshell." + msg.arch)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions docs/daemon.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ chown -R nobody:nogroup . && chmod ugo+s bin/gshell
exit

# start gshell daemon at log level info
bin/gshell -loglevel info daemon -wd rootregistry -registry Your_Server_IP:11985 -bcast 9923 -root -repo github.com/godevsig/grepo/master -update http://10.10.10.10:8088/gshell/release/latest/%s &
bin/gshell -loglevel info daemon -wd rootregistry -registry Your_Server_IP:11985 -bcast 9923 -root -repo github.com/godevsig/grepo/master -update http://10.10.10.10:8088/gshell/release/latest/ &

# after gshell daemon started, check code repo contents
bin/gshell repo ls
Expand Down Expand Up @@ -186,15 +186,15 @@ For example, to autoupdate gshell binary from official github repo, here we don'
we just use github download page:

```
bin/gshell -loglevel info daemon -wd rootregistry -registry 10.10.10.10:11985 -bcast 9923 -root -repo github.com/godevsig/grepo/master -update https://github.com/godevsig/gshellos/releases/latest/download/%s &
bin/gshell -loglevel info daemon -wd rootregistry -registry 10.10.10.10:11985 -bcast 9923 -root -repo github.com/godevsig/grepo/master -update https://github.com/godevsig/gshellos/releases/latest/download/ &
```

Another example is autoupdating from private http file server:

```shell
cd /path/to/gshell
# start root gshell daemon
bin/gshell -loglevel info daemon -wd rootregistry -registry 10.10.10.10:11985 -bcast 9923 -root -repo github.com/godevsig/grepo/master -update http://10.10.10.10:8088/gshell/release/latest/%s &
bin/gshell -loglevel info daemon -wd rootregistry -registry 10.10.10.10:11985 -bcast 9923 -root -repo github.com/godevsig/grepo/master -update http://10.10.10.10:8088/gshell/release/latest/ &
# start file server on the same node(10.10.10.10) of root gshell daemon
bin/gshell run util/fileserver/cmd/fileserver.go -dir /path/contains/gshell/release
```
Expand Down
2 changes: 1 addition & 1 deletion gshell_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ func TestMain(m *testing.M) {
cmdstr := "-test.run ^TestRunMain$ -test.coverprofile=.test/l2_gshelld" + randID() + ".cov -- "
cmdstr += "-loglevel debug daemon -wd .working -registry 127.0.0.1:11985 -bcast 9923 "
cmdstr += "-root -repo . "
cmdstr += "-update http://127.0.0.1:9001/%s"
cmdstr += "-update http://127.0.0.1:9001"
go func() {
output, _ := exec.Command("gshell.tester", strings.Split(cmdstr, " ")...).CombinedOutput()
fmt.Println(string(output))
Expand Down
17 changes: 10 additions & 7 deletions gshellbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,25 +140,27 @@ func addDaemonCmd() {
if len(*lanBroadcastPort) == 0 {
scope &= ^as.ScopeLAN // not ScopeLAN
}
if len(*updateURL) != 0 || *rootRegistry {
updateURL := *updateURL
if len(updateURL) != 0 || *rootRegistry {
if scope&as.ScopeWAN != as.ScopeWAN {
return errors.New("root registry address not set")
}
}

codeRepo := *codeRepo
crs := &codeRepoSvc{}
if len(*codeRepo) != 0 {
fi, err := os.Stat(*codeRepo)
if len(codeRepo) != 0 {
fi, err := os.Stat(codeRepo)
if err != nil || !fi.Mode().IsDir() {
crs.httpRepoInfo = strings.Split(*codeRepo, "/")
crs.httpRepoInfo = strings.Split(codeRepo, "/")
if len(crs.httpRepoInfo) != 4 {
return errors.New("wrong repo format")
}
if httpOp == nil {
return errors.New("http feature not enabled, check build tags")
}
} else {
crs.localRepoPath, _ = filepath.Abs(*codeRepo)
crs.localRepoPath, _ = filepath.Abs(codeRepo)
}
}

Expand Down Expand Up @@ -202,11 +204,12 @@ func addDaemonCmd() {
s.EnableRootRegistry()
s.EnableIPObserver()

if len(*updateURL) != 0 {
if len(updateURL) != 0 {
if httpOp == nil {
return errors.New("http feature not enabled, check build tags")
}
updtr := &updater{urlFmt: *updateURL, lg: lg}
updateURL = strings.TrimSuffix(updateURL, "/")
updtr := &updater{url: updateURL, lg: lg}
if err := s.Publish("updater",
updaterKnownMsgs,
as.OnNewStreamFunc(func(ctx as.Context) { ctx.SetContext(updtr) }),
Expand Down

0 comments on commit ffa76d2

Please sign in to comment.