-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxtreemfs_slurm_rstop.sh
executable file
·124 lines (98 loc) · 2.91 KB
/
xtreemfs_slurm_rstop.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/bin/bash
###############################################################################
# Author: Robert Bärhold
# Date: 18.05.2015
#
# Stop script for the Xtreemfs Server.
# "rstop", cause it's called remote on a specific slurm node.
#
# Call:
# ./xtreemfs_slurm_rstop.sh /path/to/env.sh (DIR|MRC|OSD*) [-savelogs]
#
# Parameter:
# $1 path to source file (env.sh)
# $2 Server name (instance)
# $3 [optional] "-savelogs"
#
###############################################################################
if [[ ! "$#" -ge 2 ]]; then
echo "Wrong parameter count!"
echo "Expecting at least 2 arguments; found: $#"
exit 1
fi
BASEDIR=$(dirname $0)
SOURCE_FILE="$1"
SERVER_NAME="$2"
SAVE_LOG="$3"
if [[ ! -f $SOURCE_FILE ]]; then
echo "SOURCE_FILE $SOURCE_FILE not found!"
exit 1;
fi
source $SOURCE_FILE
CURRENT_LOCAL_FOLDER=$(substitudeJobID "$LOCAL_DIR_GENERIC")
# Save logs to current job folder
function saveLogs() {
CURRENT_JOB_FOLDER=$(substitudeJobID "$CURRENT_JOB_FOLDER_GENERIC")
SERVER_LOG=$(substitudeName "$LOG_FILENAME_GENERIC" "$SERVER_NAME")
# if server log exists, create backup folder (if not exists) and copy log
if [[ -f "$CURRENT_LOCAL_FOLDER/$SERVER_LOG" ]]; then
mkdir -p "$CURRENT_JOB_FOLDER/savedLogs"
cp "$CURRENT_LOCAL_FOLDER/$SERVER_LOG" "$CURRENT_JOB_FOLDER/savedLogs/$SERVER_LOG"
else
echo "Couldn't save log file ($SERVER_LOG), because it doesn't exist!"
return 1
fi
return 0
}
# Killing the process of the xtreemfs server using the saved process id (pid)
function stopServer() {
SERVER_PID=$(substitudeName "$PID_FILENAME_GENERIC" "$SERVER_NAME")
if [[ -f "$CURRENT_LOCAL_FOLDER/$SERVER_PID" ]]; then
outputDebug -n "Stopping XtreemFS Process: ${SERVER_PID%.*} ..."
result=0
if [[ -e "/proc/$(<"$CURRENT_LOCAL_FOLDER/$SERVER_PID")" ]]; then
kill $KILLTERM $(<"$CURRENT_LOCAL_FOLDER/$SERVER_PID")
result=$?
fi
if [[ "$result" -eq 0 ]]; then
outputDebug "success"
else
outputDebug "failed"
fi
else
echo "PID file ($CURRENT_LOCAL_FOLDER/$SERVER_PID) not found!"
return 1
fi
return 0
}
# stop watchdog
function stopWatchdog(){
WATCHDOG_PID=$(substitudeName "$PID_FILENAME_GENERIC" "watchdog")
if [[ -f "$CURRENT_LOCAL_FOLDER/$WATCHDOG_PID" ]]; then
outputDebug -n "Stopping Watchdog for XtreemFS on $(hostname) ..."
result=0
if [[ -e "/proc/$(<"$CURRENT_LOCAL_FOLDER/$WATCHDOG_PID")" ]]; then
kill -SIGKILL $(<"$CURRENT_LOCAL_FOLDER/$WATCHDOG_PID")
result=$?
fi
if [[ "$result" -eq 0 ]]; then
outputDebug "success"
else
outputDebug "failed"
fi
else
echo "PID file ($CURRENT_LOCAL_FOLDER/$WATCHDOG_PID) not found!"
return 1
fi
return 0
}
if [[ "$SERVER_NAME" == "watchdog" ]]; then
stopWatchdog
else
stopServer
fi
RESULT=$?
if [[ ! -z "$SAVE_LOG" ]] && [[ "$SAVE_LOG" == "-savelogs" ]]; then
saveLogs
fi
exit $RESULT