Remove FOG task
-
Hello FOG Team,
OS: Kubuntu 20.04 LTS
FOG server: 1.5.9
FOG client: 0.12.0I have a wrapper service in place that decides if the FOG client service should run or not if a certain condition is met, e.g. the laptop is attached to a specific switch in the building.
Now while this is working as expected, the problem is that the task sent to this PC is still present at the FOG server because the “Task finished” signal has not been send.Is there a way to mimic the FOG client behavior and send “Task finished” requests as a response to an incoming task?
I looked at the Zazzles code and how it is done in the Snapin case in the fog-client code, but I could not completely figure it out where the information about the taskId and so on is coming from to put the correct php request together.Best,
Markus -
@mstabrin said in Remove FOG task:
the problem is that the task sent to this PC is still present at the FOG server because the “Task finished” signal has not been send
Does the fog-client actually communicate with the FOG server to receive the task infos? Is it a snapin task or a deploy task?
You might explain in more detail why you use a wrapper and how this works so we can better understand what is needed in your case.
If you know the task job ID you can mimic the call seen here: https://github.com/FOGProject/fog-client/blob/master/Modules/SnapinClient/SnapinClient.cs#L125
-
@Sebastian-Roth Ideally every incoming task just gets ignored by the client and gets marked as done at the server.
I checked how it is done within the FOS in bin/fog.nonimagecomplete and figured everything out!
Thank you for pointing me to the part of the code that does the snapin part!
I will leave my setup here for reference on a Kubuntu 20.04 LTS system (Bash v 5.0.17(1)):FOG Client running OS
Systemctl settings
# Disable FOGService on startup systemctl disable FOGService.service # Enable FOGMonitor on startup (manages FOGService) systemctl enable FOGMonitor.timer
Systemctl setup
/lib/systemd/system/FOGMonitor.service
[Unit] Description=FOGMonitor job; Manages the status of the FOGService.service Before=FOGService.service [Service] ExecStart=bash /opt/fog-service-monitor/monitor.sh [Install] WantedBy=multi-user.target
/lib/systemd/system/FOGMonitor.timer
[Unit] Description=Check required FOG status every minute [Timer] OnBootSec=0 OnCalendar=minutely [Install] WantedBy=basic.target
/opt/fog-service-monitor/monitor.sh
#!/usr/bin/bash function condition(){ if [[ # PUT YOUR ENABLE FOG SERVICE AND STOP TIMER SERVICE CONDITION HERE ]] then # This is the behaviour like systemctl enable FOGService return 0 elif [[ # PUT YOUR ENABLE FOG SERVICE CONDITION HERE ]] then # This is the ENABLE FOG SERVICE condition return 1 else # This is the DISABLE FOG SERVICE condition return 2 fi } # Run the condition check and do things based on the return value condition return_value=${?} if [[ ${return_value} -eq 0 ]] then # Just like systemctl enable FOGService.service systemctl stop FOGMonitor.timer systemctl start FOGService.service exit 0 elif [[ ${return_value} -eq 1 ]] then mode=start ignore_incoming=false elif [[ ${return_value} -eq 2 ]] then mode=stop ignore_incoming=true else # Consistency check between the return values of the condition function and this echo "Situation not defined, yet. Define it here after you added more conditions to the condition function" exit 1 fi systemctl ${mode} FOGService.service web=http://FOG_SERVER_ADDRESS/fog if [[ ${ignore_incoming} == true ]] then for interface_name in /sys/class/net/* do mac_address=$(cat ${interface_name}/address) if echo ${mac_address} | grep -q '00:00:00:00:00' then continue fi uuid=$(dmidecode -s system-uuid) # Post_Wipe seems also be able to mark every tasks as complete which is not a snapin. curl -Lks --data "sysuuid=${uuid,,}&mac=${mac_address}" ${web}/service/Post_Wipe.php # Remove possible snapin tasks snapin_id=$( curl -Lks --data "mac=${mac_address}" ${web}/service/snapins.checkin.php \ | grep -o 'JOBTASKID=[0-9]*' \ | grep -o [0-9]* ) if [[ ${?} -eq 0 ]] then curl -Lks --data "mac=${mac_address}&taskid=${snapin_id}&exitcode=0" ${web}/service/snapins.checkin.php fi done fi
Best,
Markus -
@mstabrin Sounds like you were able to make it work. Though I still don’t understand why you add this wrapper in the first place.
-
@Sebastian-Roth Yeah I made it work and let me explain to you why I wanted it
I say wanted, because it is just making the whole process easier for us to maintain and execute.We have a bunch of laptops that we use for workshops and borrow to students.
They are stored in a laptop charging cart with an attached switch so that they are exposed to the FOG server and WoL is used for imaging.
Afterwards, the laptops are actually used within the same network that has a connection to the FOG server.Now we could have done the tedious and possibly error prone way:
- On demand, select the laptops needed and that are still in the cage according to some documentation material manually and add them to a new FOG group.
- Setup a deploy task; wait to finish
- Provide the laptop to the user
- Receive the laptop from the user after usage
- Choose the same group and provide the “coming home” image that does wipe the laptop from all data
While this is a possible way of doing it, I fear the “worst case” scenario: By accident add an already provided laptop to the group and somewhere in the building you will hear a very loud scream because somebodies PhD Thesis just got remove from the harddrive due to a FOG task formatting the drive.
Therefore, I want those laptops to completely ignore FOG when they left the switch located in the cart, but are available for the next imaging round by just plugging it into the correct switch.
My FOGMonitor job is constantly checking the switch that the laptop is attached to and is ignoring all incoming tasks by ignoring them and additionally delete the task from the FOG server.This has the additional benefit that the workflow changes as follows:
- Select the laptop group containing all laptops at the FOG server
- Deploy the image to every laptop, but only those attached to the switch will listen
- Provide the laptops
- Reiceve the laptops
- Send all laptops the coming home signal
You might need to remove pending tasks from the laptops that are not conneted to the network at all.
This should work great for us, since we barely have to image different laptops for different purposes exactly at the same time,
And since imaging is so fast, it is also not that bad if all of them are imaged or only the subset that is actually needed.I hope this makes things a bit more clear
best,
Markus -
For completeness, I will also provide the postinitscript I wrote to ignore the task on reboot.
It is the same condition I used abovecondition return_value=${?} if [[ ${return_value} -eq 0 ]] then # Continue with normal imaging : elif [[ ${return_value} -eq 1 ]] then # Continue with normal imaging : elif [[ ${return_value} -eq 2 ]] then # Abort imaging . /bin/fog.nonimgcomplete ${mac} exit 0 else echo 'Return value not yet known' exit 1 fi
-
@mstabrin Yes makes sense to me now. Just a very specific case.
-
@sebastian-roth It sure is!
But I love how flexible FOG is with its postinit and postdownload scripts and the API functionality.
I can really create everything I need, really things as complex as this problem here, by simple using the FOS binaries as building blocks.I have to say that FOG is indeed an amazing product!