ncc.zabbix_fbsd_templates

Yohn Y. 2025-06-01 Parent:8b401f8069e3 Child:fa9f1740c55a

18:4c0387be9c91 Browse Files

.. v1.r202506.1 + Контроль запуска freebsd-update раз в 4 часа внутри скрипта, что позволяет запускать сам скрипт чаще. В инструкции по развёртыванию указано раз 15 минут + Контроль наличия запущенных процессов pkg, что позволит иметь меньше ошибок совместного использования БД пакетов системы

src/aw.fbsd-mon-helper/lib/fbsd_up.sh src/aw.fbsd-mon-helper/lib/pkg.sh src/aw.fbsd-mon-helper/version

     1.1 --- a/src/aw.fbsd-mon-helper/lib/fbsd_up.sh	Tue Feb 11 19:49:30 2025 +0300
     1.2 +++ b/src/aw.fbsd-mon-helper/lib/fbsd_up.sh	Sun Jun 01 12:31:35 2025 +0300
     1.3 @@ -5,6 +5,7 @@
     1.4  v_fbsd_up_out="$STATE_ROOT/fbsd_update"
     1.5  v_fbsd_up_status="$STATE_ROOT/fbsd_update.status"
     1.6  v_fbsd_up_current_ver="$STATE_ROOT/fbsd_update.versions"
     1.7 +v_fbsd_up_action_flag="$STATE_ROOT/fbsd_update.action.flag"
     1.8  
     1.9  
    1.10  fbsd_up_init () {
    1.11 @@ -25,40 +26,59 @@
    1.12      > "${v_fbsd_up_current_ver}"
    1.13  }
    1.14  
    1.15 +fbsd_up_check_action_flag () {
    1.16 +  local res _act_flag
    1.17 +
    1.18 +  res="$(( $(date '+%s') / 14400 ))"
    1.19 +  _act_flag="$(cat "$v_fbsd_up_action_flag")"
    1.20 +
    1.21 +  if [ -z "$_act_flag" ] || [ "$res" -ne "$_act_flag"  ] ; then
    1.22 +    echo "$res" | tee "$v_fbsd_up_action_flag"
    1.23 +  fi
    1.24 +}
    1.25 +
    1.26  
    1.27  fbsd_up_do () {
    1.28 +  local _action_flag _ret
    1.29 +
    1.30    log_start "fbsd_up_do"
    1.31  
    1.32 -  fbsd_up_init
    1.33 -  fbsd_up_versions
    1.34 -  {
    1.35 -    $v_fbsd_up_binary updatesready
    1.36 -    local _ret="$?"
    1.37 +  _action_flag="$(fbsd_up_check_action_flag)"
    1.38 +  if [ -z "$_action_flag" ] ; then
    1.39 +    log "Not need to update: old action mark"
    1.40  
    1.41 -    case "$_ret" in
    1.42 -      0 )
    1.43 -        if [ "$(cat "$v_fbsd_up_status")" != "NEED UPDATE" ]; then
    1.44 -          mail -s "$(hostname -f): FREEBSD UPDATE NEEDED" "$ADMIN_MAIL" < "$v_fbsd_up_out"
    1.45 -        fi
    1.46 +  else
    1.47 +    log "New action flag '${_action_flag}' - updating"
    1.48 +    fbsd_up_init
    1.49 +    fbsd_up_versions
    1.50 +    {
    1.51 +      $v_fbsd_up_binary updatesready
    1.52 +      _ret="$?"
    1.53  
    1.54 -        fbsd_up_status "NEED UPDATE"
    1.55 -       ;;
    1.56 +      case "$_ret" in
    1.57 +        0 )
    1.58 +          if [ "$(cat "$v_fbsd_up_status")" != "NEED UPDATE" ]; then
    1.59 +            mail -s "$(hostname -f): FREEBSD UPDATE NEEDED" "$ADMIN_MAIL" < "$v_fbsd_up_out"
    1.60 +          fi
    1.61  
    1.62 -      1 )
    1.63 -        fbsd_up_status "RUN ERROR"
    1.64 +          fbsd_up_status "NEED UPDATE"
    1.65          ;;
    1.66  
    1.67 -      2 )
    1.68 -        fbsd_up_status "OK"
    1.69 -        ;;
    1.70 +        1 )
    1.71 +          fbsd_up_status "RUN ERROR"
    1.72 +          ;;
    1.73 +
    1.74 +        2 )
    1.75 +          fbsd_up_status "OK"
    1.76 +          ;;
    1.77  
    1.78 -      * )
    1.79 -        fbsd_up_status "RUN ERROR"
    1.80 -        log_err "fbsd_up: updatesready return unknown code ${_ret}"
    1.81 -        ;;
    1.82 -
    1.83 +        * )
    1.84 +          fbsd_up_status "RUN ERROR"
    1.85 +          log_err "fbsd_up: updatesready return unknown code ${_ret}"
    1.86 +          ;;
    1.87        esac
    1.88 -  } 2>&1 | log
    1.89 +    } 2>&1 | log
    1.90 +  fi
    1.91  
    1.92    log_end
    1.93  }
     2.1 --- a/src/aw.fbsd-mon-helper/lib/pkg.sh	Tue Feb 11 19:49:30 2025 +0300
     2.2 +++ b/src/aw.fbsd-mon-helper/lib/pkg.sh	Sun Jun 01 12:31:35 2025 +0300
     2.3 @@ -152,16 +152,36 @@
     2.4  
     2.5  }
     2.6  
     2.7 +pkg_check_pkg_binary () {
     2.8 +  # Проверяет, нет ли в системе других запущенных приложений pkg. 
     2.9 +  # Необходимо, чтобы не мешать оперативным процессам обновления
    2.10 +
    2.11 +  {
    2.12 +    ps -Ao comm | awk '$1 == "pkg" {print $1}' | wc -l | tr -d ' '
    2.13 +  } 2>/dev/null
    2.14 +  
    2.15 +}
    2.16 +
    2.17  pkg_do () {
    2.18 +  local _other_pkgs
    2.19 +
    2.20    log_start "pkg_do"
    2.21  
    2.22 -  pkg_init
    2.23 +  _other_pkgs="$(pkg_check_pkg_binary)"
    2.24 +
    2.25 +  if [ "$_other_pkgs" -ne 0 ] ; then
    2.26 +    log "Pakages update check fail: other '${_other_pkgs}' binary working"
    2.27 +    ps -Ao comm,ppid,pid,time | awk '$1 == "pkg" {print $0}' | log
    2.28  
    2.29 -  pkg_check_up_status
    2.30 -  pkg audit -qF > "${v_pkg_update_status}.audit"
    2.31 -  mv -f "${v_pkg_update_status}.audit" "${v_pkg_update_status_res}.audit"
    2.32 +  else
    2.33 +    pkg_init
    2.34  
    2.35 -  pkg_make_detail
    2.36 +    pkg_check_up_status
    2.37 +    pkg audit -qF > "${v_pkg_update_status}.audit"
    2.38 +    mv -f "${v_pkg_update_status}.audit" "${v_pkg_update_status_res}.audit"
    2.39 +
    2.40 +    pkg_make_detail
    2.41 +  fi
    2.42  
    2.43    log_end
    2.44  }
    2.45 \ No newline at end of file
     3.1 --- a/src/aw.fbsd-mon-helper/version	Tue Feb 11 19:49:30 2025 +0300
     3.2 +++ b/src/aw.fbsd-mon-helper/version	Sun Jun 01 12:31:35 2025 +0300
     3.3 @@ -1,1 +1,1 @@
     3.4 -v1.r202502.1
     3.5 \ No newline at end of file
     3.6 +v1.r202506.2
     3.7 \ No newline at end of file