#!/bin/bash #################################################################################################### #### author: SlickStack ############################################################################ #### link: https://slickstack.io ################################################################### #### mirror: http://mirrors.slickstack.io/bash/ss-reboot.txt ####################################### #### path: /var/www/ss-reboot ###################################################################### #### destination: n/a (not a boilerplate) ########################################################## #### purpose: Force reboots the server but is rate-limited so it can be used within scripts ######## #### module version: Ubuntu 20.04 LTS ############################################################## #### sourced by: ss core cron jobs, ss core bash scripts ########################################### #### bash aliases: ss reboot ####################################################################### #################################################################################################### ## include SlickStack configuration ## source /var/www/ss-config ## include SlickStack functions ## source /var/www/ss-functions #################################################################################################### #### SS-Reboot: MESSAGE (Begin) #################################################################### #################################################################################################### ## MESSAGE ## echo -e "${PURPLE}Running ss-reboot: Force reboots the server but is rate-limited so it can be used within scripts... ${NOCOLOR}" sleep "$SLEEP_MESSAGE_BEGIN" #################################################################################################### #### SS-Reboot: Force Reboot The Server ############################################################ #################################################################################################### ## here we check to see if ss-reboot was run in the past 60 minutes or not before running ## ## this protects you from consecutive (abusive) reboots e.g. if run via ss-worker ## ## FUTURE: customize via ss-config options ## ## reboot only if ss-reboot was not run in past 60 minutes ## if [[ ! -f "/var/www/meta/.timestamp-ss-reboot" ]] || [[ -n $(find "/var/www/meta/.timestamp-ss-reboot" -amin +60) ]]; then touch /var/www/meta/.timestamp-ss-reboot /bin/bash -c "/sbin/reboot" else echo -e "" echo -e "${YELLOW}It appears your server has rebooted already within the last 60 minutes, ${NOCOLOR}" echo -e "${YELLOW}therefore ss-reboot has exited without rebooting at this time. ${NOCOLOR}" echo -e "" fi #################################################################################################### #### SS-Reboot: Touch Timestamp File (End Script) ################################################## #################################################################################################### ## this is a dummy timestamp file that will remember the last time this script was run ## ## it can be useful for developer reference and is sometimes used by SlickStack ## ## script timestamp ## # touch /var/www/meta/.timestamp-ss-reboot ## DO NOT ENABLE HERE #################################################################################################### #### SlickStack: External References Used To Improve This Script (Thanks, Interwebz) ############### #################################################################################################### ## Ref: https://askubuntu.com/questions/789058/how-to-make-sbin-shutdown-sbin-reboot-etc-require-sudo-again-in-16-04 ## Ref: https://unix.stackexchange.com/questions/46541/how-can-i-use-bashs-if-test-and-find-commands-together ## Ref: https://askubuntu.com/questions/441969/what-is-the-difference-between-reboot-and-shutdown-r ## Ref: https://askubuntu.com/questions/1023939/what-kind-of-link-to-bin-systemctl-is-sbin-reboot ## Ref: https://unix.stackexchange.com/questions/467552/reboot-over-ssh ## Ref: https://stackoverflow.com/questions/27452790/bash-reboot-command-not-found ## Ref: https://superuser.com/questions/571681/rebooting-linux-from-script ## Ref: https://www.tecmint.com/35-practical-examples-of-linux-find-command/ ## Ref: https://www.tutorialdba.com/2018/03/linux-ctimemtimeatimecminaminmmin.html ## Ref: https://askubuntu.com/questions/442575/how-to-check-when-the-ubuntu-server-was-rebooted ## Ref: https://www.cyberciti.biz/tips/linux-last-reboot-time-and-date-find-out.html ## Ref: https://serverfault.com/questions/255911/detecting-restart-since-last-run-in-a-shell-script-on-linux ## SS_EOF