Firstly, I’d like to thank @steve for creating the original content on BigFix.me for this problem
[ORIGINAL WINDOWS FIXLET]
I’d also like to thank @strawgate for his very helpful guide on this subject too
Now to the point, I’m no expert, there’s probably stuff I’ve missed and yeah I love exit codes
I’ve updated the content as there doesn’t seem to be any Unix version of this out there (which is a real pain) however I’m sure there are probably better ways of doing this so I’m putting it on here before adding it to bigfix.me to get a community effort going in making this better and more efficient (cause I know there will be ways).
Relevance will be whether or not the BESRelay is installed.
if {windows of operating system}
// restart the BES Relay first
waithidden cmd.exe /C net stop besrelay
if {exit code of action = 0}
else exit 12
endif
// set starting time
setting "_BESClient_PauseWhile"="{now as string}" on "{parameter "action issue date" of action}" for client
// PAUSE until the relay service stops or 3 minutes has passed.
pause while {(exists running application whose (name of it as lowercase = "besrelay.exe") OR exists running service whose (service name of it as lowercase = "besrelay")) AND (now - (value of setting "_BESClient_PauseWhile" of client as string as time)) < 3*minute}
delete "{value "InboxLocation" of key "HKLM\SOFTWARE\BigFix\Enterprise Server\GatherService" of registry}\GatherState.xml.bak"
if {exit code of action = 0}
else exit 13
endif
move "{value "InboxLocation" of key "HKLM\SOFTWARE\BigFix\Enterprise Server\GatherService" of registry}\GatherState.xml" "{value "InboxLocation" of key "HKLM\SOFTWARE\BigFix\Enterprise Server\GatherService" of registry}\GatherState.xml.bak"
if {exit code of action = 0}
else exit 14
endif
delete "{value "InboxLocation" of key "HKLM\SOFTWARE\BigFix\Enterprise Server\GatherService" of registry}\bfemapfile.xml.bak"
if {exit code of action = 0}
else exit 15
endif
move "{value "InboxLocation" of key "HKLM\SOFTWARE\BigFix\Enterprise Server\GatherService" of registry}\bfemapfile.xml" "{value "InboxLocation" of key "HKLM\SOFTWARE\BigFix\Enterprise Server\GatherService" of registry}\bfemapfile.xml.bak"
if {exit code of action = 0}
else exit 16
endif
waithidden cmd.exe /C rmdir "{value "ContentLocation" of key "HKLM\SOFTWARE\BigFix\Enterprise Server\GatherService" of registry}" /S /Q
if {exit code of action = 0}
else exit 17
endif
// set starting time
setting "_BESClient_PauseWhile"="{now as string}" on "{parameter "action issue date" of action}" for client
// PAUSE until the bfsites directory is gone or 5 minutes has passed.
pause while {(exists folder (value "ContentLocation" of key "HKLM\SOFTWARE\BigFix\Enterprise Server\GatherService" of registry as string)) AND (now - (value of setting "_BESClient_PauseWhile" of client as string as time)) < 5*minute}
waithidden cmd.exe /C mkdir "{value "ContentLocation" of key "HKLM\SOFTWARE\BigFix\Enterprise Server\GatherService" of registry as string}"
if {exit code of action = 0}
else exit 18
endif
waithidden cmd.exe /C net start besrelay
if {exit code of action = 0}
else exit 19
endif
// if for some reason the BES Relay hasn't started yet, fail here
if{exists running service "BESRelay"}
else exit 20
endif
// then restart the BES Client
delete __appendfile
appendfile @echo off
appendfile echo Your administrator is restarting the BES Client... Please Wait...
appendfile net stop BESClient
appendfile net start BESClient
delete clientRestart.bat
if {exit code of action = 0}
else exit 21
endif
copy __appendfile clientRestart.bat
if {exit code of action = 0}
else exit 22
endif
runhidden cmd.exe /C clientRestart.bat
if {exit code of action = 0}
else exit 23
endif
elseif {unix of operating system}
//Stop the Relay Service Running
waithidden service besrelay stop
if {exit code of action = 0}
else exit 1
endif
// allow time for relay to stop
parameter "startTime"="{now}"
pause while { (now-time(parameter "startTime") < 180*second) }
// Create a backup of the sites folder, just in case you need it
waithidden cp -R "/var/opt/BESRelay/wwwrootbes/bfmirror/bfsites" "/var/opt/BESRelay/wwwrootbes/bfmirror/bfsites_bak"
if {exit code of action = 0}
else exit 2
endif
//Allow time to copy the folder and files before deleting
parameter "startTime2"="{now}"
pause while { (now-time(parameter "startTime2") < 300*second) }
waithidden rm -rf "/var/opt/BESRelay/wwwrootbes/bfmirror/bfsites/*"
if {exit code of action = 0}
else exit 3
endif
//Create a backup of the files
waithidden mv "/var/opt/BESRelay/Mirror Server/inbox/bfemapfile.xml" "/var/opt/BESRelay/Mirror Server/inbox/bfemapfile.xml.bak"
if {exit code of action = 0}
else exit 4
endif
waithidden mv "/var/opt/BESRelay/Mirror Server/inbox/GatherState.xml" "/var/opt/BESRelay/Mirror Server/inbox/GatherState.xml.bak"
if {exit code of action = 0}
else exit 5
endif
//Remove the original files
waithidden rm "/var/opt/BESRelay/Mirror Server/inbox/bfemapfile.xml"
if {exit code of action = 0}
else exit 6
endif
waithidden rm "/var/opt/BESRelay/Mirror Server/inbox/GatherState.xml"
if {exit code of action = 0}
else exit 7
endif
//Create new GatherState file
createfile until end
<?xml version= "1.0"?>
<GatherStatus> </GatherStatus>
end
delete "/var/opt/BESRelay/Mirror Server/inbox/GatherState.xml"
if {exit code of action = 0}
else exit 8
endif
copy __createfile "/var/opt/BESRelay/Mirror Server/inbox/GatherState.xml"
if {exit code of action = 0}
else exit 9
endif
//Create new BFE Map file
createfile until end
<?xml version="1.0"?>
<URLtoID NextID="1"> </URLtoID>
end
delete "/var/opt/BESRelay/Mirror Server/inbox/bfemapfile.xml"
if {exit code of action = 0}
else exit 10
endif
copy __createfile "/var/opt/BESRelay/Mirror Server/inbox/bfemapfile.xml"
if {exit code of action = 0}
else exit 11
endif
//Start the BESRelay service
waithidden service besrelay stop
if {exit code of action = 0}
else exit 24
endif
endif