installer: support 'start_on_completion' (#96)
This commit is contained in:
parent
c0a487c47e
commit
73570c7144
|
@ -25,10 +25,11 @@ func New(ctx context.Context, manager *server.Manager, data []byte) (*Installer,
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg := &server.Configuration{
|
cfg := &server.Configuration{
|
||||||
Uuid: getString(data, "uuid"),
|
Uuid: getString(data, "uuid"),
|
||||||
Suspended: false,
|
Suspended: false,
|
||||||
Invocation: getString(data, "invocation"),
|
Invocation: getString(data, "invocation"),
|
||||||
SkipEggScripts: getBoolean(data, "skip_egg_scripts"),
|
SkipEggScripts: getBoolean(data, "skip_egg_scripts"),
|
||||||
|
StartOnCompletion: getBoolean(data, "start_on_completion"),
|
||||||
Build: environment.Limits{
|
Build: environment.Limits{
|
||||||
MemoryLimit: getInt(data, "build", "memory"),
|
MemoryLimit: getInt(data, "build", "memory"),
|
||||||
Swap: getInt(data, "build", "swap"),
|
Swap: getInt(data, "build", "swap"),
|
||||||
|
|
|
@ -2,6 +2,8 @@ package router
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -65,14 +67,30 @@ func postCreateServer(c *gin.Context) {
|
||||||
// cycle. If there are any errors they will be logged and communicated back
|
// cycle. If there are any errors they will be logged and communicated back
|
||||||
// to the Panel where a reinstall may take place.
|
// to the Panel where a reinstall may take place.
|
||||||
go func(i *installer.Installer) {
|
go func(i *installer.Installer) {
|
||||||
err := i.Server().CreateEnvironment()
|
if err := i.Server().CreateEnvironment(); err != nil {
|
||||||
if err != nil {
|
|
||||||
i.Server().Log().WithField("error", err).Error("failed to create server environment during install process")
|
i.Server().Log().WithField("error", err).Error("failed to create server environment during install process")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := i.Server().Install(false); err != nil {
|
if err := i.Server().Install(false); err != nil {
|
||||||
log.WithFields(log.Fields{"server": i.Uuid(), "error": err}).Error("failed to run install process for server")
|
log.WithFields(log.Fields{"server": i.Uuid(), "error": err}).Error("failed to run install process for server")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if i.Server().Config().StartOnCompletion {
|
||||||
|
log.WithField("server_id", i.Server().Id()).Debug("starting server after successful installation")
|
||||||
|
if err := i.Server().HandlePowerAction(server.PowerActionStart, 30); err != nil {
|
||||||
|
if errors.Is(err, context.DeadlineExceeded) {
|
||||||
|
log.WithFields(log.Fields{"server_id": i.Server().Id(), "action": "start"}).
|
||||||
|
Warn("could not acquire a lock while attempting to perform a power action")
|
||||||
|
} else {
|
||||||
|
log.WithFields(log.Fields{"server_id": i.Server().Id(), "action": "start", "error": err}).
|
||||||
|
Error("encountered error processing a server power action in the background")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.WithField("server_id", i.Server().Id()).
|
||||||
|
Debug("skipping automatic start after successful server installation")
|
||||||
}
|
}
|
||||||
}(install)
|
}(install)
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,9 @@ type Configuration struct {
|
||||||
|
|
||||||
// By default this is false, however if selected within the Panel while installing or re-installing a
|
// By default this is false, however if selected within the Panel while installing or re-installing a
|
||||||
// server, specific installation scripts will be skipped for the server process.
|
// server, specific installation scripts will be skipped for the server process.
|
||||||
SkipEggScripts bool `default:"false" json:"skip_egg_scripts"`
|
SkipEggScripts bool `json:"skip_egg_scripts"`
|
||||||
|
|
||||||
|
StartOnCompletion bool `json:"start_on_completion"`
|
||||||
|
|
||||||
// An array of environment variables that should be passed along to the running
|
// An array of environment variables that should be passed along to the running
|
||||||
// server process.
|
// server process.
|
||||||
|
@ -41,7 +43,7 @@ type Configuration struct {
|
||||||
|
|
||||||
Allocations environment.Allocations `json:"allocations"`
|
Allocations environment.Allocations `json:"allocations"`
|
||||||
Build environment.Limits `json:"build"`
|
Build environment.Limits `json:"build"`
|
||||||
CrashDetectionEnabled bool `default:"true" json:"enabled" yaml:"enabled"`
|
CrashDetectionEnabled bool `json:"crash_detection_enabled"`
|
||||||
Mounts []Mount `json:"mounts"`
|
Mounts []Mount `json:"mounts"`
|
||||||
Egg EggConfiguration `json:"egg,omitempty"`
|
Egg EggConfiguration `json:"egg,omitempty"`
|
||||||
|
|
||||||
|
@ -54,34 +56,30 @@ type Configuration struct {
|
||||||
func (s *Server) Config() *Configuration {
|
func (s *Server) Config() *Configuration {
|
||||||
s.cfg.mu.RLock()
|
s.cfg.mu.RLock()
|
||||||
defer s.cfg.mu.RUnlock()
|
defer s.cfg.mu.RUnlock()
|
||||||
|
|
||||||
return &s.cfg
|
return &s.cfg
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the amount of disk space available to a server in bytes.
|
// DiskSpace returns the amount of disk space available to a server in bytes.
|
||||||
func (s *Server) DiskSpace() int64 {
|
func (s *Server) DiskSpace() int64 {
|
||||||
s.cfg.mu.RLock()
|
s.cfg.mu.RLock()
|
||||||
defer s.cfg.mu.RUnlock()
|
defer s.cfg.mu.RUnlock()
|
||||||
|
|
||||||
return s.cfg.Build.DiskSpace * 1024.0 * 1024.0
|
return s.cfg.Build.DiskSpace * 1024.0 * 1024.0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) MemoryLimit() int64 {
|
func (s *Server) MemoryLimit() int64 {
|
||||||
s.cfg.mu.RLock()
|
s.cfg.mu.RLock()
|
||||||
defer s.cfg.mu.RUnlock()
|
defer s.cfg.mu.RUnlock()
|
||||||
|
|
||||||
return s.cfg.Build.MemoryLimit
|
return s.cfg.Build.MemoryLimit
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Configuration) GetUuid() string {
|
func (c *Configuration) GetUuid() string {
|
||||||
c.mu.RLock()
|
c.mu.RLock()
|
||||||
defer c.mu.RUnlock()
|
defer c.mu.RUnlock()
|
||||||
|
|
||||||
return c.Uuid
|
return c.Uuid
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Configuration) SetSuspended(s bool) {
|
func (c *Configuration) SetSuspended(s bool) {
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
|
defer c.mu.Unlock()
|
||||||
c.Suspended = s
|
c.Suspended = s
|
||||||
c.mu.Unlock()
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user