blob: e722b3a180d12a3698d6ca1b87db6bb74378c623 (
plain)
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
|
#!/bin/sh
if [ $# -ne 2 ]; then
echo "Usage: kill_n_check.sh <pid file path> killed|restarted"
exit 0
fi
pid_path="$1"
expected_result="$2"
if [ -z "$pid_path" -o ! -r "$pid_path" ]; then
echo "Error: invalid PID path ($pid_path) or PID file does not exist."
exit 0
fi
if [ "$expected_result" != "killed" -a \
"$expected_result" != "restarted" ]; then
echo "Error: expected result must be either 'killed' or 'restarted'."
exit 0
fi
# echo "PID path: '$pid_path'"
original_pid=`cat "$pid_path"`
# echo "Original PID: $original_pid"
echo "Killing the process..."
kill -9 $original_pid
echo "Sleeping..."
sleep 3
new_pid=""
[ -r "$pid_path" ] && new_pid=`cat "$pid_path"`
# echo "New PID: $new_pid"
if [ "$expected_result" = "restarted" ]; then
if [ -z "$new_pid" ]; then
echo "Error: the process was killed."
exit 0
fi
if [ "$original_pid" -eq "$new_pid" ]; then
echo "Error: the process was not restarted."
exit 0
fi
echo "Success: the process was restarted."
exit 0
else # $expected_result = killed
if [ "$new_pid" -a "$new_pid" -ne "$original_pid" ]; then
echo "Error: the process was restarted."
exit 0
fi
echo "Success: the process was killed."
exit 0
fi
|