-
Notifications
You must be signed in to change notification settings - Fork 0
/
shutdown.sh
executable file
·146 lines (93 loc) · 3.46 KB
/
shutdown.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/bin/sh
########################################################################################################################################################################
#
# Script Name: shutdown.sh
#
# Description: This script will stop the Folding@Home service, and check if there are users on the KF2 server. If there are no users, the server will shutdown
#
########################################################################################################################################################################
# Clear screen for consumption
clear
# Confirm user is running as root
if [ `whoami` != 'root' ]
then
echo "You must be root to run this script. This script will now exit."
exit
fi
# Variables
email=$(cat /home/git/scripts/email.txt)
# Define shutdown log variable
#touch /var/log/shutdown_logs/shutdown_log_$(date +\%c).txt
log=/var/log/shutdown_logs/shutdown_log_$(date +\%c).txt
# Confirm user really wants to shutdown system
hostname=$(hostname)
echo
while true; do
read -p "Are you sure you want to shutdown $hostname? " yn
case $yn in
[Yy]* ) break;;
[Nn]* ) echo; echo "This script will now exit."; echo; exit;;
* ) echo "Please answer yes or no.";;
esac
done
# Confirm user has gracefully stopped the KF2 server
echo
while true; do
read -p "Have you gracefully stopped the KF2 server? (y/n): " yn
case $yn in
[Yy]* ) break;;
[Nn]* ) echo; echo "This script will now exit."; echo; exit;;
* ) echo "Please answer yes or no.";;
esac
done
# Prompt that shutdown script is running
echo | tee -a "$log"
echo "################################" | tee -a "$log"
echo | tee -a "$log"
echo "### Starting system shutdown ###" | tee -a "$log"
echo | tee -a "$log"
echo "################################" | tee -a "$log"
#sleep for consumption
sleep 2
#Stop Folding@Home service
echo | tee -a "$log"
echo | tee -a "$log"
echo "Attempting to stop Folding@Home client..." | tee -a "$log"
echo | tee -a "$log"
systemctl stop fahclient
#Confirm Folding@Home service is stopped
fah_status=$(systemctl status fahclient | grep -i 'running' | wc -l)
#echo "Folding@Home Status:" $fah_status | tee -a "$log"
if [ "$fah_status" == "0" ]; then
echo "SUCCESS: fahclient stopped gracefully" | tee -a "$log"
continue
else
echo "fahclient did not stop gracefully, this script will now exit" | tee -a "$log"
exit
fi
# Sleep for consumption
sleep 2
# Start KF2 logic
#echo | tee -a "$log"
#echo "------------------------------------------------------------" | tee -a "$log"
#echo | tee -a "$log"
#echo "Checking if there are possible active users on KF2 game server..." | tee -a "$log"
#echo | tee -a "$log"
#Check if there are any users on the KF2 server
#kf_check=$(tail -3000 /home/steam/Steam/Killing_Floor_2/KFGame/Logs/Launch.log | grep "GetLivingPlayerCount" | wc -l)
#if [ "$kf_check" -eq 0 ]; then
# echo "SUCCESS: No active users found" | tee -a "$log"
# continue
#else
# echo "ACTION REQUIRED: Possible users were identified. Manually check to confirm there are no active users on the KF2 server. This script will now exit" | tee -a "$log"
# echo | tee -a "$log"
# cat | tee -a "$log"
# exit
#fi
# Sleep for consumption
sleep 3
# Shutdown the system
echo | tee -a "$log"
echo "The system will now shutdown" | tee -a "$log"
#cat "$log" | mailx -s "cloud1 Reboot Log" "$email"
#shutdown now