From d7bd10fceed703111c4648014644b82195fd4976 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Tue, 24 Dec 2019 16:57:22 -0800 Subject: [PATCH] Better approach to timezone handling by using a TZ environment variable --- config/config.go | 2 +- server/environment_docker.go | 22 +++++++++++++--------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/config/config.go b/config/config.go index 36c667a..ddb905a 100644 --- a/config/config.go +++ b/config/config.go @@ -166,7 +166,7 @@ type DockerConfiguration struct { // Defines the location of the timezone file on the host system that should // be mounted into the created containers so that they all use the same time. - TimezonePath string `default:"/etc/localtime" yaml:"timezone_path"` + TimezonePath string `default:"/etc/timezone" yaml:"timezone_path"` } // Defines the configuration for the internal API that is exposed by the diff --git a/server/environment_docker.go b/server/environment_docker.go index 0d4b2e3..6dd8d50 100644 --- a/server/environment_docker.go +++ b/server/environment_docker.go @@ -246,8 +246,6 @@ func (d *DockerEnvironment) Start() error { // No errors, good to continue through. sawError = false - zap.S().Debugw("right before start attach") - return d.Attach() } @@ -598,13 +596,16 @@ func (d *DockerEnvironment) Create() error { NetworkMode: "pterodactyl_nw", } - if err := mountTimezoneData(hostConf); err != nil { - if os.IsNotExist(err) { - zap.S().Warnw("the timezone data path configured does not exist on the system", zap.Error(errors.WithStack(err))) - } else { - zap.S().Warnw("failed to mount timezone data into container", zap.Error(errors.WithStack(err))) - } - } + // Pretty sure TZ=X in the environment variables negates the need for this + // to happen. Leaving it until I can confirm that works for everything. + // + // if err := mountTimezoneData(hostConf); err != nil { + // if os.IsNotExist(err) { + // zap.S().Warnw("the timezone data path configured does not exist on the system", zap.Error(errors.WithStack(err))) + // } else { + // zap.S().Warnw("failed to mount timezone data into container", zap.Error(errors.WithStack(err))) + // } + // } if _, err := cli.ContainerCreate(ctx, conf, hostConf, nil, d.Server.Uuid); err != nil { return errors.WithStack(err) @@ -728,7 +729,10 @@ func (d *DockerEnvironment) parseLogToStrings(b []byte) ([]string, error) { // Returns the environment variables for a server in KEY="VALUE" form. func (d *DockerEnvironment) environmentVariables() []string { + zone, _ := time.Now().In(time.Local).Zone() + var out = []string{ + fmt.Sprintf("TZ=%s", zone), fmt.Sprintf("STARTUP=%s", d.Server.Invocation), fmt.Sprintf("SERVER_MEMORY=%d", d.Server.Build.MemoryLimit), fmt.Sprintf("SERVER_IP=%s", d.Server.Allocations.DefaultMapping.Ip),