Skip to content

Commit

Permalink
Merge pull request #15 from zhangwenqiangnb/dev
Browse files Browse the repository at this point in the history
Completed automatic updates and daemons
  • Loading branch information
mmchougule authored Jun 12, 2024
2 parents fa7053e + a08c817 commit e699123
Show file tree
Hide file tree
Showing 50 changed files with 3,880 additions and 309 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/buildcicd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go

name: Go

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.20'
- name: Get dependencies
run: go get

- name: Build
run: |
make build-linux
- name: version
run: |
cd vimana-linux-amd64/
./vimana version
./vimana registry list
./vimana registry search
- name: celestia run
run: |
cd vimana-linux-amd64/
./vimana install celestia light-node
sleep 10s
./vimana stop celestia light-node
./vimana start celestia light-node
./vimana status celestia light-node
./vimana stop celestia light-node
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
avail_path
__MACOSX
vimana*
.DS_Store
.DS_Store
.vscode
4 changes: 2 additions & 2 deletions CREATE_COMPONENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ e.g.
[components.dymension]
[components.dymension.full]
binary = "/tmp/vimana/dymension/dymd"
binary = "/usr/local/bin/dymension/dymd"
download = "/tmp/vimana/dymension/init.sh"
```

Expand All @@ -39,7 +39,7 @@ func (c *DymensionFullCommander) Init(cmd *cobra.Command, args []string, mode Mo
func (c *DymensionFullCommander) Run(cmd *cobra.Command, args []string, mode Mode) {
c.Init(cmd, args, mode)
cmdexecute := c.componentMgr.GetStartCmd()
utils.ExecBashCmd(cmdexecute, utils.WithOutputToStdout(), utils.WithErrorsToStderr())
utils.ExecBinaryCmd(cmdexecute, utils.WithOutputToStdout(), utils.WithErrorsToStderr())
}
```

Expand Down
110 changes: 90 additions & 20 deletions cli/avail.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
package cli

import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"strconv"
"strings"
"vimana/cmd/utils"
"vimana/log"

// "github.com/moby/moby/daemon/logger"
"github.com/spf13/cobra"
)

type AvailLightCommander struct {
BaseCommander
}

func NewAvailLightCommander() *AvailLightCommander {
func NewAvailLightCommander(node_type string) *AvailLightCommander {
return &AvailLightCommander{
BaseCommander: BaseCommander{NodeType: "light"},
}
Expand All @@ -21,30 +26,95 @@ func NewAvailLightCommander() *AvailLightCommander {
func (a *AvailLightCommander) AddFlags(cmd *cobra.Command) {
}

func (a *AvailLightCommander) Init(cmd *cobra.Command, args []string, mode Mode) error {
utils.ExecBashCmd(exec.Command("bash", mode.Download), utils.WithOutputToStdout(), utils.WithErrorsToStderr())
a.initComponentManager("avail", mode.Binary)
return a.componentMgr.InitializeConfig()
func (a *AvailLightCommander) Init(cmd *cobra.Command, args []string, mode Mode, node_info string) error {
utils.ExecBashCmd(exec.Command("bash", mode.Download), node_info, utils.WithOutputToStdout(), utils.WithErrorsToStderr())
a.initSpacecoreManager("avail", mode.Binary)
return a.spacecoresMgr.InitializeConfig()
}

func (a *AvailLightCommander) Run(cmd *cobra.Command, args []string, mode Mode) {
cmdexecute := a.componentMgr.GetStartCmd()
utils.ExecBashCmd(cmdexecute, utils.WithOutputToStdout(), utils.WithErrorsToStderr())
func (a *AvailLightCommander) Run(cmd *cobra.Command, args []string, mode Mode, node_info string) {
cmdexecute := a.spacecoresMgr.GetStartCmd()
utils.ExecBinaryCmd(cmdexecute, node_info, utils.WithOutputToStdout(), utils.WithErrorsToStderr())
}

func (a *AvailLightCommander) Start(cmd *cobra.Command, args []string, mode Mode) {
a.Init(cmd, args, mode)
fmt.Println(a.componentMgr)
fmt.Println("executing start command")
cmdexecute := a.componentMgr.GetStartCmd()
fmt.Println(cmdexecute)
utils.ExecBashCmd(cmdexecute, utils.WithOutputToStdout(), utils.WithErrorsToStderr())
func (a *AvailLightCommander) Start(cmd *cobra.Command, args []string, mode Mode, node_info string) {
logger := log.GetLogger(cmd.Context())
// check if daemon already running.
PIDFile := utils.GetPIDFileName(node_info)
if _, err := os.Stat(PIDFile); err == nil {
logger.Info("Already running or " + PIDFile + " file exist.")
return
}

node_info_arr := strings.Split(node_info, "-")
a.Init(cmd, args, mode, node_info_arr[0])
logger.Info(a.spacecoresMgr)
logger.Info("executing start command")
cmdexecute := a.spacecoresMgr.GetStartCmd()
logger.Info(cmdexecute)
utils.ExecBashCmd(cmdexecute, node_info, utils.WithOutputToStdout(), utils.WithErrorsToStderr())
}

func (a *AvailLightCommander) Stop(cmd *cobra.Command, args []string, mode Mode) {
fmt.Println("Stopping Celestia bridge node")
func (a *AvailLightCommander) Stop(cmd *cobra.Command, args []string, mode Mode, node_info string) {
logger := log.GetLogger(cmd.Context())
logger.Info("Stopping Celestia bridge node")

PIDFile := utils.GetPIDFileName(node_info)
if _, err := os.Stat(PIDFile); err == nil {
data, err := ioutil.ReadFile(PIDFile)
if err != nil {
logger.Info("Not running")
return
}
ProcessID, err := strconv.Atoi(string(data))

if err != nil {
logger.Info("Unable to read and parse process id found in ", PIDFile)
return
}

process, err := os.FindProcess(ProcessID)

if err != nil {
logger.Infof("Unable to find process ID [%v] with error %v \n", ProcessID, err)
return
}
// remove PID file
os.Remove(PIDFile)

node_info_arr := strings.Split(node_info, "-")
logger.Info("Stopping " + node_info_arr[0] + " " + node_info_arr[1] + " node")
// kill process and exit immediately
err = process.Kill()

if err != nil {
logger.Infof("Unable to kill process ID [%v] with error %v \n", ProcessID, err)
} else {
logger.Infof("Killed process ID [%v]\n", ProcessID)
}
} else {
logger.Info("Not running.")
}
}

func (a *AvailLightCommander) Status(cmd *cobra.Command, args []string, mode Mode, node_info string) {
logger := log.GetLogger(cmd.Context())
node_info_arr := strings.Split(node_info, "-")
logger.Info("Getting status of " + node_info_arr[0] + " " + node_info_arr[1] + " node")

PIDFile := utils.GetPIDFileName(node_info)
if _, err := os.Stat(PIDFile); err == nil {
_, err := ioutil.ReadFile(PIDFile)
if err != nil {
logger.Info("Not running")
} else {
logger.Info(node_info_arr[0] + " " + node_info_arr[1] + " node is running")
}
} else {
logger.Info("Not running.")
}
}

func (a *AvailLightCommander) Status(cmd *cobra.Command, args []string, mode Mode) {
fmt.Println("Getting status of Celestia bridge node")
func (a *AvailLightCommander) Install(cmd *cobra.Command, args []string, mode Mode, node_info string) {
return
}
Loading

0 comments on commit e699123

Please sign in to comment.