Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Activity log crash #64

Merged
merged 4 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ type SystemConfiguration struct {

CrashDetection CrashDetection `yaml:"crash_detection"`

// The ammount of lines the activity logs should log on server crash
CrashActivityLogLines int `default:"2" yaml:"crash_detection_activity_lines"`

Backups Backups `yaml:"backups"`

Transfers Transfers `yaml:"transfers"`
Expand Down
2 changes: 2 additions & 0 deletions server/activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const (
ActivitySftpRename = models.Event("server:sftp.rename")
ActivitySftpDelete = models.Event("server:sftp.delete")
ActivityFileUploaded = models.Event("server:file.uploaded")
ActivityServerCrashed = models.Event("server:crashed")

)

// RequestActivity is a wrapper around a LoggedEvent that is able to track additional request
Expand Down
16 changes: 16 additions & 0 deletions server/crash.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ import (
"time"

"emperror.dev/errors"
"github.com/apex/log"

"github.com/pelican-dev/wings/config"
"github.com/pelican-dev/wings/environment"
"github.com/pelican-dev/wings/internal/models"

)

type CrashHandler struct {
Expand Down Expand Up @@ -69,6 +72,12 @@ func (s *Server) handleServerCrash() error {
return nil
}

// Get the last lines from the output before the crash so we can log it
logs, err := s.Environment.Readlog(config.Get().System.CrashActivityLogLines)
if err != nil {
log.WithField("server_id", s.ID()).Warn("Faild to get the last lines out of the console for the activity logs")
}

s.PublishConsoleOutputFromDaemon("---------- Detected server process in a crashed state! ----------")
s.PublishConsoleOutputFromDaemon(fmt.Sprintf("Exit code: %d", exitCode))
s.PublishConsoleOutputFromDaemon(fmt.Sprintf("Out of memory: %t", oomKilled))
Expand All @@ -85,6 +94,13 @@ func (s *Server) handleServerCrash() error {
return &crashTooFrequent{}
}

// Log that the server has crashed
s.SaveActivity(s.NewRequestActivity("", "127.0.0.1"), ActivityServerCrashed, models.ActivityMeta{
"exit_code": exitCode,
"oomkilled": oomKilled,
"logs": logs,
})

s.crasher.SetLastCrash(time.Now())

return errors.Wrap(s.HandlePowerAction(PowerActionStart), "failed to start server after crash detection")
Expand Down
Loading