From: Frank Brehm Date: Tue, 20 Apr 2021 17:01:50 +0000 (+0200) Subject: Setting symlinks and restarting services X-Git-Url: https://git.uhu-banane.de/?a=commitdiff_plain;h=87a5ad75e1df51f0bf3bbce2a82b6faf08ef80bb;p=pixelpark%2Fadmin-tools.git Setting symlinks and restarting services --- diff --git a/bin/update-minecraft-server-jar b/bin/update-minecraft-server-jar index 692ad2f..062aeab 100755 --- a/bin/update-minecraft-server-jar +++ b/bin/update-minecraft-server-jar @@ -34,6 +34,7 @@ UPSTREAM_VERSION= DOWNLOAD_URL= SHA1_SUM= TARGET_JAR= +NEED_RESTART='n' DESCRIPTION=$( cat <<-EOF Update Micraft server .jar file. @@ -232,6 +233,7 @@ do_download() { eval ${cmd} fi CHOWN "${MC_USER}:${MC_GROUP}" "${TARGET_JAR}" + NEED_RESTART='y' } @@ -252,6 +254,76 @@ check_sha1() { } +#------------------------------------------------------------------------------ +fix_symlinks() { + + info "Checking symlink in '${CYAN}${MC_BACKUP_DIR}${NORMAL}' ..." + + if [[ -e "${MC_SERVER_CUR_LINK_BASE}" ]] ; then + if [[ ! -h "${MC_SERVER_CUR_LINK_BASE}" ]] ; then + error "Path '${RED}/${MC_SERVER_CUR_LINK_BASE}${NORMAL}' exists, but is not a symlink." + exit 7 + fi + if [[ ! -f "${MC_SERVER_CUR_LINK_BASE}" ]] ; then + error "Symlink '${RED}/${MC_SERVER_CUR_LINK_BASE}${NORMAL}' exists, but shows not to a regular file." + exit 7 + fi + + local link_target=$( readlink -e "${MC_SERVER_CUR_LINK_BASE}" ) + debug "Current symlink points to '${CYAN}${link_target}${NORMAL}'." + local canon_path_target_jar=$( readlink -e "${TARGET_JAR}" ) + debug "Absolute path of target jar file: '${CYAN}${canon_path_target_jar}${NORMAL}'." + + if [[ "${link_target}" != "${canon_path_target_jar}" ]] ; 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' + 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' + + fi + +} + +#------------------------------------------------------------------------------ +restart_service() { + + local -a services=() + local service= + + for service in $( systemctl --plain --type=service --state=running --no-legend --no-pager | \ + grep '^minecraft' | awk '{print $1}' ) ; do + services+=( "${service}" ) + done + + if [[ "${#services[*]}" == 0 ]] ; then + info "No services found to restart." + return + fi + + empty_line + for service in "${ervices[@]}" ; do + info "Restarting '${CYAN}${service}${NORMAL}' ..." + if [[ "${SIMULATE}" != "y" ]] ; then + systemctl restart "${service}" + fi + done + + sleep 15 + + for service in "${ervices[@]}" ; do + empty_line + info "Status of '${CYAN}${service}${NORMAL}':" + systemctl status "${service}" + done + +} + #------------------------------------------------------------------------------ main() { @@ -261,15 +333,19 @@ main() { check_preferences detecting_cur_version get_upstream_info - if [[ -f "${TARGET_JAR}" ]] ; then - check_sha1 - fi - if [[ "${UPSTREAM_VERSION}" == "${CURRENT_VERSION}" ]] ; then - info "Version '${GREEN}${UPSTREAM_VERSION}${NORMAL}' not changed, no update." - exit 0 + if [[ ! -f "${TARGET_JAR}" ]] ; then + do_download fi - do_download + # if [[ "${UPSTREAM_VERSION}" == "${CURRENT_VERSION}" ]] ; then + # info "Version '${GREEN}${UPSTREAM_VERSION}${NORMAL}' not changed, no update." + # exit 0 + # fi check_sha1 + fix_symlinks + + if [[ "${NEED_RESTART}" == "y" ]] ; then + restart_service + fi }