PNG  IHDR;IDATxܻn0K )(pA 7LeG{ §㻢|ذaÆ 6lذaÆ 6lذaÆ 6lom$^yذag5bÆ 6lذaÆ 6lذa{ 6lذaÆ `}HFkm,mӪôô! x|'ܢ˟;E:9&ᶒ}{v]n&6 h_tڠ͵-ҫZ;Z$.Pkž)!o>}leQfJTu іچ\X=8Rن4`Vwl>nG^is"ms$ui?wbs[m6K4O.4%/bC%t Mז -lG6mrz2s%9s@-k9=)kB5\+͂Zsٲ Rn~GRC wIcIn7jJhۛNCS|j08yiHKֶۛkɈ+;SzL/F*\Ԕ#"5m2[S=gnaPeғL lذaÆ 6l^ḵaÆ 6lذaÆ 6lذa; _ذaÆ 6lذaÆ 6lذaÆ RIENDB` #!/bin/sh # Copyright (C) 2022 Checkmk GmbH - License: GNU General Public License v2 # This file is part of Checkmk (https://checkmk.com). It is subject to the terms and # conditions defined in the file COPYING, which is part of this source code package. RESOURCES="$(dirname "$(realpath -- "$0" || printf "%s" "$0")")" CONTROLLER_TARGET="${BIN_DIR:-/usr/bin}/cmk-agent-ctl" _usage() { cat >&2 <&2 </dev/null && return printf "systemd not found on this system\n" >&2 return 1 } _systemd_version() { systemctl --version | sed -n "s/systemd \\([0-9][0-9]*\\).*/\\1/p" } _need_ip_access_list() { grep -q '^IPAddressAllow=' "${ROOT}${RESOURCES}/check-mk-agent.socket.fallback" } _deploy_controller() { printf "Deploying agent controller: %s\n" "${CONTROLLER_TARGET}" gunzip --force --quiet -c "/var/lib/cmk-agent/cmk-agent-ctl.gz" >"/var/lib/cmk-agent/cmk-agent-ctl" || { printf "%s\n" "...Failed to unpack with gzip." return 1 } install -m 755 "/var/lib/cmk-agent/cmk-agent-ctl" "${CONTROLLER_TARGET}" || { printf "%s\n" "...Failed to move to target location." return 1 } rm -f "/var/lib/cmk-agent/cmk-agent-ctl" # Test rightaway. It might be dysfunctional (e.g., wrong architecture) "${CONTROLLER_TARGET}" --version >/dev/null 2>&1 || { printf "%s\n" "...Not running on this system. Falling back to legacy systemd setup." rm -f "${CONTROLLER_TARGET}" return 1 } return 0 } _systemd_sufficient() { _systemd_present || return 1 _destination >/dev/null || return 1 # version 219 is used on RHEL7 -- if we use the controller, that's sufficient. if [ "$(_systemd_version)" -lt 219 ]; then cat >&2 <&2 </dev/null systemctl stop "check-mk-agent.socket" 2>/dev/null systemctl disable "check_mk.socket" 2>/dev/null systemctl disable "check-mk-agent.socket" 2>/dev/null } prefix="Removing leftover systemd units:" suffix= units='check_mk.socket check_mk@.service check_mk-async.service check-mk-agent.socket check-mk-agent@.service check-mk-agent-async.service' for unit in ${units}; do path="/etc/systemd/system/${unit}" [ -e "${path}" ] || continue printf "%s %s" "${prefix}" "${path}" prefix="," suffix="\n" rm -f "${path}" done printf "%s" "${suffix}" cleanup } trigger() { _systemd_present || return 0 systemctl daemon-reload for unit in $(_unit_files); do # skip unit templates + timer activated units grep -q '\[Install\]' "${ROOT}${RESOURCES}/${unit}" || continue if _unit_deployed "${unit}"; then printf "Activating systemd unit '%s'...\n" "${unit}" systemctl enable "${unit}" systemctl restart "${unit}" else printf "Deactivating systemd unit '%s' (if active)...\n" "${unit}" systemctl stop "${unit}" 2>/dev/null systemctl disable "${unit}" 2>/dev/null fi done } _unit_deployed() { _destination --all | while read -r dest; do [ -e "${ROOT}${dest}/${1}" ] && break done } isdeployed() { for unit in $(_unit_files); do _unit_deployed "${unit}" && return 0 done return 1 } main() { case "$1" in deploy) deploy "$@" ;; cleanup) cleanup "$@" ;; purge) purge ;; trigger) trigger ;; isdeployed) isdeployed ;; *) _usage ;; esac } [ -z "${MK_SOURCE_ONLY}" ] && main "$@"