Fix some typos and run gofmt on all .go files
This commit is contained in:
@@ -36,7 +36,7 @@ func (a *Archive) Create(dst string, ctx context.Context) (os.FileInfo, error) {
|
||||
}
|
||||
|
||||
gzw, _ := gzip.NewWriterLevel(f, gzip.BestSpeed)
|
||||
_ = gzw.SetConcurrency(1 << 20, maxCpu)
|
||||
_ = gzw.SetConcurrency(1<<20, maxCpu)
|
||||
|
||||
defer gzw.Flush()
|
||||
defer gzw.Close()
|
||||
|
||||
@@ -77,10 +77,10 @@ func (s *S3Backup) generateRemoteRequest(rc io.ReadCloser) (*http.Response, erro
|
||||
}
|
||||
|
||||
r.Body = rc
|
||||
|
||||
|
||||
log.WithFields(log.Fields{
|
||||
"endpoint": s.PresignedUrl,
|
||||
"headers": r.Header,
|
||||
"headers": r.Header,
|
||||
}).Debug("uploading backup to remote S3 endpoint")
|
||||
|
||||
return http.DefaultClient.Do(r)
|
||||
|
||||
@@ -29,4 +29,4 @@ func (s *Server) UpdateConfigurationFiles() {
|
||||
}
|
||||
|
||||
pool.StopWait()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,7 +96,6 @@ func (s *Server) Throttler() *ConsoleThrottler {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Sends output to the server console formatted to appear correctly as being sent
|
||||
// from Wings.
|
||||
func (s *Server) PublishConsoleOutputFromDaemon(data string) {
|
||||
|
||||
@@ -35,7 +35,7 @@ func (cd *CrashHandler) SetLastCrash(t time.Time) {
|
||||
// if it was the result of an event that we should try to recover from.
|
||||
//
|
||||
// This function assumes it is called under circumstances where a crash is suspected
|
||||
// of occuring. It will not do anything to determine if it was actually a crash, just
|
||||
// of occurring. It will not do anything to determine if it was actually a crash, just
|
||||
// look at the exit state and check if it meets the criteria of being called a crash
|
||||
// by Wings.
|
||||
//
|
||||
@@ -75,7 +75,7 @@ func (s *Server) handleServerCrash() error {
|
||||
c := s.crasher.LastCrashTime()
|
||||
// If the last crash time was within the last 60 seconds we do not want to perform
|
||||
// an automatic reboot of the process. Return an error that can be handled.
|
||||
if !c.IsZero() && c.Add(time.Second * 60).After(time.Now()) {
|
||||
if !c.IsZero() && c.Add(time.Second*60).After(time.Now()) {
|
||||
s.PublishConsoleOutputFromDaemon("Aborting automatic reboot: last crash occurred less than 60 seconds ago.")
|
||||
|
||||
return &crashTooFrequent{}
|
||||
@@ -84,4 +84,4 @@ func (s *Server) handleServerCrash() error {
|
||||
s.crasher.SetLastCrash(time.Now())
|
||||
|
||||
return s.HandlePowerAction(PowerActionStart)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,4 +37,4 @@ func IsServerDoesNotExistError(err error) bool {
|
||||
_, ok := err.(*serverDoesNotExist)
|
||||
|
||||
return ok
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,14 +183,14 @@ func (fs *Filesystem) ParallelSafePath(paths []string) ([]string, error) {
|
||||
pi := p
|
||||
|
||||
// Recursively call this function to continue digging through the directory tree within
|
||||
// a seperate goroutine. If the context is canceled abort this process.
|
||||
// a separate goroutine. If the context is canceled abort this process.
|
||||
g.Go(func() error {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
default:
|
||||
// If the callback returns true, go ahead and keep walking deeper. This allows
|
||||
// us to programatically continue deeper into directories, or stop digging
|
||||
// us to programmatically continue deeper into directories, or stop digging
|
||||
// if that pathway knows it needs nothing else.
|
||||
if c, err := fs.SafePath(pi); err != nil {
|
||||
return err
|
||||
@@ -647,7 +647,7 @@ func (fs *Filesystem) Copy(p string) error {
|
||||
// Deletes a file or folder from the system. Prevents the user from accidentally
|
||||
// (or maliciously) removing their root server data directory.
|
||||
func (fs *Filesystem) Delete(p string) error {
|
||||
// This is one of the few (only?) places in the codebase where we're explictly not using
|
||||
// This is one of the few (only?) places in the codebase where we're explicitly not using
|
||||
// the SafePath functionality when working with user provided input. If we did, you would
|
||||
// not be able to delete a file that is a symlink pointing to a location outside of the data
|
||||
// directory.
|
||||
|
||||
@@ -9,5 +9,5 @@ import (
|
||||
func (s *Stat) CTime() time.Time {
|
||||
st := s.Info.Sys().(*syscall.Stat_t)
|
||||
|
||||
return time.Unix(int64(st.Ctimespec.Sec), int64(st.Ctimespec.Nsec))
|
||||
}
|
||||
return time.Unix(st.Ctimespec.Sec, st.Ctimespec.Nsec)
|
||||
}
|
||||
|
||||
@@ -9,5 +9,5 @@ import (
|
||||
func (s *Stat) CTime() time.Time {
|
||||
st := s.Info.Sys().(*syscall.Stat_t)
|
||||
|
||||
return time.Unix(int64(st.Ctim.Sec), int64(st.Ctim.Nsec))
|
||||
}
|
||||
return time.Unix(st.Ctim.Sec, st.Ctim.Nsec)
|
||||
}
|
||||
|
||||
@@ -9,4 +9,4 @@ import (
|
||||
// for right now.
|
||||
func (s *Stat) CTime() time.Time {
|
||||
return s.Info.ModTime()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ import (
|
||||
// Executes the installation stack for a server process. Bubbles any errors up to the calling
|
||||
// function which should handle contacting the panel to notify it of the server state.
|
||||
//
|
||||
// Pass true as the first arugment in order to execute a server sync before the process to
|
||||
// Pass true as the first argument in order to execute a server sync before the process to
|
||||
// ensure the latest information is used.
|
||||
func (s *Server) Install(sync bool) error {
|
||||
if sync {
|
||||
@@ -197,7 +197,7 @@ func (ip *InstallationProcess) RemoveContainer() {
|
||||
}
|
||||
}
|
||||
|
||||
// Runs the installation process, this is done as a backgrounded thread. This will configure
|
||||
// Runs the installation process, this is done as in a background thread. This will configure
|
||||
// the required environment, and then spin up the installation container.
|
||||
//
|
||||
// Once the container finishes installing the results will be stored in an installation
|
||||
@@ -210,7 +210,7 @@ func (ip *InstallationProcess) Run() error {
|
||||
|
||||
// We now have an exclusive lock on this installation process. Ensure that whenever this
|
||||
// process is finished that the semaphore is released so that other processes and be executed
|
||||
// without encounting a wait timeout.
|
||||
// without encountering a wait timeout.
|
||||
defer func() {
|
||||
ip.Server.Log().Debug("releasing installation process lock")
|
||||
ip.Server.installer.sem.Release(1)
|
||||
@@ -464,13 +464,13 @@ func (ip *InstallationProcess) Execute() (string, error) {
|
||||
ip.Server.Events().Publish(DaemonMessageEvent, "Installation process completed.")
|
||||
}(r.ID)
|
||||
|
||||
sChann, eChann := ip.client.ContainerWait(ip.context, r.ID, container.WaitConditionNotRunning)
|
||||
sChan, eChan := ip.client.ContainerWait(ip.context, r.ID, container.WaitConditionNotRunning)
|
||||
select {
|
||||
case err := <-eChann:
|
||||
case err := <-eChan:
|
||||
if err != nil {
|
||||
return "", errors.WithStack(err)
|
||||
}
|
||||
case <-sChann:
|
||||
case <-sChan:
|
||||
}
|
||||
|
||||
return r.ID, nil
|
||||
|
||||
@@ -33,8 +33,10 @@ func (s *Server) StartEventListeners() {
|
||||
|
||||
// Also pass the data along to the console output channel.
|
||||
s.onConsoleOutput(data.Data)
|
||||
|
||||
case data := <-state:
|
||||
s.SetState(data.Data)
|
||||
|
||||
case data := <-stats:
|
||||
st := new(environment.Stats)
|
||||
if err := json.Unmarshal([]byte(data.Data), st); err != nil {
|
||||
|
||||
@@ -94,7 +94,7 @@ func (s *Server) HandlePowerAction(action PowerAction, waitSeconds ...int) error
|
||||
|
||||
return s.Environment.Start()
|
||||
case PowerActionStop:
|
||||
// We're specificially waiting for the process to be stopped here, otherwise the lock is released
|
||||
// We're specifically waiting for the process to be stopped here, otherwise the lock is released
|
||||
// too soon, and you can rack up all sorts of issues.
|
||||
return s.Environment.WaitForStop(10*60, true)
|
||||
case PowerActionRestart:
|
||||
@@ -148,7 +148,7 @@ func (s *Server) onBeforeStart() error {
|
||||
|
||||
// Update the configuration files defined for the server before beginning the boot process.
|
||||
// This process executes a bunch of parallel updates, so we just block until that process
|
||||
// is completee. Any errors as a result of this will just be bubbled out in the logger,
|
||||
// is complete. Any errors as a result of this will just be bubbled out in the logger,
|
||||
// we don't need to actively do anything about it at this point, worst comes to worst the
|
||||
// server starts in a weird state and the user can manually adjust.
|
||||
s.PublishConsoleOutputFromDaemon("Updating process configuration files...")
|
||||
|
||||
@@ -39,8 +39,12 @@ func (s *Server) emitProcUsage() {
|
||||
s.resources.mu.RLock()
|
||||
defer s.resources.mu.RUnlock()
|
||||
|
||||
b, _ := json.Marshal(s.resources)
|
||||
s.Events().Publish(StatsEvent, string(b))
|
||||
b, err := json.Marshal(s.resources)
|
||||
if err == nil {
|
||||
s.Events().Publish(StatsEvent, string(b))
|
||||
}
|
||||
|
||||
// TODO: This might be a good place to add a debug log if stats are not sending.
|
||||
}
|
||||
|
||||
// Returns the servers current state.
|
||||
|
||||
@@ -156,7 +156,7 @@ func (s *Server) IsBootable() bool {
|
||||
return exists
|
||||
}
|
||||
|
||||
// Initalizes a server instance. This will run through and ensure that the environment
|
||||
// Initializes a server instance. This will run through and ensure that the environment
|
||||
// for the server is setup, and that all of the necessary files are created.
|
||||
func (s *Server) CreateEnvironment() error {
|
||||
// Ensure the data directory exists before getting too far through this process.
|
||||
|
||||
@@ -145,7 +145,7 @@ func (s *Server) SyncWithEnvironment() {
|
||||
// will be gracefully stopped (and terminated if it refuses to stop).
|
||||
s.Log().Info("server suspended with running process state, terminating now")
|
||||
|
||||
go func (s *Server) {
|
||||
go func(s *Server) {
|
||||
if err := s.Environment.WaitForStop(60, true); err != nil {
|
||||
s.Log().WithField("error", err).Warn("failed to terminate server environment after suspension")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user