Use more easily configurable timezone, remove /etc/timezone mounts from containers; closes pterodactyl/panel#2513
If this does not completely solve the issue in containers then we need to evaluate the image being used to determine what changes need to happen to the image itself to support the timezone. ref pterodactyl/panel#2239 ref pterodactyl/panel#2329 ref pterodactyl/panel#2389
This commit is contained in:
@@ -2,10 +2,8 @@ package server
|
||||
|
||||
import (
|
||||
"github.com/apex/log"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/pterodactyl/wings/config"
|
||||
"github.com/pterodactyl/wings/environment"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
@@ -16,41 +14,17 @@ import (
|
||||
type Mount environment.Mount
|
||||
|
||||
// Returns the default container mounts for the server instance. This includes the data directory
|
||||
// for the server as well as any timezone related files if they exist on the host system so that
|
||||
// servers running within the container will use the correct time.
|
||||
// for the server. Previously this would also mount in host timezone files, however we've moved from
|
||||
// that approach to just setting `TZ=Timezone` environment values in containers which should work
|
||||
// in most scenarios.
|
||||
func (s *Server) Mounts() []environment.Mount {
|
||||
var m []environment.Mount
|
||||
|
||||
m = append(m, environment.Mount{
|
||||
Default: true,
|
||||
Target: "/home/container",
|
||||
Source: s.Filesystem().Path(),
|
||||
ReadOnly: false,
|
||||
})
|
||||
|
||||
// Try to mount in /etc/localtime and /etc/timezone if they exist on the host system.
|
||||
if _, err := os.Stat("/etc/localtime"); err != nil {
|
||||
if !os.IsNotExist(err) {
|
||||
log.WithField("error", errors.WithStack(err)).Warn("failed to stat /etc/localtime due to an error")
|
||||
}
|
||||
} else {
|
||||
m = append(m, environment.Mount{
|
||||
Target: "/etc/localtime",
|
||||
Source: "/etc/localtime",
|
||||
ReadOnly: true,
|
||||
})
|
||||
}
|
||||
|
||||
if _, err := os.Stat("/etc/timezone"); err != nil {
|
||||
if !os.IsNotExist(err) {
|
||||
log.WithField("error", errors.WithStack(err)).Warn("failed to stat /etc/timezone due to an error")
|
||||
}
|
||||
} else {
|
||||
m = append(m, environment.Mount{
|
||||
Target: "/etc/timezone",
|
||||
Source: "/etc/timezone",
|
||||
ReadOnly: true,
|
||||
})
|
||||
m := []environment.Mount{
|
||||
{
|
||||
Default: true,
|
||||
Target: "/home/container",
|
||||
Source: s.Filesystem().Path(),
|
||||
ReadOnly: false,
|
||||
},
|
||||
}
|
||||
|
||||
// Also include any of this server's custom mounts when returning them.
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/apex/log"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/pterodactyl/wings/api"
|
||||
"github.com/pterodactyl/wings/config"
|
||||
"github.com/pterodactyl/wings/environment"
|
||||
"github.com/pterodactyl/wings/environment/docker"
|
||||
"github.com/pterodactyl/wings/events"
|
||||
@@ -13,7 +14,6 @@ import (
|
||||
"golang.org/x/sync/semaphore"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
// High level definition for a server instance being controlled by Wings.
|
||||
@@ -78,10 +78,8 @@ func (s *Server) Id() string {
|
||||
// Returns all of the environment variables that should be assigned to a running
|
||||
// server instance.
|
||||
func (s *Server) GetEnvironmentVariables() []string {
|
||||
zone, _ := time.Now().In(time.Local).Zone()
|
||||
|
||||
var out = []string{
|
||||
fmt.Sprintf("TZ=%s", zone),
|
||||
fmt.Sprintf("TZ=%s", config.Get().System.Timezone),
|
||||
fmt.Sprintf("STARTUP=%s", s.Config().Invocation),
|
||||
fmt.Sprintf("SERVER_MEMORY=%d", s.MemoryLimit()),
|
||||
fmt.Sprintf("SERVER_IP=%s", s.Config().Allocations.DefaultMapping.Ip),
|
||||
@@ -90,6 +88,7 @@ func (s *Server) GetEnvironmentVariables() []string {
|
||||
|
||||
eloop:
|
||||
for k := range s.Config().EnvVars {
|
||||
// Don't allow any environment variables that we have already set above.
|
||||
for _, e := range out {
|
||||
if strings.HasPrefix(e, strings.ToUpper(k)) {
|
||||
continue eloop
|
||||
|
||||
Reference in New Issue
Block a user