Skip to content
This repository has been archived by the owner on Mar 26, 2020. It is now read-only.

Commit

Permalink
Minor cleanup of main() function
Browse files Browse the repository at this point in the history
Signed-off-by: Prashanth Pai <[email protected]>
  • Loading branch information
prashanthpai committed Feb 1, 2017
1 parent 7c53d62 commit 2fbbc93
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 36 deletions.
7 changes: 0 additions & 7 deletions gdctx/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (

log "github.com/Sirupsen/logrus"
"github.com/pborman/uuid"
config "github.com/spf13/viper"
)

// Various version constants that will be used by GD2
Expand Down Expand Up @@ -47,19 +46,13 @@ func initOpVersion() {
}

func doInit() {
log.Debug("Initializing GlusterD context")

utils.InitDir(config.GetString("localstatedir"))

initOpVersion()

// When glusterd is started for the first time, we will have Restart set to
// false. That is when we'll have to initialize prefixes by passing true to
// InitStore(). On subsequent restarts of glusterd, we would want to skip
// initializing prefixes by passing false to InitStore()
InitStore(!Restart)

log.Debug("Initialized GlusterD context")
}

// Init initializes the GlusterD context. This should be called once before doing anything else.
Expand Down
4 changes: 2 additions & 2 deletions gdctx/myuuid.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func InitMyUUID() uuid.UUID {
}

u := uuid.Parse(string(ubytes))
log.WithField("myuuid", u.String()).Info("restored uuid")
log.WithField("uuid", u.String()).Info("Found existing UUID")
Restart = true

return u
Expand All @@ -45,7 +45,7 @@ func genMyUUID() uuid.UUID {
u := uuid.NewRandom()

writeMyUUIDFile(u)
log.WithField("myuuid", u.String()).Info("generated new MyUUID")
log.WithField("uuid", u.String()).Info("Generated new UUID")
return u
}

Expand Down
52 changes: 26 additions & 26 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,75 +19,69 @@ import (

func main() {

// Set IP and hostname once.
gdctx.SetHostnameAndIP()

// Parse flags and handle version and logging before continuing
// Parse command-line arguments
parseFlags()

showvers, _ := flag.CommandLine.GetBool("version")
if showvers {
if showvers, _ := flag.CommandLine.GetBool("version"); showvers {
dumpVersionInfo()
return
}

logLevel, _ := flag.CommandLine.GetString("loglevel")
initLog(logLevel, os.Stderr)

log.WithField("pid", os.Getpid()).Info("GlusterD starting")
log.WithField("pid", os.Getpid()).Info("Starting GlusterD")

// Read in config
// Read config file
confFile, _ := flag.CommandLine.GetString("config")
initConfig(confFile)

// Change to working directory before continuing
if e := os.Chdir(config.GetString("workdir")); e != nil {
log.WithError(e).Fatalf("failed to change working directory")
workdir := config.GetString("workdir")
if err := os.Chdir(workdir); err != nil {
log.WithError(err).Fatalf("Failed to change working directory to %s", workdir)
}

// TODO: This really should go into its own function.
utils.InitDir(config.GetString("localstatedir"))
utils.InitDir(config.GetString("rundir"))
utils.InitDir(config.GetString("logdir"))
utils.InitDir(path.Join(config.GetString("rundir"), "gluster"))
utils.InitDir(path.Join(config.GetString("logdir"), "glusterfs/bricks"))
// Create directories inside workdir - run dir, logdir etc
createDirectories()

// Generate UUID if it doesn't exist
gdctx.MyUUID = gdctx.InitMyUUID()

// Start embedded etcd server
etcdConfig, err := etcdmgmt.GetEtcdConfig(true)
if err != nil {
log.WithField("Error", err).Fatal("Could not fetch config options for etcd.")
log.WithError(err).Fatal("Could not fetch config options for etcd")
}
err = etcdmgmt.StartEmbeddedEtcd(etcdConfig)
if err != nil {
log.WithField("Error", err).Fatal("Could not start embedded etcd server.")
log.WithError(err).Fatal("Could not start embedded etcd server")
}

// Initialize op version and etcd store
gdctx.Init()

// Store self information in the store if GlusterD is coming up for
// first time
if !gdctx.Restart {
peer.AddSelfDetails()
}

// Start all servers (rest, peerrpc, sunrpc) managed by suture supervisor
super := initGD2Supervisor()
super.ServeBackground()

super.Add(servers.New())

// Use the main goroutine as signal handling loop
sigCh := make(chan os.Signal)
signal.Notify(sigCh)
for s := range sigCh {
log.WithField("signal", s).Debug("Signal recieved")
log.WithField("signal", s).Debug("Signal received")
switch s {
case os.Interrupt:
log.WithField("signal", s).Info("Recieved SIGTERM. Stopping GlusterD.")
log.Info("Received SIGTERM. Stopping GlusterD")
// Stop embedded etcd server, but don't wipe local etcd data
etcdmgmt.DestroyEmbeddedEtcd(false)
super.Stop()
log.Info("Terminating GlusterD.")
log.Info("Stopped GlusterD")
return
default:
continue
Expand All @@ -99,7 +93,13 @@ func initGD2Supervisor() *suture.Supervisor {
superlogger := func(msg string) {
log.WithField("supervisor", "gd2-main").Println(msg)
}
super := suture.New("gd2-main", suture.Spec{Log: superlogger})
return suture.New("gd2-main", suture.Spec{Log: superlogger})
}

return super
func createDirectories() {
utils.InitDir(config.GetString("localstatedir"))
utils.InitDir(config.GetString("rundir"))
utils.InitDir(config.GetString("logdir"))
utils.InitDir(path.Join(config.GetString("rundir"), "gluster"))
utils.InitDir(path.Join(config.GetString("logdir"), "glusterfs/bricks"))
}
2 changes: 1 addition & 1 deletion servers/sunrpc/program.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func registerProgram(server *rpc.Server, program Program, port int) error {
"progver": program.Version(),
})

logger.Info("registering sunrpc program")
logger.Debug("registering sunrpc program")

// NOTE: This will throw some benign log messages complaining about
// signatures of methods in Program interface. rpc.Server.Register()
Expand Down

0 comments on commit 2fbbc93

Please sign in to comment.