Want to subscribe to topics you're interested in?
Become a Member

Cron errors

Discussion in 'Beta release code' started by tjk, Jun 14, 2016.

  1. tjk

    tjk Member

    74
    16
    8
    Jun 27, 2015
    Ratings:
    +25
    Local Time:
    8:32 AM
    Still seeing these cron errors, I thought they stopped, but appear to be back now:

    Code:
    generated nginx include file: /usr/local/nginx/conf/autoprotect/domain.io/autoprotect-domain.io.conf
    generated nginx include file: /usr/local/nginx/conf/autoprotect/demodomain.com/autoprotect-demodomain.com.conf
    
    autoprotect.sh run completed...
    
    /usr/bin/ngxrestart: line 1: service: command not found
    

     
  2. eva2000

    eva2000 Administrator Staff Member

    30,850
    6,905
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,396
    Local Time:
    11:32 PM
    Nginx 1.13.x
    MariaDB 5.5
    what's output for
    Code (Text):
    crontab -l
    

    and contents of the tools/autoprotect.sh ?
     
  3. tjk

    tjk Member

    74
    16
    8
    Jun 27, 2015
    Ratings:
    +25
    Local Time:
    8:32 AM
    Code (Text):
    11 */23 * * * /usr/local/src/centminmod/tools/autoprotect.sh
    0 */4 * * * /usr/bin/cminfo_updater
    

    Code (Text):
    [root@node01 ~]# cat /usr/local/src/centminmod/tools/autoprotect.sh
    #!/bin/bash
    #################################################################
    # for centminmod.com LEMP stack environments
    # auto generate and convert detected .htaccess file directory
    # paths to nginx deny all equivalents only when .htaccess file
    # contains 'Deny from all' text and generate a per nginx vhost
    # auto protect directory at /usr/local/nginx/conf/autoprotect/${domain}
    # with /usr/local/nginx/conf/autoprotect/${domain}/autoprotect-${domain}.conf
    # include file which you include into your nginx vhost above the
    # root / location match i.e.
    # include /usr/local/nginx/conf/autoprotect/${domain}/autoprotect-${domain}.conf;
    #################################################################
    DT=$(date +"%d%m%y-%H%M%S")
    SCRIPTDIR="$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)"
    BASEDIR=$(dirname $SCRIPTDIR)
    
    DEBUG='n'
    TOPLEVEL_DIR='/home/nginx/domains'
    
    genprotect() {
      # need to restart to ensure all existing or recently 403 denied directory settings
      # are detected
      /usr/bin/ngxrestart >/dev/null 2>&1
      sleep 2
    
        # generate /usr/local/nginx/conf/autoprotect.conf include file
        # to be placed in individual nginx vhosts
    for domain in $(ls $TOPLEVEL_DIR); do
        if [ ! -d "/usr/local/nginx/conf/autoprotect/${domain}" ]; then
          mkdir -p "/usr/local/nginx/conf/autoprotect/${domain}"
        fi
        HTPATHS=$(find "${TOPLEVEL_DIR}/${domain}" -name ".htaccess" -print0 | xargs -0 echo)
        declare -a arrays
        arrays=(${HTPATHS})
      for d in "${arrays[@]}"; do
        if [[ "$(echo "$d" | grep "${domain}/public/")" ]]; then
          # get directory path which contains .htaccess file
          PROTECTDIR=$(dirname "$d");
          # get the web url path for the .htaccess file
          URL_WEB=$(echo "$PROTECTDIR" |sed -e 's|\/home\/nginx\/domains\/||' -e 's|\/public||')
          # check if 'Deny from all' exists in .htaccess and only generate nginx deny all location
          # matches if .htaccess file has 'Deny from all' but also give end user option to bypass
          # autoprotect.sh script and NOT create a nginx deny all location match by manually creating
          # a .autoprotect-bypass file within the directory you want to bypass and exclude from autoprotect.sh
          if [ -f "${PROTECTDIR}/.htaccess" ]; then
            if [[ "$(cat "${PROTECTDIR}/.htaccess" | grep -v "\#" | grep -i 'Deny from all' >/dev/null 2>&1; echo $?)" = '0' && ! -f "${PROTECTDIR}/.autoprotect-bypass" ]]; then
              # check the web url for .htaccess directory path to see if it's already deny all / 403 protected
              # only generate nginx deny all rules for .htaccess directory paths which are not already returning
              # 403 permission denied http status codes (also include check for 404)
              # 
              # if [[ "$(curl -sI ${URL_WEB}/ | grep 'HTTP\/' | egrep -o '403|404' >/dev/null 2>&1; echo $?)" != '0' ]]; then
                PROTECTDIR_PATH=$(echo "$PROTECTDIR" |sed -e "s|\/home\/nginx\/domains\/${domain}\/public||")
                echo -e "# $PROTECTDIR\nlocation ~* ^$PROTECTDIR_PATH/ { deny all; }"
              # fi
            fi
          fi
        fi # grep public only
      done > "/usr/local/nginx/conf/autoprotect/${domain}/autoprotect-${domain}.conf"
        echo "generated nginx include file: /usr/local/nginx/conf/autoprotect/${domain}/autoprotect-${domain}.conf"
    done
    
    if [[ "$DEBUG" = [yY] ]]; then
      echo
      ls -lahR /usr/local/nginx/conf/autoprotect/
      echo
    else
      echo
      echo "autoprotect.sh run completed..."
      echo
    fi
    
    # only trigger nginx restart service when there are new differences detected
    # in current and previous autoprotect include conf files
    if [[ -f /usr/bin/ngxrestart ]]; then
            # /usr/bin/ngxrestart >/dev/null 2>&1
            sleep 2
            /usr/bin/ngxrestart
            rm -rf /usr/local/nginx/conf/autoprotect/status-restart
    fi
    
    }
    
     
  4. eva2000

    eva2000 Administrator Staff Member

    30,850
    6,905
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,396
    Local Time:
    11:32 PM
    Nginx 1.13.x
    MariaDB 5.5
    looks good script wise so not entirely sure why you're getting that..

    when you manually run the command do you get an error ? or just when auto run via cron ?
    Code (Text):
    /usr/local/src/centminmod/tools/autoprotect.sh
    
     
  5. tjk

    tjk Member

    74
    16
    8
    Jun 27, 2015
    Ratings:
    +25
    Local Time:
    8:32 AM
    Runs fine via cli, looks like the error is only via cron.

    Code (Text):
    [root@node01 ~]# /usr/local/src/centminmod/tools/autoprotect.sh
    generated nginx include file: /usr/local/nginx/conf/autoprotect/datacentertalk.io/autoprotect-datacentertalk.io.conf
    generated nginx include file: /usr/local/nginx/conf/autoprotect/demodomain.com/autoprotect-demodomain.com.conf
    
    autoprotect.sh run completed...
    
    Restarting nginx (via systemctl):                          [  OK  ]
    
     
  6. eva2000

    eva2000 Administrator Staff Member

    30,850
    6,905
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,396
    Local Time:
    11:32 PM
    Nginx 1.13.x
    MariaDB 5.5
    what's output for contents of /etc/crontab ? centmin mod should of auto adjusted PATH variable to cover all paths cron might look for

    i.e.
    Code (Text):
    cat /etc/crontab
    SHELL=/bin/bash
    PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin
    MAILTO=root
    
    # For details see man 4 crontabs
    
    # Example of job definition:
    # .---------------- minute (0 - 59)
    # |  .------------- hour (0 - 23)
    # |  |  .---------- day of month (1 - 31)
    # |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
    # |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
    # |  |  |  |  |
    # *  *  *  *  * user-name  command to be executed
    
    */1 * * * * root /usr/local/rtm/bin/rtm 55 > /dev/null 2> /dev/null
     
  7. tjk

    tjk Member

    74
    16
    8
    Jun 27, 2015
    Ratings:
    +25
    Local Time:
    8:32 AM
    Code (Text):
    [root@node01 ~]# cat /etc/crontab
    SHELL=/bin/bash
    PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin
    MAILTO=root
    
    # For details see man 4 crontabs
    
    # Example of job definition:
    # .---------------- minute (0 - 59)
    # |  .------------- hour (0 - 23)
    # |  |  .---------- day of month (1 - 31)
    # |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
    # |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
    # |  |  |  |  |
    # *  *  *  *  * user-name  command to be executed
    
    [root@node01 ~]# 
    
     
  8. eva2000

    eva2000 Administrator Staff Member

    30,850
    6,905
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,396
    Local Time:
    11:32 PM
    Nginx 1.13.x
    MariaDB 5.5
    looks good too * scratches head *
     
  9. tjk

    tjk Member

    74
    16
    8
    Jun 27, 2015
    Ratings:
    +25
    Local Time:
    8:32 AM
    Just fyi, upgraded to latest beta this morning, still seeing the cron errors.
     
  10. eva2000

    eva2000 Administrator Staff Member

    30,850
    6,905
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,396
    Local Time:
    11:32 PM
    Nginx 1.13.x
    MariaDB 5.5
    just updated 123.09beta01 tools/autoprotect.sh with a fix, centmin.sh menu option 23 submenu option 2 to update
     
  11. tjk

    tjk Member

    74
    16
    8
    Jun 27, 2015
    Ratings:
    +25
    Local Time:
    8:32 AM
    Code (Text):
    cd /usr/local/src/centminmod
        git stash
        git pull
        chmod +x centmin.sh
    


    I'll let you know tomorrow if they continue, thank you @eva2000!
     
    • Like Like x 1
  12. BigIron

    BigIron Member

    49
    10
    8
    Sep 18, 2015
    Ratings:
    +13
    Local Time:
    5:32 AM
    Have this same error on my servers.

    Just updated :)
     
  13. eva2000

    eva2000 Administrator Staff Member

    30,850
    6,905
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,396
    Local Time:
    11:32 PM
    Nginx 1.13.x
    MariaDB 5.5
    i just committed 2 more related typo/syntax fixes for this too ;)
     
  14. tjk

    tjk Member

    74
    16
    8
    Jun 27, 2015
    Ratings:
    +25
    Local Time:
    8:32 AM
    Bottom part of cron email:

    Code (Text):
    autoprotect.sh run completed...
    
    Restarting nginx (via systemctl):  [  OK  ]
    
     
    • Like Like x 1
  15. eva2000

    eva2000 Administrator Staff Member

    30,850
    6,905
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,396
    Local Time:
    11:32 PM
    Nginx 1.13.x
    MariaDB 5.5
    Means it's fixed :)
     
  16. tjk

    tjk Member

    74
    16
    8
    Jun 27, 2015
    Ratings:
    +25
    Local Time:
    8:32 AM
    Indeed, thank you sir!
     
    • Like Like x 1