diff --git a/pkg/cli/flags.go b/pkg/cli/flags.go index e54b0794bd24..154fa80a6420 100644 --- a/pkg/cli/flags.go +++ b/pkg/cli/flags.go @@ -815,6 +815,7 @@ func init() { varFlag(f, addrSetter{&serverHTTPAddr, &serverHTTPPort}, cliflags.ListenHTTPAddr) stringSliceFlag(f, &serverCfg.SQLConfig.TenantKVAddrs, cliflags.KVAddrs) + varFlag(f, &startCtx.logDir, cliflags.LogDir) } } diff --git a/pkg/cli/mt_start_sql.go b/pkg/cli/mt_start_sql.go index d12f103fc57c..d33bf22340e3 100644 --- a/pkg/cli/mt_start_sql.go +++ b/pkg/cli/mt_start_sql.go @@ -19,7 +19,6 @@ import ( "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/server" "github.com/cockroachdb/cockroach/pkg/util/log" - "github.com/cockroachdb/cockroach/pkg/util/stop" "github.com/cockroachdb/errors" "github.com/spf13/cobra" ) @@ -61,7 +60,18 @@ well unless it can be verified using a trusted root certificate store. That is, func runStartSQL(cmd *cobra.Command, args []string) error { ctx := context.Background() const clusterName = "" - stopper := stop.NewStopper() + + // Remove the default store, which avoids using it to set up logging. + // Instead, we'll default to logging to stderr unless --log-dir is + // specified. This makes sense since the standalone SQL server is + // at the time of writing stateless and may not be provisioned with + // suitable storage. + serverCfg.Stores.Specs = nil + + stopper, err := setupAndInitializeLoggingAndProfiling(ctx, cmd) + if err != nil { + return err + } defer stopper.Stop(ctx) st := serverCfg.BaseConfig.Settings diff --git a/pkg/cli/start.go b/pkg/cli/start.go index 4a2992ad375c..ef3c4a487cc4 100644 --- a/pkg/cli/start.go +++ b/pkg/cli/start.go @@ -1001,7 +1001,7 @@ func logOutputDirectory() string { // setupAndInitializeLoggingAndProfiling does what it says on the label. // Prior to this however it determines suitable defaults for the // logging output directory and the verbosity level of stderr logging. -// We only do this for the "start" command which is why this work +// We only do this for the "start" and "start-sql" commands which is why this work // occurs here and not in an OnInitialize function. func setupAndInitializeLoggingAndProfiling( ctx context.Context, cmd *cobra.Command, @@ -1031,6 +1031,7 @@ func setupAndInitializeLoggingAndProfiling( } newDir = filepath.Join(spec.Path, "logs") } + if err := startCtx.logDir.Set(newDir); err != nil { return nil, err } diff --git a/pkg/server/config.go b/pkg/server/config.go index 6a6b6cb0f4fa..c243d5f34ac9 100644 --- a/pkg/server/config.go +++ b/pkg/server/config.go @@ -54,7 +54,7 @@ const ( defaultScanMinIdleTime = 10 * time.Millisecond defaultScanMaxIdleTime = 1 * time.Second - defaultStorePath = "cockroach-data" + DefaultStorePath = "cockroach-data" // TempDirPrefix is the filename prefix of any temporary subdirectory // created. TempDirPrefix = "cockroach-temp" @@ -384,7 +384,7 @@ func SetOpenFileLimitForOneStore() (uint64, error) { // MakeConfig returns a Config for the system tenant with default values. func MakeConfig(ctx context.Context, st *cluster.Settings) Config { - storeSpec, err := base.NewStoreSpec(defaultStorePath) + storeSpec, err := base.NewStoreSpec(DefaultStorePath) if err != nil { panic(err) } diff --git a/pkg/server/testserver.go b/pkg/server/testserver.go index 7eedbc499a74..42aa0fad79b7 100644 --- a/pkg/server/testserver.go +++ b/pkg/server/testserver.go @@ -544,6 +544,9 @@ func makeSQLServerArgs( const sqlInstanceID = base.SQLInstanceID(10001) idContainer := base.NewSQLIDContainer(sqlInstanceID, &c, false /* exposed */) + runtime := status.NewRuntimeStatSampler(context.Background(), clock) + registry.AddMetricStruct(runtime) + // We don't need this for anything except some services that want a gRPC // server to register against (but they'll never get RPCs at the time of // writing): the blob service and DistSQL. @@ -573,7 +576,7 @@ func makeSQLServerArgs( BaseConfig: &baseCfg, stopper: stopper, clock: clock, - runtime: status.NewRuntimeStatSampler(context.Background(), clock), + runtime: runtime, rpcContext: rpcContext, nodeDescs: tenantConnect, systemConfigProvider: tenantConnect,