-
Notifications
You must be signed in to change notification settings - Fork 0
/
reboot.sh
executable file
·143 lines (105 loc) · 3.61 KB
/
reboot.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
#!/bin/sh
########################################################################################################################################################################
#
# Script Name: reboot.sh
#
# Description: This script will stop the Folding@Home service, and check if there are users on the KF2 server.
#
########################################################################################################################################################################
email=$(cat /home/git/scripts/email.txt)
# 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
# Clear screen for consumption
clear
# Confirm user wants to reboot system
hostname=$(hostname)
echo
while true; do
read -p "Are you sure you want to reboot $hostname? (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
# Confirm user has gracefully stopped the KF2 server
echo
while true; do
read -p "Has the KF2 server been gracefully stopped? (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
# Create reboot log file
#touch /var/log/reboot_logs/reboot_log_$(date +\%m.\%d.\%Y).txt
log=/var/log/reboot_logs/reboot_log_$(date +\%c).txt
# Sleep for consumption
sleep 2
# Prompt that reboot script is running
echo | tee -a "$log"
echo "##############################" | tee -a "$log"
echo | tee -a "$log"
echo "### Starting System Reboot ###" | 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
# Add wait to allow FAHClient to stop
sleep 2
# Confirm Folding@Home service is stopped
#fah_status=$(systemctl status fahclient)
#
#echo "Folding@Home Status:" $fah_status | tee -a "$log"
#echo | tee -a "$log"
#
#if [ "$fah_status" == "fahclient is not running" ]; 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
# 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 2
# Email user log file
#echo | tee -a "$log"
#echo "------------------------------------------------------------" | tee -a "$log"
#echo | tee -a "$log"
#echo "Sending log file to "$email"..." | tee -a "$log"
#echo | tee -a "$log"
#cat "$log" | mailx -s "Cloud1 Reboot Log" "$email"
# Perform reboot
echo | tee -a "$log"
echo "$hostname will now reboot" | tee -a "$log"
echo | tee -a "$log"
#reboot