Skip to content

Commit

Permalink
Extract server struct and add server options (#826)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexshtin committed Oct 11, 2020
1 parent 0531c95 commit 32d6a92
Show file tree
Hide file tree
Showing 17 changed files with 748 additions and 636 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/test.log

# Executables produced by temporal repo
/temporal*
/temporal-*
/tctl*

# Buf proto image
Expand Down
81 changes: 78 additions & 3 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,90 @@
package main

import (
"fmt"
"os"
"path"

"go.temporal.io/server/cmd/server/temporal"
"github.com/urfave/cli"

"go.temporal.io/server/common/headers"
_ "go.temporal.io/server/common/persistence/sql/sqlplugin/mysql" // needed to load mysql plugin
_ "go.temporal.io/server/common/persistence/sql/sqlplugin/postgresql" // needed to load postgresql plugin
"go.temporal.io/server/common/service/config"
"go.temporal.io/server/temporal"
)

// main entry point for the temporal server
func main() {
app := temporal.BuildCLI()
app.Run(os.Args)
app := buildCLI()
_ = app.Run(os.Args)
}

// buildCLI is the main entry point for the temporal server
func buildCLI() *cli.App {
app := cli.NewApp()
app.Name = "temporal"
app.Usage = "Temporal server"
app.Version = headers.ServerVersion

app.Flags = []cli.Flag{
cli.StringFlag{
Name: "root, r",
Value: ".",
Usage: "root directory of execution environment",
EnvVar: config.EnvKeyRoot,
},
cli.StringFlag{
Name: "config, c",
Value: "config",
Usage: "config dir path relative to root",
EnvVar: config.EnvKeyConfigDir,
},
cli.StringFlag{
Name: "env, e",
Value: "development",
Usage: "runtime environment",
EnvVar: config.EnvKeyEnvironment,
},
cli.StringFlag{
Name: "zone, az",
Usage: "availability zone",
EnvVar: config.EnvKeyAvailabilityZone,
},
}

allServicesStringSlice := cli.StringSlice(temporal.Services)
app.Commands = []cli.Command{
{
Name: "start",
Usage: "Start Temporal server",
Flags: []cli.Flag{
cli.StringSliceFlag{
Name: "services, s",
Value: &allServicesStringSlice,
Usage: "List of services to start",
},
},
Action: func(c *cli.Context) error {
env := c.GlobalString("env")
zone := c.GlobalString("zone")
configDir := path.Join(c.GlobalString("root"), c.GlobalString("config"))

services := c.StringSlice("services")

s := temporal.NewServer(
temporal.ForServices(services),
temporal.WithConfigLoader(configDir, env, zone),
temporal.InterruptOn(temporal.InterruptCh()),
)

err := s.Start()
if err != nil {
return cli.NewExitError(fmt.Sprintf("Unable to start server: %v.", err), 1)
}
return cli.NewExitError("All services are stopped.", 0)
},
},
}
return app
}

0 comments on commit 32d6a92

Please sign in to comment.