-
Notifications
You must be signed in to change notification settings - Fork 0
/
sshfs-wd.sh
executable file
·80 lines (66 loc) · 1.84 KB
/
sshfs-wd.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/bash
echo "sshfs-wd.sh start"
#base=$(readlink -f $(dirname "$0"))
#$(readlink -f $(dirname "$0"))/scripts/variables.sh
export base=$(readlink -f $(dirname "$0"))
source "$base/scripts/commons.sh"
command="$1"
if mkdir -p "$connectionConfigDir"; then
echo "Using config dir: $connectionConfigDir"
else
echo "Failed to create config dir: $connectionConfigDir"
exit 1
fi
if ls $connectionConfigDir/*.config 1> /dev/null 2>&1; then
echo "Some configs are in place..."
else
echo "No configs found in config folder (*.config). Exiting..."
exit 0
fi
# process configurations
for conf in "$connectionConfigDir"/*.config
do
if [ ! -f "$conf" ]; then
continue
fi
echo "Processing $conf"
killCycles=0
killMaxCycles=15
while :
do
instancePids=$(getSshfsWdInstancePids "$user" "$conf")
if [ ! -z "${instancePids}" ]; then
if (( killCycles == 0 )); then
if kill -SIGTERM $instancePids
then
echo "Sent SIGTERM to processes: ${instancePids}"
else
echo "Failed to send SIGTERM to processes: ${instancePids}"
exit 1
fi
fi
else
break
fi
if (( killCycles > killMaxCycles )); then
echo "We waited too much... processes appears to be stuck: ${instancePids}"
exit 1
fi
echo "waiting ${killCycles} / ${killMaxCycles}"
(( killCycles++ ))
sleep 1
done
if [ "$command" == "stop" ]; then # if stop command is passed then no new instances should be launched
continue
fi
configFileBasename=$(basename "$conf")
# start watch dog instance
( "$base"/scripts/sshfs-wd-instance.sh "$conf" 2>&1
if [ $? == "0" ] ; then
echo "${configFileBasename} started"
else
echo "ERROR during startup ${configFileBasename}"
fi
) >> "/tmp/sshfs_${user}_${configFileBasename}.log" &
done
echo "sshfs-wd.sh end"