Need to create a While loop on deployment for when an image has not been assigned
-
HI guys
After the host has been registered and is ready for deployment I need to create a While loop to “pause” the deployment until and image has been assigned.
I have tried to create a while loop using " while the $OSID = null then sleep 200 " but this does not seem to work.
What is the correct way of doing this?
-
@zaboxmaster As we have dozens of new posts every day you might want to include some more information in your posts to make it easier for us to follow. Due to the lack of information I had a look at your earlier posts and my guess is you are still working on modifying fog.man.reg. Is that right?
Which version of FOG do you use by the way?
I have tried to create a while loop using " while the $OSID = null then sleep 200 " but this does not seem to work.
Please post the exact code you have tried and the result you got!
If you seem to have issues with the bash scripting syntax then search the web and you’ll find hundreds of great tutorials on how to do while loops!
-
@zaboxmaster said in Need to create a While loop on deployment for when an image has not been assigned:
" while the $OSID = null then sleep 200 "
I’m little confused why the OSID would not be assigned since you should pick the image as part of registration. I suppose you could use OSID to check to set if its set but wouldn’t the image id be more appropriate? If the image ID is not set then there is no image assigned.
Next as I mentioned in another thread, as I remember your while loop doesn’t do anything to update OSID and I don’t know if that variable is dynamic enough for it to be set in another part of FOG that it will fall through to your local variable. Possibly making that curl call to the hostinfo php page and then updating the variables will do it. I don’t know without really looking at the code. But the $OSID variable is local to the master fog script and is set with kernel parameters or the hostinfo.php page. I don’t think its updated dynamically, but I could be wrong.
While its a matter of programming style but couldn’t this
while $OSID = null
be written as this
while “${OSID}” -eq “”
But you will still have the issue of $OSID not being updated once the master fog script starts.
-
@zaboxmaster said in Need to create a While loop on deployment for when an image has not been assigned:
while the $OSID = null then sleep 200
That’s because you’re setting the $OSID to null in your while loop, so it will never end.
A single = means set value to
Double = (==) means compare strings
In bash, if you want to check if a variable is ‘null’, you want to do something like (not sure if syntax is 100% correct) (-z checks if the variable is null)
while [[ -z "$OSID" ]] do sleep 200 done
-
Sorry I have taken so long to respond.
Okay so to start I am editing the fog.man.reg file. I have do this with help from George.
I have taken away the option to select which image to deploy this was done because, non technical people are using the system and I will decide which image to install for them. I have modified my fog.man.reg file to go straight into the deployment with out rebooting by call on the fog.download. This works fine but what I am looking for is a way of not proceeding to the fog.download file until I have remotely assign an image to be deployed.
So regarding the while loop
I have tried the following commands in the fog.man.reg file:
while [[ -z “$OSID”]]; do
echo “Please wait”
sleep 60
done
(this failed as the syntax is incorrect)while $OSID==“0” ; do
I have also looked through the fog.checkin file and found a command that i put into the fog.checkin file
while [[-z $osid]]; do
echo “Please Wait”
[[ -z $deployed ]] && determineOS “$osid”
sleep 60
doneDoes this help ?
-
@zaboxmaster So what doesn’t work?
Does it not wait? Does it get stuck on waiting? It’s unclear which part “doesn’t work”
-
@Quazz Sorry it skips right past and continues. Its does not pause or wait.
-
@zaboxmaster Alright. I do think $osid should be in lowercase to start off with.
Does the checkin file work or does that one also not work?
All that said, I’m not entirely sure if this will work, though I admit my knowledge in this area isn’t great.
I don’t know if the osid is ever even passed into this area of FOS.
The imageid might be a better bet.
-
@Quazz Okay so I have tried using Imageid but in the fog.man.reg, I will try this in the fog.checkin file. As osid in the fog.checkin did not work either. It just skipped through
One thing I am not sure of is how the following works,
[[ -z $deployed ]] && determineOS “$osid”
I would think that hold the key
-
@zaboxmaster said in Need to create a While loop on deployment for when an image has not been assigned:
@Quazz Okay so I have tried using Imageid but in the fog.man.reg, I will try this in the fog.checkin file. As osid in the fog.checkin did not work either. It just skipped through
One thing I am not sure of is how the following works,
[[ -z $deployed ]] && determineOS “$osid”
I would think that hold the key
So I tried the following
while [[ $imageid -le 10 ]]; do
if [[ -z “$imageid” ]]
then
echo “Please Wait”
sleep 60
fi
doneSorry i really do not have the greatest bash skills. But it works but the problem is I need a way to check the variable. In the loop. This is where i get really stuck. Would a curl command to the server to check the variable work ? If so what would that command be ?
-
By any chance do you know where the determineOS function is located ?
-
@zaboxmaster
/usr/share/fog/lib/funcs.sh