I have a daemon that, when it's started, loads its data from a directory that happens to be a symlink. Periodically, new data is generated and the symlink updated. I want a bash script that will check if the current symlink is the same as the old one (that the daemon started with) and if not, restart the daemon. My current thought is:
if [[ ! -e $old_dir || $(readlink "$data_dir") == $(readlink "$old_dir") ]];
then
echo restart
...
ln "$(readlink "$data_dir")" "$old_dir" -sf
else
echo no restart
fi
The abstract requirement is: each time the script runs, it needs to check if a symlink on a given path now points to a something other than it did the last time, and if so do something. (The alternative would be to check if the data at the path has changed but I don't see that being any cleaner.) My questions:
$old_dir, where should I put the symlink?As for a good approach, I'm not sure. Seems plenty workable but weird.
I'd put old_dir in /var/local/projectname
EDIT: Without seeing enough to truly know if leading you down the wrong path, I somehow think the correct way to do this is to use spooling directories.
The way this works is:
Step 2 is the atomic handoff. Step 3 might have to be armored so processing the same file twice is harmless.
Then again, if you have something here like keeping a full history and the symlink refers to current you're doing it right already.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With