Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
auto-tx
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
vamp
auto-tx
Commits
b6b1d5cd
Commit
b6b1d5cd
authored
7 years ago
by
Niko Ehrenfeuchter
Browse files
Options
Downloads
Patches
Plain Diff
Wrap main logic in a try/catch block.
Closes
#28
parent
cb2fdc91
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Updater/Update-Service.ps1
+73
-65
73 additions, 65 deletions
Updater/Update-Service.ps1
with
73 additions
and
65 deletions
Updater/Update-Service.ps1
+
73
−
65
View file @
b6b1d5cd
...
...
@@ -569,90 +569,98 @@ Exit-IfDirMissing $UploadPathLogs "log file target"
# terminates the entire script:
Upload
-LogFiles
$UpdItems
=
@()
$ConfigShouldBeUpdated
=
NewConfig
-Available
$ConfigPath
$ServiceShouldBeUpdated
=
ServiceUpdate
-Requested
if
(
-Not
(
$ConfigShouldBeUpdated
-Or
$ServiceShouldBeUpdated
))
{
Log-Debug
"No update action found to be necessary."
Exit
}
try
{
$UpdItems
=
@()
$ConfigShouldBeUpdated
=
NewConfig-Available
$ConfigPath
$ServiceShouldBeUpdated
=
ServiceUpdate-Requested
if
(
-Not
(
$ConfigShouldBeUpdated
-Or
$ServiceShouldBeUpdated
))
{
Log-Debug
"No update action found to be necessary."
Exit
}
# define where the configuration is located that should be tested:
$ConfigToTest
=
$ConfigPath
if
(
$ConfigShouldBeUpdated
)
{
$ConfigToTest
=
$UpdPathConfig
$UpdItems
+=
"configuration files"
}
# define where the configuration is located that should be tested:
$ConfigToTest
=
$ConfigPath
if
(
$ConfigShouldBeUpdated
)
{
$ConfigToTest
=
$UpdPathConfig
$UpdItems
+=
"configuration files"
}
# define which configuration checker executable to use for testing:
$ConftestExe
=
"
$(
$InstallationPath
)
\AutoTxConfigTest.exe"
if
(
$ServiceShouldBeUpdated
)
{
$UpdPackage
=
Find-InstallationPackage
$ConftestExe
=
"
$(
$UpdPackage
)
\
$(
$ServiceName
)
\AutoTxConfigTest.exe"
$UpdItems
+=
"service binaries"
}
# define which configuration checker executable to use for testing:
$ConftestExe
=
"
$(
$InstallationPath
)
\AutoTxConfigTest.exe"
if
(
$ServiceShouldBeUpdated
)
{
$UpdPackage
=
Find-InstallationPackage
$ConftestExe
=
"
$(
$UpdPackage
)
\
$(
$ServiceName
)
\AutoTxConfigTest.exe"
$UpdItems
+=
"service binaries"
}
# now we're all set and can run the config test:
$ConfigValid
,
$ConfigSummary
=
Config
-IsValid
$ConftestExe
$ConfigToTest
# now we're all set and can run the config test:
$ConfigValid
,
$ConfigSummary
=
Config-IsValid
$ConftestExe
$ConfigToTest
# if we don't have a valid configuration we complain and terminate:
if
(
-Not
(
$ConfigValid
))
{
Log-Error
"Configuration not valid for service,
$(
$Me
)
terminating!"
Send-MailReport
-Subject
"Update failed, configuration invalid!"
`
-Body
$
(
"An update action was found to be necessary, however the"
"configuration didn't
`n
pass the validator.
`n`n
The following"
"summary was generated by the configuration checker:"
"
`n`n
$(
$ConfigSummary
)
"
)
Exit
}
# if we don't have a valid configuration we complain and terminate:
if
(
-Not
(
$ConfigValid
))
{
Log-Error
"Configuration not valid for service,
$(
$Me
)
terminating!"
Send-MailReport
-Subject
"Update failed, configuration invalid!"
`
-Body
$
(
"An update action was found to be necessary, however the"
"configuration didn't
`n
pass the validator.
`n`n
The following"
"summary was generated by the configuration checker:"
"
`n`n
$(
$ConfigSummary
)
"
)
Exit
}
# reaching this point means
# (1) something needs to be updated (config, service or both)
# AND
# (2) the config validates with the corresponding service version
Write
-Verbose
"Required update items:
`n
> -
$(
$UpdItems
-join
"
`n
> - "
)
`n
"
# reaching this point means
# (1) something needs to be updated (config, service or both)
# AND
# (2) the config validates with the corresponding service version
Write-Verbose
"Required update items:
`n
> -
$(
$UpdItems
-join
"
`n
> - "
)
`n
"
if
(
$ConfigShouldBeUpdated
)
{
$ConfigUpdated
=
Update-Configuration
if
(
-Not
$ConfigUpdated
)
{
$msg
=
"Updating the configuration failed,
$(
$Me
)
terminating!"
Log-Error
$msg
Send-MailReport
-Subject
"updated failed!"
-Body
$msg
Exit
if
(
$ConfigShouldBeUpdated
)
{
$ConfigUpdated
=
Update-Configuration
if
(
-Not
$ConfigUpdated
)
{
$msg
=
"Updating the configuration failed,
$(
$Me
)
terminating!"
Log-Error
$msg
Send-MailReport
-Subject
"updated failed!"
-Body
$msg
Exit
}
}
}
if
(
$ServiceShouldBeUpdated
)
{
$ServiceUpdated
=
Update-ServiceBinaries
if
(
-Not
$ServiceUpdated
)
{
$msg
=
"Updating the service binaries failed,
$(
$Me
)
terminating!"
Log-Error
$msg
Send-MailReport
-Subject
"updated failed!"
-Body
$msg
Exit
if
(
$ServiceShouldBeUpdated
)
{
$ServiceUpdated
=
Update-ServiceBinaries
if
(
-Not
$ServiceUpdated
)
{
$msg
=
"Updating the service binaries failed,
$(
$Me
)
terminating!"
Log-Error
$msg
Send-MailReport
-Subject
"updated failed!"
-Body
$msg
Exit
}
}
}
$UpdSummary
=
"Updated
$(
$UpdItems
-join
" and "
)
."
$UpdSummary
=
"Updated
$(
$UpdItems
-join
" and "
)
."
if
(
$ServiceRunningBefore
)
{
Log-Debug
"
$(
$UpdSummary
)
Trying to start the service again..."
Start-MyService
}
else
{
Log-Debug
"
$(
$UpdSummary
)
Leaving the service stopped, as before."
}
if
(
$ServiceRunningBefore
)
{
Log-Debug
"
$(
$UpdSummary
)
Trying to start the service again..."
Start-MyService
}
else
{
Log-Debug
"
$(
$UpdSummary
)
Leaving the service stopped, as before."
}
$UpdDetails
=
$
(
"An
$(
$Me
)
run completed successfully. Updated items:"
"
`n
> -
$(
$UpdItems
-join
"
`n
> - "
)
"
)
if
(
$ConfigUpdated
)
{
$UpdDetails
+=
"
`n`n
Config validation summary:
`n
$(
$ConfigSummary
)
"
$UpdDetails
=
$
(
"An
$(
$Me
)
run completed successfully. Updated items:"
"
`n
> -
$(
$UpdItems
-join
"
`n
> - "
)
"
)
if
(
$ConfigUpdated
)
{
$UpdDetails
+=
"
`n`n
Config validation summary:
`n
$(
$ConfigSummary
)
"
}
}
catch
{
$UpdDetails
=
$
(
"Unexpected problem, check logs!
$(
$Me
)
terminating."
"
`n`n
$(
$_
.
Exception
.
Message
)
"
)
$UpdSummary
=
"ERROR, unhandled problem occurered!"
Log-Error
$UpdDetails
}
Send-MailReport
-Subject
"
$UpdSummary
"
-Body
"
$UpdDetails
"
Send-MailReport
-Subject
"
$UpdSummary
"
-Body
"
$UpdDetails
"
Upload-LogFiles
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment