Skip to content

Commit

Permalink
Update Pelican to not require a set $HOME in some configurations
Browse files Browse the repository at this point in the history
In some remote environments like HTCondor, we can't always assume that the user
has a configured $HOME directory. Previously, this was enforced in both the root
command and in the `main` package's chain of `init()` functions, preventing
stash_plugin from running in HTCondor even though no $HOME directory is needed
in that case.

This makes an unset $HOME a non-fatal warning at the root command level, and moves
`InitServer()` into a pre-run for each cobra command that is actually responsible
for starting a server. In the cases of servers, we do still require $HOME.
  • Loading branch information
jhiemstrawisc committed Oct 13, 2023
1 parent 8a87a1f commit e92a09d
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 9 deletions.
5 changes: 5 additions & 0 deletions cmd/director.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,18 @@
package main

import (
"github.com/pelicanplatform/pelican/config"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

var (
directorCmd = &cobra.Command{
Use: "director",
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
err := config.InitServer()
return err
},
Short: "Launch a Pelican Director",
Long: `Launch a Pelican Director service:
Expand Down
5 changes: 5 additions & 0 deletions cmd/namespace_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,17 @@
package main

import (
"github.com/pelicanplatform/pelican/config"
"github.com/spf13/cobra"
)

var (
namespaceRegistryCmd = &cobra.Command{
Use: "registry",
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
err := config.InitServer()
return err
},
Short: "Interact with a Pelican namespace registry service",
Long: `Interact with a Pelican namespace registry service:
Expand Down
17 changes: 17 additions & 0 deletions cmd/origin.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"fmt"
"os"

"github.com/pelicanplatform/pelican/config"
"github.com/pelicanplatform/pelican/metrics"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
Expand All @@ -30,6 +32,10 @@ var (
originCmd = &cobra.Command{
Use: "origin",
Short: "Operate a Pelican origin service",
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
err := initOrigin()
return err
},
}

originConfigCmd = &cobra.Command{
Expand Down Expand Up @@ -81,6 +87,17 @@ func configOrigin( /*cmd*/ *cobra.Command /*args*/, []string) {
os.Exit(1)
}

func initOrigin() error {
err := config.InitServer()
cobra.CheckErr(err)
err = metrics.SetComponentHealthStatus("xrootd", "critical", "xrootd has not been started")
cobra.CheckErr(err)
err = metrics.SetComponentHealthStatus("cmsd", "critical", "cmsd has not been started")
cobra.CheckErr(err)

return err
}

func init() {
originCmd.AddCommand(originConfigCmd)
originCmd.AddCommand(originServeCmd)
Expand Down
8 changes: 0 additions & 8 deletions cmd/origin_serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,6 @@ type (
}
)

func init() {
err := config.InitServer()
cobra.CheckErr(err)
err = metrics.SetComponentHealthStatus("xrootd", "critical", "xrootd has not been started")
cobra.CheckErr(err)
err = metrics.SetComponentHealthStatus("cmsd", "critical", "cmsd has not been started")
cobra.CheckErr(err)
}

func checkXrootdEnv() error {
uid, err := config.GetDaemonUID()
Expand Down
4 changes: 3 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ func initConfig() {
viper.SetConfigFile(cfgFile)
} else {
home, err := os.UserHomeDir()
cobra.CheckErr(err)
if err != nil {
log.Warningln("No home directory found for user -- will check for configuration yaml in /etc/pelican/")
}

viper.AddConfigPath(filepath.Join(home, ".config", "pelican"))
viper.AddConfigPath(filepath.Join("/etc", "pelican"))
Expand Down

0 comments on commit e92a09d

Please sign in to comment.