TARGET_JAR=
NEED_RESTART='n'
+MAIL_FROM_ADDRESS="minecraft+$( fqdn -f )@uhu-banane.de"
+MAIL_TO_ADDRESS="frank@brehm-online.com"
+MAIL_RETURN_ADDRESS="postmaster@brehm-online.com"
+
+MAIL_BODY=""
+
DESCRIPTION=$( cat <<-EOF
Update Micraft server .jar file.
EOF
)
+START_DATE=$( my_date )
+
detect_color
#------------------------------------------------------------------------------
CHOWN "${MC_USER}:${MC_GROUP}" "${TARGET_JAR}"
NEED_RESTART='y'
+ if [[ -n "${MAIL_BODY}" ]] ; then
+ MAIL_BODY+="\n"
+ fi
+ MAIL_BODY+="$( my_date ): Downloaded latest server.jar file as '${TARGET_JAR}'.\n"
+
}
#------------------------------------------------------------------------------
fix_symlinks() {
info "Checking symlink in '${CYAN}${MC_BACKUP_DIR}${NORMAL}' ..."
+ local symlink_was_set="n"
if [[ -e "${MC_SERVER_CUR_LINK_BASE}" ]] ; then
if [[ ! -h "${MC_SERVER_CUR_LINK_BASE}" ]] ; then
info "Symlink '${CYAN}${MC_SERVER_CUR_LINK_BASE}${NORMAL}' must be corrected."
LN -sf "${TARGET_JAR}" "${MC_SERVER_CUR_LINK_BASE}"
NEED_RESTART='y'
+ symlink_was_set="y"
fi
else
info "Symlink '${CYAN}${MC_SERVER_CUR_LINK_BASE}${NORMAL}' does not exists, will be created."
LN -sf "${TARGET_JAR}" "${MC_SERVER_CUR_LINK_BASE}"
NEED_RESTART='y'
+ symlink_was_set="y"
fi
+ if [[ "${symlink_was_set}" == "y" ]] ; then
+ if [[ -n "${MAIL_BODY}" ]] ; then
+ MAIL_BODY+="\n"
+ fi
+ MAIL_BODY+="$( my_date ): Symlink '${MC_SERVER_CUR_LINK_BASE}' was set pointing to '${TARGET_JAR}'.\n"
+ fi
+
}
#------------------------------------------------------------------------------
local -a services=()
local service=
+ local svc_status=
for service in $( systemctl --plain --type=service --state=running --no-legend --no-pager | \
grep '^minecraft' | awk '{print $1}' ) ; do
return
fi
+ if [[ -n "${MAIL_BODY}" ]] ; then
+ MAIL_BODY+="\n"
+ fi
+
empty_line
for service in "${ervices[@]}" ; do
info "Restarting '${CYAN}${service}${NORMAL}' ..."
if [[ "${SIMULATE}" != "y" ]] ; then
systemctl restart "${service}"
fi
+ MAIL_BODY+="$( my_date ): Restarted service '${service}'.\n"
done
sleep 15
for service in "${ervices[@]}" ; do
empty_line
info "Status of '${CYAN}${service}${NORMAL}':"
- systemctl status "${service}"
+ svc_status=$( systemctl status "${service}" 2>&1 )
+ if [[ "${QUIET}" != "y" ]] ; then
+ echo "${svc_status}"
+ fi
+ MAIL_BODY+="\n$( my_date ): Status of service '${service}':\n${svc_status}\n"
done
}
+#------------------------------------------------------------------------------
+check_and_send_mail() {
+
+ if [[ -z "${MAIL_BODY}" ]] ; then
+ debug "No mail message body - don't sending mail."
+ return
+ fi
+
+ local subject="Updating Minecraft server on $( fqdn -f ) to version '${UPSTREAM_VERSION}'."
+
+ MAIL_BODY="Update was starting: ${START_DATE}.\n\n${MAIL_BODY}\n\n"
+ MAIL_BODY+="With best regards\n\n"
+ MAIL_BODY+="Your ${BASE_NAME}"
+
+ if [[ "${SIMULATE}" == "y" ]] ; then
+ local msg="Following mail should be sent:\n"
+ msg+="From: <${MAIL_FROM_ADDRESS}>\n"
+ msg+="To: <${MAIL_TO_ADDRESS}>\n"
+ msg+="Return-path: <${MAIL_RETURN_ADDRESS}>\n"
+ msg+="Subject: ${subject}\n\n"
+ msg+="${MAIL_BODY}"
+ info "${msg}"
+ return
+ fi
+
+ info "Sending mail to <${MAIL_TO_ADDRESS}>"
+ echo "${MAIL_BODY}" | mailx --return-address="${MAIL_RETURN_ADDRESS}" \
+ --append="From: ${MAIL_FROM_ADDRESS}" --subject="${subject}" "${MAIL_TO_ADDRESS}"
+
+}
+
#------------------------------------------------------------------------------
main() {
restart_service
fi
+ check_and_send_mail
+
}
main "$@"