mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-23 17:06:16 -04:00
Revert "scripts: Various shell script cleanups (#4008)"
This reverts commit fba4fd5314
.
The series of commits I made for PR #4008 were squashed into a single
commit and rebased. Somewhere along the way a mistake was made in a
merge conflict resolution, resulting in some bad code in
`bin/buildForWindows.sh`. This commit reverts the bad squashed commit.
This commit is contained in:
parent
02af7d0c2d
commit
9ffb2ccfb0
5 changed files with 132 additions and 129 deletions
|
@ -1,11 +1,10 @@
|
|||
#!/bin/sh
|
||||
|
||||
# This script ensures that ep-lite is automatically restarting after
|
||||
# an error happens
|
||||
#This script ensures that ep-lite is automatically restarting after an error happens
|
||||
|
||||
# Handling Errors
|
||||
# 0 silent
|
||||
# 1 email
|
||||
#Handling Errors
|
||||
# 0 silent
|
||||
# 1 email
|
||||
ERROR_HANDLING=0
|
||||
# Your email address which should receive the error messages
|
||||
EMAIL_ADDRESS="no-reply@example.com"
|
||||
|
@ -16,54 +15,54 @@ TIME_BETWEEN_EMAILS=600 # 10 minutes
|
|||
|
||||
# DON'T EDIT AFTER THIS LINE
|
||||
|
||||
pecho() { printf %s\\n "$*"; }
|
||||
log() { pecho "$@"; }
|
||||
error() { log "ERROR: $@" >&2; }
|
||||
fatal() { error "$@"; exit 1; }
|
||||
|
||||
LAST_EMAIL_SEND=0
|
||||
|
||||
# Move to the folder where ep-lite is installed
|
||||
cd "$(dirname "$0")"/..
|
||||
|
||||
# Check if a logfile parameter is set
|
||||
LOG="$1"
|
||||
[ -n "${LOG}" ] || fatal "Set a logfile as the first parameter"
|
||||
|
||||
#Move to the folder where ep-lite is installed
|
||||
cd $(dirname $0)
|
||||
|
||||
#Was this script started in the bin folder? if yes move out
|
||||
if [ -d "../bin" ]; then
|
||||
cd "../"
|
||||
fi
|
||||
|
||||
#Check if a logfile parameter is set
|
||||
if [ -z "${LOG}" ]; then
|
||||
echo "Set a logfile as the first parameter"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
shift
|
||||
while [ 1 ]
|
||||
do
|
||||
#Try to touch the file if it doesn't exist
|
||||
if [ ! -f ${LOG} ]; then
|
||||
touch ${LOG} || ( echo "Logfile '${LOG}' is not writeable" && exit 1 )
|
||||
fi
|
||||
|
||||
while true; do
|
||||
# Try to touch the file if it doesn't exist
|
||||
[ -f "${LOG}" ] || touch "${LOG}" || fatal "Logfile '${LOG}' is not writeable"
|
||||
#Check if the file is writeable
|
||||
if [ ! -w ${LOG} ]; then
|
||||
echo "Logfile '${LOG}' is not writeable"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if the file is writeable
|
||||
[ -w "${LOG}" ] || fatal "Logfile '${LOG}' is not writeable"
|
||||
#Start the application
|
||||
bin/run.sh $@ >>${LOG} 2>>${LOG}
|
||||
|
||||
# Start the application
|
||||
bin/run.sh "$@" >>${LOG} 2>>${LOG}
|
||||
|
||||
TIME_FMT=$(date +%Y-%m-%dT%H:%M:%S%z)
|
||||
|
||||
# Send email
|
||||
if [ "$ERROR_HANDLING" = 1 ]; then
|
||||
#Send email
|
||||
if [ $ERROR_HANDLING = 1 ]; then
|
||||
TIME_NOW=$(date +%s)
|
||||
TIME_SINCE_LAST_SEND=$(($TIME_NOW - $LAST_EMAIL_SEND))
|
||||
|
||||
if [ "$TIME_SINCE_LAST_SEND" -gt "$TIME_BETWEEN_EMAILS" ]; then
|
||||
{
|
||||
cat <<EOF
|
||||
Server was restarted at: ${TIME_FMT}
|
||||
The last 50 lines of the log before the server exited:
|
||||
|
||||
EOF
|
||||
tail -n 50 "${LOG}"
|
||||
} | mail -s "Etherpad restarted" "$EMAIL_ADDRESS"
|
||||
if [ $TIME_SINCE_LAST_SEND -gt $TIME_BETWEEN_EMAILS ]; then
|
||||
printf "Server was restarted at: $(date)\nThe last 50 lines of the log before the error happens:\n $(tail -n 50 ${LOG})" | mail -s "Pad Server was restarted" $EMAIL_ADDRESS
|
||||
|
||||
LAST_EMAIL_SEND=$TIME_NOW
|
||||
fi
|
||||
fi
|
||||
|
||||
pecho "RESTART! ${TIME_FMT}" >>${LOG}
|
||||
echo "RESTART!" >>${LOG}
|
||||
|
||||
# Sleep 10 seconds before restart
|
||||
#Sleep 10 seconds before restart
|
||||
sleep 10
|
||||
done
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue