Skip to content
This repository has been archived by the owner on Jan 23, 2019. It is now read-only.

Commit

Permalink
Add run & version sub-commands (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
tamalsaha authored May 29, 2017
1 parent a9c603a commit 96d8ac3
Show file tree
Hide file tree
Showing 21 changed files with 769 additions and 1,241 deletions.
37 changes: 21 additions & 16 deletions cmd/gearmand/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,35 @@
package main

import (
_ "net/http/pprof"
"flag"
"log"
"os"

gearmand "github.com/appscode/g2/pkg/server"
"github.com/appscode/go/flags"
"github.com/appscode/go/runtime"
"github.com/appscode/go/version"
logs "github.com/appscode/log/golog"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)

func main() {
cfg := &gearmand.Config{}

pflag.StringVar(&cfg.ListenAddr, "addr", ":4730", "listening on, such as 0.0.0.0:4730")
pflag.StringVar(&cfg.Storage, "storage-dir", os.TempDir()+"/gearmand", "Directory where LevelDB file is stored.")
pflag.StringVar(&cfg.WebAddress, "web.addr", ":3000", "Server HTTP api Address")

defer runtime.HandleCrash()

flags.InitFlags()
logs.InitLogs()
defer logs.FlushLogs()

flags.DumpAll()

gearmand.NewServer(cfg).Start()
var rootCmd = &cobra.Command{
Use: "gearmand",
PersistentPreRun: func(c *cobra.Command, args []string) {
c.Flags().VisitAll(func(flag *pflag.Flag) {
log.Printf("FLAG: --%s=%q", flag.Name, flag.Value)
})
},
}
rootCmd.PersistentFlags().AddGoFlagSet(flag.CommandLine)

rootCmd.AddCommand(version.NewCmdVersion())
rootCmd.AddCommand(NewCmdRun())

if err := rootCmd.Execute(); err != nil {
os.Exit(1)
}
os.Exit(0)
}
28 changes: 28 additions & 0 deletions cmd/gearmand/run.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package main

import (
_ "net/http/pprof"
"os"

gearmand "github.com/appscode/g2/pkg/server"
"github.com/appscode/go/runtime"
"github.com/spf13/cobra"
)

func NewCmdRun() *cobra.Command {
var cfg gearmand.Config

cmd := &cobra.Command{
Use: "run",
Short: "Run Gearman server",
Run: func(cmd *cobra.Command, args []string) {
defer runtime.HandleCrash()
gearmand.NewServer(cfg).Start()
},
}

cmd.Flags().StringVar(&cfg.ListenAddr, "addr", ":4730", "listening on, such as 0.0.0.0:4730")
cmd.Flags().StringVar(&cfg.Storage, "storage-dir", os.TempDir()+"/gearmand", "Directory where LevelDB file is stored.")
cmd.Flags().StringVar(&cfg.WebAddress, "web.addr", ":3000", "Server HTTP api Address")
return cmd
}
35 changes: 35 additions & 0 deletions cmd/gearmand/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package main

import (
v "github.com/appscode/go/version"
)

var (
Version string
VersionStrategy string
Os string
Arch string
CommitHash string
GitBranch string
GitTag string
CommitTimestamp string
BuildTimestamp string
BuildHost string
BuildHostOs string
BuildHostArch string
)

func init() {
v.Version.Version = Version
v.Version.VersionStrategy = VersionStrategy
v.Version.Os = Os
v.Version.Arch = Arch
v.Version.CommitHash = CommitHash
v.Version.GitBranch = GitBranch
v.Version.GitTag = GitTag
v.Version.CommitTimestamp = CommitTimestamp
v.Version.BuildTimestamp = BuildTimestamp
v.Version.BuildHost = BuildHost
v.Version.BuildHostOs = BuildHostOs
v.Version.BuildHostArch = BuildHostArch
}
8 changes: 4 additions & 4 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions hack/docker/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ build_docker() {
cat >Dockerfile <<EOL
FROM alpine
RUN set -x \
&& apk update \
&& apk add ca-certificates \
&& rm -rf /var/cache/apk/*
COPY gearmand /gearmand
USER nobody:nobody
Expand Down
4 changes: 2 additions & 2 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type Config struct {
}

type Server struct {
config *Config
config Config
protoEvtCh chan *event
ctrlEvtCh chan *event
funcWorker map[string]*jobworkermap //function worker
Expand All @@ -53,7 +53,7 @@ var ( //const replys, to avoid building it every time
nojobReply = constructReply(PT_NoJob, nil)
)

func NewServer(cfg *Config) *Server {
func NewServer(cfg Config) *Server {
srv := &Server{
config: cfg,
funcWorker: make(map[string]*jobworkermap),
Expand Down
77 changes: 0 additions & 77 deletions vendor/github.com/appscode/go/flags/flags.go

This file was deleted.

52 changes: 52 additions & 0 deletions vendor/github.com/appscode/go/version/version.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 96d8ac3

Please sign in to comment.