mirror of
https://github.com/hanzozt/zt.git
synced 2026-11-02 11:38:22 +00:00
- Repo names: ziti-* → zt-* - Go modules: github.com/hanzozt/ziti → github.com/hanzozt/zt - Docker images: hanzozt/ziti-* → hanzozt/zt-* - C/Java/JS symbols: ziti_* → zt_* - File and directory names updated
85 lines
2.4 KiB
Go
85 lines
2.4 KiB
Go
/*
|
|
Copyright 2020 NetFoundry Inc.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
https://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package ztlib_runlevel_5_operation
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/hanzozt/fablab/kernel/libssh"
|
|
"github.com/hanzozt/fablab/kernel/model"
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
func Loop3Dialer(host *model.Host, scenario, endpoint string, joiner chan struct{}, extraArgs ...string) model.Stage {
|
|
return &loopDialer{
|
|
host: host,
|
|
scenario: scenario,
|
|
endpoint: endpoint,
|
|
joiner: joiner,
|
|
subcmd: "loop3",
|
|
extraArgs: extraArgs,
|
|
}
|
|
}
|
|
|
|
func LoopDialer(host *model.Host, scenario, endpoint string, joiner chan struct{}, extraArgs ...string) model.Stage {
|
|
return &loopDialer{
|
|
host: host,
|
|
scenario: scenario,
|
|
endpoint: endpoint,
|
|
joiner: joiner,
|
|
subcmd: "loop2",
|
|
extraArgs: extraArgs,
|
|
}
|
|
}
|
|
|
|
func (self *loopDialer) Execute(run model.Run) error {
|
|
ssh := self.host.NewSshConfigFactory()
|
|
if err := libssh.RemoteKill(ssh, fmt.Sprintf("zt-fabric-test %v dialer", self.subcmd)); err != nil {
|
|
return fmt.Errorf("error killing %v listeners (%w)", self.subcmd, err)
|
|
}
|
|
|
|
go self.run(run)
|
|
return nil
|
|
}
|
|
|
|
func (self *loopDialer) run(ctx model.Run) {
|
|
defer func() {
|
|
if self.joiner != nil {
|
|
close(self.joiner)
|
|
logrus.Debugf("closed joiner")
|
|
}
|
|
}()
|
|
|
|
ssh := self.host.NewSshConfigFactory()
|
|
logFile := fmt.Sprintf("/home/%s/logs/%v-dialer-%s.log", ssh.User(), self.subcmd, ctx.GetId())
|
|
dialerCmd := fmt.Sprintf("/home/%s/fablab/bin/zt-fabric-test %v dialer /home/%s/fablab/cfg/%s -e %s -s %s %s >> %s 2>&1",
|
|
ssh.User(), self.subcmd, ssh.User(), self.scenario, self.endpoint, self.host.GetId(), strings.Join(self.extraArgs, " "), logFile)
|
|
if output, err := libssh.RemoteExec(ssh, dialerCmd); err != nil {
|
|
logrus.Errorf("error starting loop dialer [%s] (%v)", output, err)
|
|
}
|
|
}
|
|
|
|
type loopDialer struct {
|
|
host *model.Host
|
|
endpoint string
|
|
scenario string
|
|
joiner chan struct{}
|
|
subcmd string
|
|
extraArgs []string
|
|
}
|