cmd

package
v4.0.0-...-5430b12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 22, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RootCmd = &cobra.Command{
	Use:   "server",
	Short: "Start the web server",
	Long: `Start the web server.

Starting the web server brings up a web interface and REST API that will use the
latest *.dgut.dbs directory and basedirs.db inside the given 'wrstat multi'
output directory to answer questions about where data is on the disks. (Provide
your 'wrstat multi -f' argument as an unamed argument to this command.)

Your --bind address should include the port, and for it to work with your
--cert, you probably need to specify it as fqdn:port.

The server authenticates users using Okta. You must specify all of
--okta_issuer, --okta_id and --okta_secret or env vars OKTA_OAUTH2_ISSUER,
OKTA_OAUTH2_CLIENT_ID and OKTA_OAUTH2_CLIENT_SECRET. You must also specify
--okta_url if that is different to --bind (eg. the service is bound to localhost
and will be behind a proxy accessed at a different domain).

The server will log all messages (of any severity) to syslog at the INFO level,
except for non-graceful stops of the server, which are sent at the CRIT level or
include 'panic' in the message. The messages are tagged 'wrstat-server', and you
might want to filter away 'STATUS=200' to find problems.
If --logfile is supplied, logs to that file instaed of syslog.

If --areas is supplied, the group,area csv file pointed to will be used to add
"areas" to the server, allowing clients to specify an area to filter on all
groups with that area.

--owners gid,owner csv file is required and will be used to associate groups
with their owners. If your groups don't really have owners, just supply the path
to a file with a fake entry.

The server must be running for 'wrstat where' calls to succeed.

This command will block forever in the foreground; you can background it with
ctrl-z; bg. Or better yet, use the daemonize program to daemonize this.

It will monitor a file called ".dgut.dbs.updated" in the given directory and
attempt to reload the databases when the file is updated by another run of
'wrstat multi' with the same output directory. After reloading, will delete the
previous run's database files. It will use the mtime of the file as the data
creation time in reports.
`,
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) != 1 {
			die("you must supply the path to your 'wrstat multi -f' output directory")
		}

		if serverBind == "" {
			die("you must supply --bind")
		}

		if serverCert == "" {
			die("you must supply --cert")
		}

		if serverKey == "" {
			die("you must supply --key")
		}

		if ownersPath == "" {
			die("you must supply --owners")
		}

		checkOAuthArgs()

		logWriter := setServerLogger(serverLogPath)

		s := server.New(logWriter)

		err := s.EnableAuthWithServerToken(serverCert, serverKey, serverTokenBasename, authenticateDeny)
		if err != nil {
			die("failed to enable authentication: %s", err)
		}

		if oktaURL == "" {
			oktaURL = serverBind
		}

		s.AddOIDCRoutes(oktaURL, oktaOAuthIssuer, oktaOAuthClientID, oktaOAuthClientSecret)

		s.WhiteListGroups(whiteLister)

		if areasPath != "" {
			s.AddGroupAreas(areasCSVToMap(areasPath))
		}

		info("opening databases, please wait...")
		dbPaths, err := server.FindLatestDgutDirs(args[0], dgutDBsSuffix)
		if err != nil {
			die("failed to find database paths: %s", err)
		}

		basedirsDBPath, err := server.FindLatestBasedirsDB(args[0], basedirBasename)
		if err != nil {
			die("failed to find basedirs database path: %s", err)
		}

		err = s.LoadDGUTDBs(dbPaths...)
		if err != nil {
			die("failed to load database: %s", err)
		}

		err = s.LoadBasedirsDB(basedirsDBPath, ownersPath)
		if err != nil {
			die("failed to load database: %s", err)
		}

		sentinel := filepath.Join(args[0], dgutDBsSentinelBasename)

		err = s.EnableDGUTDBReloading(sentinel, args[0], dgutDBsSuffix, sentinelPollFrequencty)
		if err != nil {
			die("failed to set up database reloading: %s", err)
		}

		err = s.EnableBasedirDBReloading(sentinel, args[0], basedirBasename, sentinelPollFrequencty)
		if err != nil {
			die("failed to set up database reloading: %s", err)
		}

		err = s.AddTreePage()
		if err != nil {
			die("failed to add tree page: %s", err)
		}

		defer s.Stop()

		sayStarted()

		err = s.Start(serverBind, serverCert, serverKey)
		if err != nil {
			die("non-graceful stop: %s", err)
		}
	},
}

RootCmd represents the server command.

View Source
var Version string

Version gets set during build: go build -ldflags "-X github.com/wtsi-ssg/wrstat/cmd.Version=`git describe --tags --always --long --dirty`" .

Functions

func Execute

func Execute()

Execute adds all child commands to the root command and sets flags appropriately. This is called by main.main(). It only needs to happen once to the rootCmd.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL