Get the most out of your Centmin Mod LEMP stack
Become a Member

Beta Branch update inc/wpsetup.inc

Discussion in 'Centmin Mod Github Commits' started by eva2000, Jul 8, 2018.

  1. eva2000

    eva2000 Administrator Staff Member

    55,156
    12,249
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,825
    Local Time:
    5:58 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    update inc/wpsetup.inc

    - fix bug in .wpcli-status status check
    - change nginx + php-fpm ngxrestart command to only trigger if zend opcache is installed and when opcache.revalidate_freq is set to greater than 10 seconds. The default value for opcache.revalidate_freq for installs is 180 seconds for better performance but if you have high traffic sites with many wordpress installs created from centmin.sh menu option 22, you may not want to have nginx and php-fpm restarted that often, so you can set opcache.revalidate_freq to a lower value like 10 instead o 180 and thus wp_updater cronjobs will skip ngxrestart triggers at cronjob runs. Issue was discussed at PHP-FPM - Troubleshooting php-fpm self restarts

    Continue reading...

    123.09beta01 branch


     
  2. eva2000

    eva2000 Administrator Staff Member

    55,156
    12,249
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,825
    Local Time:
    5:58 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    part 1 of the fix for .wpcli-status check is auto applied to Centmin Mod 123.09beta01 wordpress installed instances which have latest 123.09beta01 code via cmupdate command and have at least once ran centmin.sh.

    example of the auto fix in action when you run centmin.sh after this update for auto fixing cronjob at /root/tools/wp_updater_blog.domain.com.sh. A backup of the script is made before auto fixing at
    /root/tools/wp_updater_blog.domain.com.sh.backup-* where timestamp is added to backup filename.
    Code (Text):
    updating wp updater code for /root/tools/wp_updater_blog.domain.com.sh
    https://community.centminmod.com/threads/15123/
    cp -a /root/tools/wp_updater_blog.domain.com.sh /root/tools/wp_updater_blog.domain.com.sh.backup-070718-210824
    if [[ -f .wpcli-status && ! "$(grep -w 'Plugin already updated' .wpcli-status)" ]]; then
    

    note you will only see and get that auto fix if centmin checks the 23rd line of file and it has the expected bug and that the cronjob updater file/script has exactly 36 lines of code. This is to prevent messing up customized files edited by end users

    which basically replaces the incorrect line 23 of wp_updater at /root/tools/wp_updater_blog.domain.com.sh cronjob below
    Code (Text):
    if [[ -f .wpcli-status && ! "" ]]; then
    

    and replaces it with correct line
    Code (Text):
    if [[ -f .wpcli-status && ! "$(grep -w 'Plugin already updated' .wpcli-status)" ]]; then
    
     
    Last edited: Jul 8, 2018
  3. eva2000

    eva2000 Administrator Staff Member

    55,156
    12,249
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,825
    Local Time:
    5:58 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    part 2 of update in 1st post isn't auto applied though so manual update is needed. The change is in way nginx + php-fpm ngxrestart are triggered

    change from
    Code (Text):
    if [[ -f .wpcli-status && ! "$(grep -w 'Plugin already updated' .wpcli-status)" ]]; then
      exec 99>/tmp/wp_updater_phpfpm.lock
      if flock -n -x 99; then
      /usr/bin/nprestart
      rm -rf /tmp/wp_updater_phpfpm.lock
      else
      echo "already detected running process"
      echo "skipping nprestart"
      fi
    fi
    

    to
    Code (Text):
    if [[ -f .wpcli-status && ! "$(grep -w 'Plugin already updated' .wpcli-status)" ]]; then
      exec 99>/tmp/wp_updater_phpfpm.lock
      if flock -n -x 99; then
        # only do nginx + php-fpm restarts when zend opcache caching is enabled and revalidation
        # frequency is greater than 10 seconds set by opcache.revalidate_freq php setting
        if [[ "$(php --ri "Zend Opcache" >/dev/null 2>&1; echo $?)" -eq '0' && "$(php --ri "Zend Opcache" | awk '/opcache.revalidate_freq/ {print $3}')" -gt '10' ]]; then
          /usr/bin/nprestart
        fi
      rm -rf /tmp/wp_updater_phpfpm.lock
      else
      echo "already detected running process"
      echo "skipping nprestart"
      fi
    fi
    

    basically /usr/bin/nprestart command is wrapped in a conditional check to only do nginx + php-fpm restarts when zend opcache caching is enabled and revalidation frequency is greater than 10 seconds set by opcache.revalidate_freq php setting
    Code (Text):
        if [[ "$(php --ri "Zend Opcache" >/dev/null 2>&1; echo $?)" -eq '0' && "$(php --ri "Zend Opcache" | awk '/opcache.revalidate_freq/ {print $3}')" -gt '10' ]]; then
          /usr/bin/nprestart
        fi
    
     
  4. ahmed

    ahmed Active Member

    361
    49
    28
    Feb 21, 2017
    Ratings:
    +63
    Local Time:
    9:58 PM
    Hi

    I have this code, how to fix it?
    Code (Text):
    #!/bin/bash
    
    PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/root/bin:/bin
    
    EMAIL= domain.comm
    
    EMAILFROM=
    
    DT=$(date +"%d%m%y-%H%M%S")
    
    
    
    {
    
    cd /home/nginx/domains/domain.com/public
    
    echo "/home/nginx/domains/domain.com/public"
    
    #/usr/bin/wp cli update --allow-root
    
    echo "update wp-cli"
    
    rm -rf /usr/bin/wp
    
    wget -cnv --no-check-certificate [URL]https://raw.github.com/wp-cli/builds/gh-pages/phar/wp-cli.phar[/URL] -O /usr/bin/wp --tries=3
    
    chmod 0700 /usr/bin/wp
    
    /usr/bin/wp --info --allow-root
    
    /usr/bin/wp plugin status --allow-root
    
    /usr/bin/wp plugin update --all --allow-root
    
    #/usr/bin/wp core check-update --allow-root
    
    #/usr/bin/wp core update --allow-root
    
    #/usr/bin/wp core update-db --allow-root
    
    #/usr/bin/wp core update --allow-root
    
    chown -R nginx:nginx /home/nginx/domains/domain.com/public
    
    ###### w3tc remove minifies cache
    
    rm -rf /home/nginx/domains/domain.com/public/wp-content/cache/minify/*
    
    /usr/bin/nprestart
    
    } 2>&1 | tee /home/nginx/domains/domain.com/log/wp_updater-${DT}.log
    
    cat -v /home/nginx/domains/domain.com/log/wp_updater-${DT}.log | /usr/bin/tr -cd '\11\12\15\40-\176' | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" | dos2unix | mail -r $EMA$
    
    #rm -rf /home/nginx/domains/domain.com/log/wp_updater-${DT}.log
    
    
    
    #
    
    # Written by AC - 2015 <al@terraltech.com> - sys0dm1n.com
    
    #
    
    URL='domain.com'
    
    
    
    wget --quiet [URL]http://$URL/sitemap.xml[/URL] --no-cache --output-document - | egrep -o "http(s?)://$URL[^ \"\'()\<>]+" | while read line; do
    
        if [[ $line == *.xml ]]
    
        then
    
            newURL=$line
    
            wget --quiet $newURL --no-cache --output-document - | egrep -o "http(s?)://$URL[^ \"\'()\<>]+" | while read newline; do
    
              time curl -A 'Cache Warmer' -sL -w "%{http_code} %{url_effective}\n" $newline -o /dev/null 2>&1
    
              echo $newline
    
            done
    
        else
    
            time curl -A 'Cache Warmer' -sL -w "%{http_code} %{url_effective}\n" $line -o /dev/null 2>&1
    
            echo $line
    
        fi
    
    done
    
    
    
    echo cache warmed
    
     
  5. eva2000

    eva2000 Administrator Staff Member

    55,156
    12,249
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,825
    Local Time:
    5:58 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    doesn't look like standard centmin mod generated wp updater cronjob script code ?
     
  6. ahmed

    ahmed Active Member

    361
    49
    28
    Feb 21, 2017
    Ratings:
    +63
    Local Time:
    9:58 PM
    yes, maybe I edited that long time ago, do u suggest getting a new code and replace
     
  7. eva2000

    eva2000 Administrator Staff Member

    55,156
    12,249
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,825
    Local Time:
    5:58 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    you can try manual updates as follows

    find
    Code (Text):
    /usr/bin/wp plugin update --all --allow-root
    

    replace with below which basically pipes update status output into file named .wpcli-status
    Code (Text):
    /usr/bin/wp plugin update --all --allow-root | tee .wpcli-status
    

    find
    Code (Text):
    /usr/bin/nprestart
    

    replace with below which basically checks .wpcli-status file to see if updates are available and updated and only restart nginx/php-fpm if updates were made otherwise skip restarts and also checks via flock if another wp_updater script instance is already running and skips restarts if another script is running
    Code (Text):
    if [[ -f .wpcli-status && ! "$(grep -w 'Plugin already updated' .wpcli-status)" ]]; then
      exec 99>/tmp/wp_updater_phpfpm.lock
      if flock -n -x 99; then
       # only do nginx + php-fpm restarts when zend opcache caching is enabled and revalidation
       # frequency is greater than 10 seconds set by opcache.revalidate_freq php setting
       if [[ "$(php --ri "Zend Opcache" >/dev/null 2>&1; echo $?)" -eq '0' && "$(php --ri "Zend Opcache" | awk '/opcache.revalidate_freq/ {print $3}')" -gt '10' ]]; then
         /usr/bin/nprestart
       fi
      rm -rf /tmp/wp_updater_phpfpm.lock
      else
      echo "already detected running process"
      echo "skipping nprestart"
      fi
    fi