Skip to content

Commit

Permalink
1.add http deployment method
Browse files Browse the repository at this point in the history
Signed-off-by: liuminjian <[email protected]>
  • Loading branch information
liuminjian committed Nov 29, 2023
1 parent 580b26d commit 281ba47
Show file tree
Hide file tree
Showing 78 changed files with 1,172 additions and 185 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ GO := go

# output
OUTPUT := bin/curveadm
SERVER_OUTPUT := bin/pigeon

# build flags
LDFLAGS := -s -w
Expand Down Expand Up @@ -52,12 +53,14 @@ TEST_FLAGS += -run $(CASE)

# packages
PACKAGES := $(PWD)/cmd/curveadm/main.go
SERVER_PACKAGES := $(PWD)/cmd/service/main.go

# tar
VERSION := "unknown"

build:
$(GOENV) $(GO) build -o $(OUTPUT) $(BUILD_FLAGS) $(PACKAGES)
$(GO) build -o $(SERVER_OUTPUT) $(SERVER_PACKAGES)

debug:
$(GOENV) $(GO) build -o $(OUTPUT) $(DEBUG_FLAGS) $(PACKAGES)
Expand Down
2 changes: 2 additions & 0 deletions cli/command/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ package command

import (
"fmt"
"github.com/opencurve/curveadm/cli/command/daemon"

"github.com/opencurve/curveadm/cli/cli"
"github.com/opencurve/curveadm/cli/command/client"
Expand Down Expand Up @@ -66,6 +67,7 @@ func addSubCommands(cmd *cobra.Command, curveadm *cli.CurveAdm) {
target.NewTargetCommand(curveadm), // curveadm target ...
pfs.NewPFSCommand(curveadm), // curveadm pfs ...
monitor.NewMonitorCommand(curveadm), // curveadm monitor ...
daemon.NewDaemonCommand(curveadm), // curveadm http

NewAuditCommand(curveadm), // curveadm audit
NewCleanCommand(curveadm), // curveadm clean
Expand Down
44 changes: 44 additions & 0 deletions cli/command/daemon/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (c) 2023 NetEase 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
*
* http://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.
*/

/*
* Project: Curveadm
* Created Date: 2023-03-31
* Author: wanghai (SeanHai)
*/

package daemon

import (
"github.com/opencurve/curveadm/cli/cli"
cliutil "github.com/opencurve/curveadm/internal/utils"
"github.com/spf13/cobra"
)

func NewDaemonCommand(curveadm *cli.CurveAdm) *cobra.Command {
cmd := &cobra.Command{
Use: "daemon",
Short: "Manage http service",
Args: cliutil.NoArgs,
RunE: cliutil.ShowHelp(curveadm.Err()),
}

cmd.AddCommand(
NewStartCommand(curveadm),
NewStopCommand(curveadm),
)
return cmd
}
61 changes: 61 additions & 0 deletions cli/command/daemon/start.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2023 NetEase 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
*
* http://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.
*/

/*
* Project: Curveadm
* Created Date: 2023-03-31
* Author: wanghai (SeanHai)
*/

package daemon

import (
"fmt"
"os/exec"
"path"

"github.com/opencurve/curveadm/cli/cli"
"github.com/spf13/cobra"
)

const (
START_EXAMPLR = `Examples:
$ curveadm daemon start # Start an http service to receive requests`
EXEC_PATH = "http/pigeon"
)

func NewStartCommand(curveadm *cli.CurveAdm) *cobra.Command {
cmd := &cobra.Command{
Use: "start [OPTIONS]",
Short: "Start http service",
Example: START_EXAMPLR,
RunE: func(cmd *cobra.Command, args []string) error {
return runStart(curveadm)
},
DisableFlagsInUseLine: true,
}
return cmd
}

func runStart(curveadm *cli.CurveAdm) error {
path := path.Join(curveadm.RootDir(), EXEC_PATH)
cmd := exec.Command(path, "start")
output, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("%s", output)
}
return nil
}
62 changes: 62 additions & 0 deletions cli/command/daemon/stop.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright (c) 2023 NetEase 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
*
* http://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.
*/

/*
* Project: Curveadm
* Created Date: 2023-03-31
* Author: wanghai (SeanHai)
*/

package daemon

import (
"fmt"
"os/exec"
"path"

"github.com/opencurve/curveadm/cli/cli"
cliutil "github.com/opencurve/curveadm/internal/utils"
"github.com/spf13/cobra"
)

const (
STOP_EXAMPLR = `Examples:
$ curveadm daemon stop # Stop an http service`
)

func NewStopCommand(curveadm *cli.CurveAdm) *cobra.Command {
cmd := &cobra.Command{
Use: "stop",
Short: "Stop http service",
Args: cliutil.NoArgs,
Example: STOP_EXAMPLR,
RunE: func(cmd *cobra.Command, args []string) error {
return runStop(curveadm)
},
DisableFlagsInUseLine: true,
}
return cmd
}

func runStop(curveadm *cli.CurveAdm) error {
path := path.Join(curveadm.RootDir(), EXEC_PATH)
cmd := exec.Command(path, "stop")
output, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("%s", output)
}
return nil
}
27 changes: 27 additions & 0 deletions cmd/service/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (c) 2023 NetEase 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
*
* http://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 main

import (
"github.com/opencurve/curveadm/internal/daemon"
"github.com/opencurve/pigeon"
)

func main() {
admServer := daemon.NewServer()
pigeon.Serve(admServer)
}
54 changes: 48 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ require (
github.com/jpillora/longestcommon v0.0.0-20161227235612-adb9d91ee629
github.com/kpango/glg v1.6.14
github.com/mattn/go-sqlite3 v1.14.16
github.com/mcuadros/go-defaults v1.2.0
github.com/melbahja/goph v1.3.0
github.com/mitchellh/hashstructure/v2 v2.0.2
github.com/moby/term v0.0.0-20221205130635-1aeaba878587
github.com/opencurve/pigeon v0.0.0-20230512031044-d5a430bb02a4
github.com/pingcap/log v1.1.0
github.com/sergi/go-diff v1.2.0
github.com/spf13/cobra v1.7.0
Expand All @@ -25,10 +27,47 @@ require (
golang.org/x/crypto v0.8.0
)

require (
github.com/Wine93/grace v0.0.0-20221021033009-7d0348013a3c // indirect
github.com/bytedance/sonic v1.8.7 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/facebookgo/clock v0.0.0-20150410010913-600d898af40a // indirect
github.com/facebookgo/grace v0.0.0-20180706040059-75cf19382434 // indirect
github.com/facebookgo/httpdown v0.0.0-20180706035922-5979d39b15c2 // indirect
github.com/facebookgo/stats v0.0.0-20151006221625-1b76add642e4 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/gin-gonic/gin v1.9.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.12.0 // indirect
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/google/pprof v0.0.0-20230406165453-00490a63f317 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/imroc/req/v3 v3.33.2 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 // indirect
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
github.com/leodido/go-urn v1.2.3 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/onsi/ginkgo/v2 v2.9.2 // indirect
github.com/quic-go/qpack v0.4.0 // indirect
github.com/quic-go/qtls-go1-18 v0.2.0 // indirect
github.com/quic-go/qtls-go1-19 v0.3.2 // indirect
github.com/quic-go/qtls-go1-20 v0.2.2 // indirect
github.com/quic-go/quic-go v0.33.0 // indirect
github.com/sevlyar/go-daemon v0.1.6 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
golang.org/x/arch v0.3.0 // indirect
golang.org/x/exp v0.0.0-20230321023759-10a507213a29 // indirect
)

require (
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/Shopify/logrus-bugsnag v0.0.0-20171204204709-577dee27f20d // indirect
github.com/VividCortex/ewma v1.2.0 // indirect
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d // indirect
github.com/benbjohnson/clock v1.3.0 // indirect
Expand Down Expand Up @@ -81,18 +120,21 @@ require (
github.com/subosito/gotenv v1.4.2 // indirect
github.com/theupdateframework/notary v0.7.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
golang.org/x/mod v0.9.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/mod v0.10.0 // indirect
golang.org/x/net v0.9.0 // indirect
golang.org/x/sys v0.7.0 // indirect
golang.org/x/term v0.7.0 // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/tools v0.7.0 // indirect
google.golang.org/protobuf v1.29.1 // indirect
golang.org/x/tools v0.8.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gotest.tools/v3 v3.0.3 // indirect
)

replace github.com/melbahja/goph v1.3.0 => github.com/Wine93/goph v0.0.0-20220907033045-3b286d827fb3

replace github.com/quic-go/quic-go => github.com/quic-go/quic-go v0.32.0

replace go.uber.org/multierr => go.uber.org/multierr v1.8.0
Loading

0 comments on commit 281ba47

Please sign in to comment.