storagenode/updater: recover command in Service Manager (#3425)

This commit is contained in:
Michal Niewrzal 2019-11-15 06:37:29 -08:00 committed by GitHub
parent a8e4e9cb03
commit ead8af3c16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 10 deletions

View File

@ -339,10 +339,6 @@ func fileExists(filename string) bool {
return info.Mode().IsRegular()
}
func main() {
process.Exec(rootCmd)
}
// TODO: improve logging; other commands use zap but due to an apparent
// windows bug we're unable to use the existing process logging infrastructure.
func openLog() (closeFunc func() error, err error) {
@ -359,3 +355,7 @@ func openLog() (closeFunc func() error, err error) {
}
return closeFunc, nil
}
func main() {
process.Exec(rootCmd)
}

View File

@ -56,7 +56,10 @@ func (m *service) Execute(args []string, r <-chan svc.ChangeRequest, changes cha
changes <- svc.Status{State: svc.StartPending}
go func() {
_ = rootCmd.Execute()
err := rootCmd.Execute()
if err != nil {
os.Exit(1)
}
}()
changes <- svc.Status{State: svc.Running, Accepts: cmdsAccepted}

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:fire="http://schemas.microsoft.com/wix/FirewallExtension">
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:fire="http://schemas.microsoft.com/wix/FirewallExtension" xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
<Product Id="*" Name="Storj V3 Storage Node" Language="1033" Version="!(bind.FileVersion.Storagenodeexe)" Manufacturer="Storj Labs Inc." UpgradeCode="{B32CF5FC-0665-4712-B88A-22D299565F9E}">
<Package Platform="x64" InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." AllowSameVersionUpgrades="yes" Schedule="afterInstallExecute"/>
@ -40,7 +40,7 @@
ErrorControl="normal"
Arguments="run --config-dir &quot;[INSTALLFOLDER]\&quot;"
/>
<ServiceControl Id="StoragenodeStartService" Start="install" Stop="both" Remove="uninstall" Name="storagenode" Wait="yes" />
<ServiceControl Id="StoragenodeStartService" Start="install" Stop="both" Remove="both" Name="storagenode" Wait="yes" />
<fire:FirewallException Id="StoragenodePort" Name="storagenode.exe" Port="28967" Scope="any"/>
</Component>
@ -57,9 +57,18 @@
Account="[SERVICEACCOUNT]"
Password="[SERVICEPASSWORD]"
ErrorControl="normal"
Arguments="run --config-dir &quot;[INSTALLFOLDER]\&quot; --identity-dir &quot;[IDENTITYDIR]\&quot; --binary-location &quot;[INSTALLFOLDER]\storagenode.exe&quot; --log &quot;[INSTALLFOLDER]\storagenode-updater.log&quot;"
/>
<ServiceControl Id="StoragenodeUpdaterStartService" Start="install" Stop="both" Remove="uninstall" Name="storagenode-updater" Wait="yes" />
Arguments="run --config-dir &quot;[INSTALLFOLDER]\&quot; --identity-dir &quot;[IDENTITYDIR]\&quot; --binary-location &quot;[INSTALLFOLDER]\storagenode.exe&quot; --log &quot;[INSTALLFOLDER]\storagenode-updater.log&quot;">
<util:ServiceConfig
ServiceName="storagenode-updater"
ResetPeriodInDays="1"
RestartServiceDelayInSeconds="60"
FirstFailureActionType="restart"
SecondFailureActionType="runCommand"
ThirdFailureActionType="runCommand"
ProgramCommandLine="cmd /c &quot;(echo %date% %time% recovery triggered to execute in 3 minutes &amp;&amp; timeout 180 >NUL &amp;&amp; echo %date% %time% recovery command executed: &amp;&amp; copy /y &quot;[INSTALLFOLDER]storagenode-updater.old.exe&quot; &quot;[INSTALLFOLDER]storagenode-updater.exe&quot; &amp;&amp; net start storagenode-updater) >> &quot;[INSTALLFOLDER]storagenode-updater-recovery.log&quot; 2>&amp;1&quot;"
/>
</ServiceInstall>
<ServiceControl Id="StoragenodeUpdaterStartService" Start="install" Stop="both" Remove="both" Name="storagenode-updater" Wait="yes" />
</Component>
<Component Id="dashboardShortcut" Guid="{C48A862E-869D-4FD4-A215-D47092A40BAA}" Win64="yes">