Skip to content

Commit

Permalink
Merge pull request PelicanPlatform#1639 from Saartank/cleanup-origin-…
Browse files Browse the repository at this point in the history
…startup

Cleanup origin startup stdout
  • Loading branch information
Saartank authored Oct 10, 2024
2 parents 11e6978 + 16703ff commit 2b6a14f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
20 changes: 20 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import (
"github.com/go-playground/validator/v10"
en_translations "github.com/go-playground/validator/v10/translations/en"
"github.com/pkg/errors"
"github.com/pressly/goose/v3"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand Down Expand Up @@ -88,6 +89,9 @@ type (
}

ContextKey string

// Custom goose logger
CustomGooseLogger struct{}
)

const (
Expand Down Expand Up @@ -180,6 +184,14 @@ func init() {
validate = validator.New(validator.WithRequiredStructEnabled())
}

// Implement logging for info and fatal levels using logrus.
func (l CustomGooseLogger) Printf(format string, v ...interface{}) {
log.Infof(format, v...)
}
func (l CustomGooseLogger) Fatalf(format string, v ...interface{}) {
log.Fatalf(format, v...)
}

// setEnabledServer sets the global variable config.EnabledServers to include newServers.
// Since this function should only be called in config package, we mark it "private" to avoid
// reset value in other package
Expand Down Expand Up @@ -834,6 +846,8 @@ func InitConfig() {
SetLogging(level)
}

goose.SetLogger(CustomGooseLogger{})

// Warn users about deprecated config keys they're using and try to map them to any new equivalent we've defined.
handleDeprecatedConfig()

Expand Down Expand Up @@ -919,6 +933,12 @@ func PrintPelicanVersion(out *os.File) {
fmt.Fprintln(out, "Built By:", GetBuiltBy())
}

func LogPelicanVersion() {
log.Infoln("Version:", GetVersion())
log.Infoln("Build Date:", GetBuiltDate())
log.Infoln("Build Commit:", GetBuiltCommit())
}

// Print Pelican configuration to stderr
func PrintConfig() error {
rawConfig, err := param.UnmarshalConfig()
Expand Down
8 changes: 2 additions & 6 deletions images/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
# OA4MP is only for origin. Don't configure it if the deamon is not origin
# the script is expect the argument in "[osdf|pelican] [deamon name] [...args]"
if [ "$2" == "origin" ]; then
echo "Initializing run environment for Pelican..."
####
# Setup the OA4MP configuration. Items are taken from https://github.com/scitokens/scitokens-oauth2-server/blob/master/start.sh
# which appears to have an Apache 2.0 license.
Expand All @@ -35,7 +34,8 @@ if [ "$2" == "origin" ]; then
export PATH="${ST_HOME}/bin:${QDL_HOME}/bin:${PATH}"

# Run the boot to inject the template
${QDL_HOME}/var/scripts/boot.qdl
#Suppress the output of the script, as it is unhelpful for the user.
${QDL_HOME}/var/scripts/boot.qdl > /dev/null

# check for one or more files in a directory
if [ -e /opt/scitokens-server/etc/qdl/ ]; then
Expand All @@ -52,7 +52,6 @@ if [ "$2" == "origin" ]; then

shopt -s nullglob
for fullfile in /opt/scitokens-server/etc/trusted-cas/*.pem; do
echo "Importing CA certificate $fullfile into the Java trusted CA store."
aliasname=$(basename "$file")
aliasname="${filename%.*}"
keytool -cacerts -importcert -noprompt -storepass changeit -file "$fullfile" -alias "$aliasname"
Expand Down Expand Up @@ -86,14 +85,11 @@ if [ "$2" == "origin" ]; then
# Tomcat requires us to provide the intermediate chain (which, in Kubernetes, is often in the same
# file as the host certificate itself. If there wasn't one provided, try splitting it out.
if [ ! -e /opt/tomcat/conf/chain.pem ]; then
echo "No chain present for host cert; trying to derive one"
pushd /tmp > /dev/null
if csplit -f tls- -b "%02d.crt.pem" -s -z "/opt/tomcat/conf/hostcert.pem" '/-----BEGIN CERTIFICATE-----/' '{1}' 2>/dev/null ; then
echo "Chain present in hostcert.pem; using it."
cp /tmp/tls-01.crt.pem /opt/tomcat/conf/chain.pem
rm /tmp/tls-*.crt.pem
else
echo "No chain present; will use empty file"
# No intermediate CAs found. Create an empty file.
touch /opt/tomcat/conf/chain.pem
fi
Expand Down
2 changes: 1 addition & 1 deletion launchers/launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func LaunchModules(ctx context.Context, modules server_structs.ServerType) (serv

ctx, shutdownCancel = context.WithCancel(ctx)

config.PrintPelicanVersion(os.Stderr) // Print Pelican version to stderr at server start
config.LogPelicanVersion()

// Print Pelican config at server start if it's in debug or info level
if log.GetLevel() >= log.InfoLevel {
Expand Down

0 comments on commit 2b6a14f

Please sign in to comment.