Monday, April 29, 2024
 Popular · Latest · Hot · Upcoming
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 493  / 2 Years ago, fri, may 20, 2022, 12:18:47

I have a service that is started by a script /etc/init.d/foo. When a certain CIFS share (//fileserver/multimedia on /home/username/multimedia type cifs) becomes unavailable for any reason (unmounted, network down, cosmic rays,...), then I want the service foo to be stopped automatically. When the share is available again, then I want the service foo to (re)start automatically.
My criterium for "available" is: being able to access the files on the share.


How do I do that?


More From » mount

 Answers
2

My criterium for "available" is: being able to access the files on the
share.



You can create a test file on the mount like so:


touch /home/username/multimedia/testfile

Then run a bash script to check for the accessibility of that test file every 60 seconds like so:


#!/bin/bash
# Set the full path to the test file between " " in the next line
file="/home/username/multimedia/testfile"
while true; do
if [ -f "$file" ]; then
echo "File is available"
# Your command/s here when the files on the mount are accessible.
elif [ ! -f "$file" ]; then
echo "File is NOT available"
# Your command/s here when the files on the mount are NOT accessible.
fi
sleep 60
done

[#667] Saturday, May 21, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tubequ

Total Points: 11
Total Questions: 113
Total Answers: 115

Location: Equatorial Guinea
Member since Thu, Oct 7, 2021
3 Years ago
;