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
0242fa58
Commit
0242fa58
authored
7 years ago
by
Niko Ehrenfeuchter
Committed by
Niko Ehrenfeuchter (adm)
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add functions Log-Message(), Log-Error() and Log-Info().
Refers to
#13
parent
ad4fa830
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
AutoTx/Resources/Update-AutoTxService.ps1
+38
-6
38 additions, 6 deletions
AutoTx/Resources/Update-AutoTxService.ps1
with
38 additions
and
6 deletions
AutoTx/Resources/Update-AutoTxService.ps1
+
38
−
6
View file @
0242fa58
...
...
@@ -36,7 +36,7 @@ function Check-ServiceState([string]$ServiceName) {
if
(
$Continue
)
{
Return
}
Write-Host
"ERROR: Service
$(
$ServiceName
)
must be installed and running."
Log-Error
"ERROR: Service
'
$(
$ServiceName
)
'
must be installed and running."
Exit
}
...
...
@@ -98,7 +98,7 @@ function Update-FileIfNewer([string]$SourcePath, [string]$Destination) {
if
(
-Not
(
$SrcWriteTime
-gt
$TgtWriteTime
))
{
Return
}
Write-Host
"Found newer file at
$(
$SourcePath
)
, updating..."
Log-Info
-Message
"Found newer file at
$(
$SourcePath
)
, updating..."
Stop-MyService
$BakTimeStamp
=
Get-Date
-Format
s
|
foreach
{
$_
-replace
":"
,
"."
}
...
...
@@ -109,9 +109,8 @@ function Update-FileIfNewer([string]$SourcePath, [string]$Destination) {
Copy-Item
-Path
$SourcePath
-Destination
$Destination
-ErrorAction
Stop
}
catch
{
$ex
=
$_
.
Exception
Write-Host
"Copying
$(
$SourcePath
)
FAILED!"
-Fore
Red
Write-Host
$ex
.
Message
$ex
=
$_
.
Exception
.
Message
Log-Error
-Message
"Copying
$(
$SourcePath
)
FAILED!
`n
$(
$ex
)
"
Exit
}
}
...
...
@@ -151,13 +150,46 @@ function Update-ServiceBinaries {
if
(
Test-Path
"
$MarkerFile
"
-Type
Leaf
)
{
Return
}
Write-Host
"No marker file found, trying to update service binaries.
..
"
Log-Info
-Message
"No marker file found, trying to update service binaries."
Stop-MyService
Copy-ServiceFiles
New-Item
-Type
File
"
$MarkerFile
"
|
Out-Null
}
function
Log-Message
([
string
]
$Type
,
[
string
]
$Message
,
[
int
]
$Id
){
$msg
=
"[
$(
$Me
)
] "
try
{
Write-EventLog
`
-LogName
Application
`
-Source
"AutoTx"
`
-Category
0
`
-EventId
$Id
`
-EntryType
$Type
`
-Message
"[
$(
$Me
)
]:
$(
$Message
)
"
`
-ErrorAction
Stop
$msg
+=
"Logged message (Id=
$(
$Id
)
, Type=
$(
$Type
)
).
`n
"
$msg
+=
"--- Log Message ---
`n
$(
$Message
)
`n
--- Log Message ---
`n
"
}
catch
{
$ex
=
$_
.
Exception
.
Message
$msg
+=
"Error logging message (Id=
$(
$Id
)
, Type=
$(
$Type
)
)!
`n
"
$msg
+=
"--- Log Message ---
`n
$(
$Message
)
`n
--- Log Message ---
`n
"
$msg
+=
"--- Exception ---
`n
$(
$ex
)
`n
--- Exception ---"
}
Write-Host
$msg
}
function
Log-Error
([
string
]
$Message
){
Log-Message
-Type
Error
-Message
$Message
-Id
1
}
function
Log-Info
([
string
]
$Message
)
{
Log-Message
-Type
Information
-Message
$Message
-Id
1
}
# first check if the service is installed and running at all
...
...
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