Skip to content

Commit

Permalink
Added flexibility to restart and clean scripts
Browse files Browse the repository at this point in the history
- Added logic to extract the name of the parent app running the `restart` and `clean` scripts in the event the app name is changed from `MetricsMetaConfigurationApp`
  • Loading branch information
codingWithJimmy committed Oct 3, 2022
1 parent 87f93c5 commit 4e34975
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
3 changes: 2 additions & 1 deletion bin/cleanMeta.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
### Configure path to checkpoint file as well as customer name and app path
$scriptAppPath=($MyInvocation.MyCommand.Source) -Replace ("\\bin\\cleanMeta.ps1","")
$CHECKPOINT = $SplunkHome + "\etc\metricsCheckpoint"
$APPHOME = $SplunkHome + "\etc\apps\metrics_meta_settings"

Expand All @@ -7,4 +8,4 @@ Remove-Item -path "$CHECKPOINT"
Remove-Item -path "$APPHOME" -recurse

### Remove the DeleteMeToRestart file to trigger a restart from the deployment server
Remove-Item -path "$SplunkHome\etc\apps\MetricsMetaConfigurationApp\DeleteMeToRestart"
Remove-Item -path "$scriptAppPath\DeleteMeToRestart"
17 changes: 9 additions & 8 deletions bin/restart.ps1
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
### Configure path to restart_check.txt
$scriptAppPath=($MyInvocation.MyCommand.Source) -Replace ("\\bin\\restart.ps1","")
$metaPath = "$SplunkHome\etc\restart_meta.txt"
$restartMeta = $(Test-Path "$SplunkHome\etc\restart_meta.txt" -PathType Leaf)

### Filter to attach timestamps where necessary
filter timestamp {"$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss.fff') ${env:COMPUTERNAME}: $_"}

if ($restartMeta -eq "True") {
Write-output "Meta settings has been changed." | timestamp
Write-output "Restarting forwarder." | timestamp
if ($restartMeta -eq "True") {
Remove-Item -path "$metaPath"
}
Remove-Item -path "$SplunkHome\etc\apps\MetricsMetaConfigurationApp\DeleteMeToRestart"
Write-output "Meta settings has been changed." | timestamp
Write-output "Restarting forwarder." | timestamp
if ($restartMeta -eq "True") {
Remove-Item -path "$metaPath"
}
Remove-Item -path "$scriptAppPath\DeleteMeToRestart"
} else {
Write-output "No settings have been changed." | timestamp
Write-output "No restart required." | timestamp
Write-output "No settings have been changed." | timestamp
Write-output "No restart required." | timestamp
}

0 comments on commit 4e34975

Please sign in to comment.