Skip to content

Commit 85928c2

Browse files
Update to dsremove scripts
Updates to the dsremove scripts so they perform the same actions with the same logic so they behave the same way
1 parent 136167b commit 85928c2

File tree

2 files changed

+27
-19
lines changed

2 files changed

+27
-19
lines changed

bin/dsRemove.ps1

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
### Configure file paths for the system
2-
$LOCAL = {$(Test-Path "$SPLUNKHOME\etc\system\local\deploymentclient.conf")}
3-
$DEPLOYED = {$(Test-Path "$SPLUNKHOME\etc\apps\*\*\deploymentclient.conf")}
2+
$LOCAL = {$((Get-ChildItem -Path "$SPLUNKHOME\etc\system\local" -Include deploymentclient.conf -File -Recurse).Count)}
3+
$DEPLOYED = {$((Get-ChildItem -Path "$SPLUNKHOME\etc\apps" -Include deploymentclient.conf -File -Recurse).Count)}
44
$RESTART_CHECK = "$SPLUNKHOME\etc\restartds.txt"
55

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

9-
### Check to see if there is a deploymentclient.conf file under $SPLUNK_HOME\etc\apps and bail out if there isn't
10-
if ($DEPLOYED -eq "False") {
11-
Write-output "No deploymentclient.conf detected in \$SPLUNK_HOME\etc\apps. Bailing out so the fowarder doesn't get orphaned." | timestamp
12-
} elseif ($LOCAL -eq "True") {
9+
### Check to see if there is a deploymentclient.conf file under $SPLUNKHOME\etc\apps and bail out if there isn't
10+
if ($DEPLOYED -eq "0") {
11+
Write-output "No deploymentclient.conf detected in $SPLUNKHOME\etc\apps. Bailing out so the fowarder doesn't get orphaned." | timestamp
12+
} elseif ($DEPLOYED -gt "1") {
13+
Write-output "Multiple deploymentclient.conf detected in $SPLUNKHOME\etc\apps. Check all deployed apps to ensure you\'re only using one." | timestamp
14+
} elseif ($LOCAL -eq "1" -AND $DEPLOYED -eq "1") {
1315
### Remove the local "deploymentclient.conf" and flag
1416
Write-output "Removed deploymentclient.conf from local system." | timestamp
1517
Remove-Item -Path "$LOCAL"
1618
Out-File -FilePath "$RESTART_CHECK"
17-
} else {
19+
} else {
1820
Write-output "No deploymentclient.conf correction necessary." | timestamp
19-
}
21+
}

bin/dsRemove.sh

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,20 @@ LOCAL=$(find $SPLUNK_HOME/etc/system/local -type f -name deploymentclient.conf |
55
RESTART_CHECK=$SPLUNK_HOME/etc/restartds.txt
66

77
### Check variables and take action accordingly
8-
if [ $LOCAL = "1" ] & [ $DEPLOYED_APP = "0" ]; then
9-
echo $(date -R) $HOSTNAME: No deploymentclient.conf detected in \$SPLUNK_HOME/etc/apps. Bailing out so the fowarder doesn\'t get orphaned.
10-
exit
11-
elif [ $LOCAL = "1" ] & [ $DEPLOYED_APP = "1" ]; then
12-
# Remove the deploymentclient.conf from $SPLUNK_HOME/etc/system/local
13-
rm -f $SPLUNK_HOME/etc/system/local/deploymentclient.conf > /dev/null 2>&1
14-
echo $(date -R) $HOSTNAME: Removed deploymentclient.conf from local system.
15-
touch $RESTART_CHECK
16-
else
17-
echo $(date -R) $HOSTNAME: No deploymentclient.conf correction necessary.
18-
fi
8+
## If there is no deployed app with a deployment client, bail out
9+
if [ $DEPLOYED_APP = "0" ]; then
10+
echo $(date -R) $HOSTNAME: No deploymentclient.conf detected in $SPLUNK_HOME/etc/apps. Bailing out so the fowarder doesn\'t get orphaned.
11+
exit 1
12+
## If more than one deploymentclient.conf file is deployed, bail out
13+
elif [ $DEPLOYED_APP > "1" ]; then
14+
echo $(date -R) $HOSTNAME: Multiple deploymentclient.conf detected in $SPLUNK_HOME/etc/apps. Check all deployed apps to ensure you\'re only using one.
15+
exit 1
16+
## If there's 1 local config and 1 deployed config, remove the local one and set the checkpoint file
17+
elif [ $LOCAL = "1" ] & [ $DEPLOYED_APP = "1" ]; then
18+
# Remove the deploymentclient.conf from $SPLUNK_HOME/etc/system/local
19+
rm -f $SPLUNK_HOME/etc/system/local/deploymentclient.conf > /dev/null 2>&1
20+
echo $(date -R) $HOSTNAME: Removed deploymentclient.conf from local system.
21+
touch $RESTART_CHECK
22+
else
23+
echo $(date -R) $HOSTNAME: No deploymentclient.conf correction necessary.
24+
fi

0 commit comments

Comments
 (0)