516b8cf2be
Reimplement windows service restart part using svc, add recovery for failed service startup. Added restart-service cmd, to execute self restart in a separate process. Addressed issues: https://storjlabs.atlassian.net/browse/SG-49 https://storjlabs.atlassian.net/browse/SG-136 https://storjlabs.atlassian.net/browse/SG-137 Change-Id: Ic51d9a99e8c1c10800c6c60ff4e218321c674fea
31 lines
656 B
Go
31 lines
656 B
Go
// Copyright (C) 2020 Storj Labs, Inc.
|
|
// See LICENSE for copying information.
|
|
|
|
// +build unittest !windows
|
|
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
|
|
"github.com/spf13/cobra"
|
|
"github.com/zeebo/errs"
|
|
)
|
|
|
|
func cmdRestart(cmd *cobra.Command, args []string) error {
|
|
return nil
|
|
}
|
|
|
|
func restartService(ctx context.Context, service, binaryLocation, newVersionPath, backupPath string) error {
|
|
if err := os.Rename(binaryLocation, backupPath); err != nil {
|
|
return errs.Wrap(err)
|
|
}
|
|
|
|
if err := os.Rename(newVersionPath, binaryLocation); err != nil {
|
|
return errs.Combine(err, os.Rename(backupPath, binaryLocation), os.Remove(newVersionPath))
|
|
}
|
|
|
|
return nil
|
|
}
|