Hi,
I deal with my problem, now crashed multicast clients can be stopped and relaunch automatically once session has finished.
The fact that any machine in our environnement use IP reservation made things easy.
I managed only crashed clients, but it would be easy to add a WOL or a client restart but I consider that if WOL or Client restart has not worked first there no reason it works better 1h later without any intervention.
If someone is interested by such a feature here is the script. It could be trigger every hour, this way whenever the multicast session is finished the client is reinstalled.
I used it in test environnement for now, so there could be some issues. I you find some or have any idea to make it better please share and I’ll correct it :
#!/bin/bash
# Infos
# Works on linux machine (tested on Ubuntu 22.04)
# Requirements:
# -sshpass installed
# -mysql table hostsIP with hosts names and IPs.
# -a modified init.xz containing a modified shadow file with a root password set inside (more informations here : https://wiki.fogproject.org/wiki/index.php?title=Modifying_the_Init_Image)
IFS=$'\n'
userToken='userToken'
fogToken='serverToken'
fogserver='fogServerIP'
rootPass='set password in shadow file of init.xz'
multicastSessions=$(curl -X 'GET' -s -L -H "fog-user-token: $userToken" -H "fog-api-token: $fogToken" http://$fogserver/fog/multicastsession/current | jq -r '.multicastsessions[].name')
#echo "curl -X 'GET' -s -L -H \"fog-user-token: $userToken\" -H \"fog-api-token: $fogToken\" http://$fogserver/fog/task/current | jq -r ."
for session in $multicastSessions;do
hostArray=()
group=$(echo $session | rev | cut -d' ' -f1 | rev)
groupHostsQty=$(curl -X 'GET' -s -L -H "fog-user-token: $userToken" -H "fog-api-token: $fogToken" http://$fogserver/fog/group/list | jq '.groups[] | select(.name == "'${group}'") | .hostcount')
currentHostQty=$(curl -X 'GET' -s -L -H "fog-user-token: $userToken" -H "fog-api-token: $fogToken" http://$fogserver/fog/task/current | jq '.tasks[] | select(.name == "'${session}'") | .host.name' | wc -l)
if [[ $groupHostsQty != $currentHostQty ]];then
hosts=$(curl -X 'GET' -s -L -H "fog-user-token: $userToken" -H "fog-api-token: $fogToken" http://$fogserver/fog/task/current | jq -r '.tasks[] | select(.host.name | startswith("'${group}'")) | .host.name')
for host in $hosts; do
hostIP=$(mysql fog -Bse "SELECT ip FROM hostsIP WHERE name = '$host'")
hostID=$(curl -X 'GET' -s -L -H "fog-user-token: $userToken" -H "fog-api-token: $fogToken" http://$fogserver/fog/task/current | jq -r '.tasks[] | select(.host.name == "'${host}'") | .host.id')
if [[ -z $taskID ]]; then
taskID=$(curl -X 'GET' -s -L -H "fog-user-token: $userToken" -H "fog-api-token: $fogToken" http://$fogserver/fog/task/current | jq -r '.tasks[] | select(.host.name == "'${host}'") | .id')
fi
if [[ -z $imageID ]]; then
imageID=$(curl -X 'GET' -s -L -H "fog-user-token: $userToken" -H "fog-api-token: $fogToken" http://$fogserver/fog/task/current | jq -r '.tasks[] | select(.host.name == "'${host}'") | .image.id')
fi
hostArray=("${hostArray[@]}" "$hostIP,$hostID")
done
echo "Task : $taskID"
curl -X "DELETE" -s -L -H "fog-user-token: $userToken" -H "fog-api-token: $fogToken" http://$fogserver/fog/task/$taskID/cancel
message="Multicast session still active"
while sessionActive=$(curl -X 'GET' -s -L -H "fog-user-token: $userToken" -H "fog-api-token: $fogToken" http://$fogserver/fog/multicastsession/current | jq -r '.multicastsessions[] | .name | select(contains("'${group}'"))'); [[ -n $sessionActive ]]; do
message="${message}."
sleep 1
done
for host in ${hostArray[@]}; do
hostIP=$(echo $host | cut -d',' -f1)
hostID=$(echo $host | cut -d',' -f2)
echo "Relaunch JOB for : $hostID ($hostIP)"
curl -X 'POST' -s -L -H "fog-user-token: $userToken" -H "fog-api-token: $fogToken" -d '{"taskTypeID": 1, "imageID": "'${imageID}'", "taskName": "$hostID : deploy", "shutdown": false, "debug": false, "deploySnapins": false, "wol": false}' http://$fogserver/fog/host/$hostID/task
echo "Reboot PC"
sshpass -p "$rootPass" ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null root@$hostIP 'nohup reboot -f > /dev/null 2>&1 & exit'
done
fi
done
Bye
Proc.