#!/bin/sh # This script ensures that ep-lite is automatically restarting after # an error happens # Handling Errors # 0 silent # 1 email ERROR_HANDLING=0 # Your email address which should receive the error messages EMAIL_ADDRESS="no-reply@example.com" # Sets the minimum amount of time between the sending of error emails. # This ensures you do not get spammed during an endless reboot loop # It's the time in seconds 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 Etherpad base directory. MY_DIR=$(try cd "${0%/*}" && try pwd -P) || exit 1 try cd "${MY_DIR}/../.." # Check if a logfile parameter is set LOG="$1" [ -n "${LOG}" ] || fatal "Set a logfile as the first parameter" shift 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 [ -w "${LOG}" ] || fatal "Logfile '${LOG}' is not writeable" # Start the application src/bin/run.sh "$@" >>${LOG} 2>>${LOG} TIME_FMT=$(date +%Y-%m-%dT%H:%M:%S%z) # 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 <>${LOG} # Sleep 10 seconds before restart sleep 10 done