Changes to ProcessConfiguration
This commit is contained in:
parent
eb975e0cbd
commit
9bd10f1043
|
@ -31,10 +31,9 @@ type ServerConfigurationResponse struct {
|
||||||
// and what changes to make to the configuration file for a server.
|
// and what changes to make to the configuration file for a server.
|
||||||
type ProcessConfiguration struct {
|
type ProcessConfiguration struct {
|
||||||
Startup struct {
|
Startup struct {
|
||||||
Done string `json:"done"`
|
Done []string `json:"done"`
|
||||||
UserInteraction []string `json:"userInteraction"`
|
UserInteraction []string `json:"user_interaction"`
|
||||||
SplitCharacter string `json:"splitCharacter"`
|
StripAnsi bool `json:"strip_ansi"`
|
||||||
StripAnsi bool `json:"stripAnsi"`
|
|
||||||
} `json:"startup"`
|
} `json:"startup"`
|
||||||
|
|
||||||
Stop struct {
|
Stop struct {
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"github.com/pterodactyl/wings/api"
|
"github.com/pterodactyl/wings/api"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Adds all of the internal event listeners we want to use for a server.
|
// Adds all of the internal event listeners we want to use for a server.
|
||||||
|
@ -22,7 +23,12 @@ func (s *Server) AddEventListeners() {
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
var stripAnsiRegex = regexp.MustCompile("[\u001B\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))")
|
var (
|
||||||
|
stripAnsiRegex = regexp.MustCompile("[\u001B\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))")
|
||||||
|
|
||||||
|
regexpCacheMx sync.RWMutex
|
||||||
|
regexpCache map[string]*regexp.Regexp
|
||||||
|
)
|
||||||
|
|
||||||
// Custom listener for console output events that will check if the given line
|
// Custom listener for console output events that will check if the given line
|
||||||
// of output matches one that should mark the server as started or not.
|
// of output matches one that should mark the server as started or not.
|
||||||
|
@ -36,22 +42,39 @@ func (s *Server) onConsoleOutput(data string) {
|
||||||
// set the server to that state. Only do this if the server is not currently stopped
|
// set the server to that state. Only do this if the server is not currently stopped
|
||||||
// or stopping.
|
// or stopping.
|
||||||
|
|
||||||
var matches []string
|
|
||||||
if processConfiguration.Startup.SplitCharacter != "" {
|
|
||||||
matches = strings.Split(processConfiguration.Startup.Done, processConfiguration.Startup.SplitCharacter)
|
|
||||||
} else {
|
|
||||||
matches = []string{processConfiguration.Startup.Done}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if we should strip ansi color codes.
|
// Check if we should strip ansi color codes.
|
||||||
if processConfiguration.Startup.StripAnsi {
|
if processConfiguration.Startup.StripAnsi {
|
||||||
// Strip ansi color codes from the data string.
|
// Strip ansi color codes from the data string.
|
||||||
data = stripAnsiRegex.ReplaceAllString(data, "")
|
data = stripAnsiRegex.ReplaceAllString(data, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iterate over all the matches.
|
// Iterate over all the done lines.
|
||||||
for _, match := range matches {
|
for _, match := range processConfiguration.Startup.Done {
|
||||||
if !strings.Contains(data, match) {
|
if strings.HasPrefix(match, "regex:") && len(match) > 6 {
|
||||||
|
match = match[6:]
|
||||||
|
|
||||||
|
regexpCacheMx.RLock()
|
||||||
|
rxp, ok := regexpCache[match]
|
||||||
|
regexpCacheMx.RUnlock()
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
rxp, err = regexp.Compile(match)
|
||||||
|
if err != nil {
|
||||||
|
log.WithError(err).Warn("failed to compile regexp")
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
regexpCacheMx.Lock()
|
||||||
|
regexpCache[match] = rxp
|
||||||
|
regexpCacheMx.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
if !rxp.MatchString(data) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
} else if !strings.Contains(data, match) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user