-
Notifications
You must be signed in to change notification settings - Fork 0
/
reboot.sh
48 lines (44 loc) · 1.62 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
#!/bin/bash
#############################################################
## Name : reboot.sh
## Version : 1.4
## Date : 2022-05-31
## Author : LHammonds
## Compatibility : Verified on Ubuntu Server 22.04 LTS
## Requirements : Run as root
## Purpose : Stop services and reboot server.
## Run Frequency : As needed
## Exit Codes : None
###################### CHANGE LOG ###########################
## DATE VER WHO WHAT WAS CHANGED
## ---------- --- --- ---------------------------------------
## 2013-01-07 1.0 LTH Created script.
## 2017-12-18 1.1 LTH Added logging.
## 2018-04-19 1.2 LTH Various minor changes.
## 2020-09-02 1.3 LTH Added broadcast notice to all connected SSH users.
## 2022-05-31 1.4 LTH Replaced echo statements with printf.
#############################################################
## Import standard variables and functions. ##
source /var/scripts/common/standard.conf
## Define local variables.
LogFile="${LogDir}/${Company}-reboot.log"
## Requirement Check: Script must run as root user.
if [ "$(id -u)" != "0" ]; then
## FATAL ERROR DETECTED: Document problem and terminate script.
printf "\nERROR: Root user required to run this script.\n"
printf "Type 'sudo su' to temporarily become root user.\n"
exit 1
fi
clear
printf "`date +%Y-%m-%d_%H:%M:%S` - Reboot initiated.\n" | tee -a ${LogFile}
${ScriptDir}/prod/servicestop.sh
## Broadcasting message to any other users logged in via SSH.
printf "WARNING: Rebooting server. Should be back online in 20 seconds.\n" | wall
printf "Rebooting...\n"
printf "3\n"
sleep 1
printf "2\n"
sleep 1
printf "1\n"
sleep 1
shutdown -r now