среда, 6 ноября 2024 г.

NGINX redirect for non whitelisted IPs

fixing an infinity loop issue

map $remote_addr $notwhitelisted_ip {

  default   1;

# VPN

  1.2.3.4   0;

}


server {

    ...

   

    set $maintenance_redirect 0;


    if ($notwhitelisted_ip = 1) {

      set $maintenance_redirect 1;

    }


    if ($request_uri = "/maintenance-vik.html") {

      set $maintenance_redirect 0;

    }


    if ($maintenance_redirect = 1) {

      return 301 /maintenance-vik.html;      

    } 

    ...

четверг, 3 октября 2024 г.

Bash check process status and restarting

 #!/bin/bash

PROCESS_NAME="queue:consumers:start specificName"

START_COMMAND="/usr/bin/php8.2 /var/www/project/html/bin/magento queue:consumers:start specificName --single-thread --max-messages=20000"


pgrep -f "$PROCESS_NAME" > /dev/null

PGREP_STATUS=$?


# 0 - found, 1 - not found

if [ $PGREP_STATUS -ne 0 ]; then

    echo "$(date '+%Y-%m-%d %H:%M:%S') - The process $PROCESS_NAME wasn't found, restarting..."

    $START_COMMAND &

    pgrep -af "PROCESS_NAME"

fi

четверг, 26 сентября 2024 г.

Siege with Basic Http Auth

 https://gist.github.com/rob-murray/dd77778b1770f32c46e8

# Basic auth;

auth=$(echo -n 'username:password' | openssl base64)

siege -t60s -c20 -d10 --header="Authorization:Basic $auth" 'https://staging.a-hostname.co.uk/'

siege -f sitemap.txt -c100 -t15m -d7 -iv --no-parser --header="Authorization:Basic $auth" -m "Project siege Sep 26 2024" -l  


пятница, 9 августа 2024 г.

550 5.7.64 TenantAttribution; Relay Access Denied [No TLS]

 Troubleshooting:

1) create/enable 'Connector' in 'Exchange'

Show all > Exchange > EAC (Exchange Administrative Control) > Mail flow > Connectors

2) check into created connector if enabled an option like 'keep Exchange headers'

четверг, 18 апреля 2024 г.

Linux Bash rsync remote to remote with forwarding keys

We need it for loading files directly from one remote server to another one where we have SSH access.

SSH access from a Workstation -> Server1 -> rsync loading files -> Server2

ssh -v username@server1

find an identity SSH key for sure

ssh-add <the_key>

ssh -A username@server1

run with A option for allowing forwarding keys 

rsync -azP --exclude '.4y8-folder' --exclude 'file.tar.gz' pub/media/ username@server2:pub/media/

среда, 14 июня 2023 г.

Linux Bash remove old files more than 10 if exists

if [ $(expr $(ls -1 /test/111 | wc -l | tr -d ' ')) -gt 10 ]; then rm $(ls -d -1 -At /test/111/* | tail -n $(expr $(ls -1 /test/111 | wc -l | tr -d ' ') - 10)) ; fi 

to crontab

/bin/bash -c "if [ $(expr $(ls -1 /test/111 | wc -l | tr -d ' ')) -gt 10 ]; then rm $(ls -d -1 -At /test/111/* | tail -n $(expr $(ls -1 /test/111 | wc -l | tr -d ' ') - 10)) ; fi"

среда, 24 мая 2023 г.

Linux Bash rsync only specific a files list

Check rsync --help whether it supports --files-from= option 

lst content

./folder-source/1/1

./folder-source/2/2

...

cd to a folder where folder-source as a sub-folder (it's an explanation of period "." in rsync command)

rsync --files-from=/tmp/lst . /app/var/folder-sync

четверг, 6 апреля 2023 г.

Linux Bash find multiple conditions and move files

remove only *.dat and *.csv files older than 4 moths 

find /path -type f -mtime +120 \( -name '*.dat' -or -name '*.csv' \) -exec rm '{}' ';'

or move the files, but please be aware if destination is wrong or some bad happens then you'll lose files 

find /path -type f -mtime +120 \( -name '*.dat' -or -name '*.csv' \) -exec mv '{}' /destination/ ';'

пятница, 11 ноября 2022 г.

Linux logrotate jira logs

 Jira has its own log rotate

However, it doesn't delete old files.

It can be done with crontab though.

#### remove old jira log files longer 180 days

30 2 * * * /usr/bin/find /opt/atlassian/servicedesk/logs/ -maxdepth 1 -type f -mtime +180 -exec rm -rf {} \;

45 2 * * * /usr/bin/find /opt/atlassian/servicedesk/logs/ -maxdepth 1 -type f -mtime +6 -exec gzip -q {} \;



суббота, 26 февраля 2022 г.

Linux logrotate twice per day

Before:

/etc/logrotate.d/logs

/mnt/shared/project/var/log/*.log 

{
  su www-project www-data
  rotate 30
  daily
  missingok
  compress
  notifempty
  copytruncate
  dateext

}

After:

1) create a separate additional logrotate conf file /etc/logrotate.d/logs_erp with content below (increased twice rotate 30 -> 60 and plus delaycompress):

/etc/logrotate.d/logs_erp
/mnt/shared/project/var/log/erp.log 
{
  su www-project www-data
  rotate 60
  daily
  missingok
  compress
  delaycompress
  notifempty
  copytruncate
  dateext
}
2) modify current logrotate conf file /etc/logrotate.d/logs with excluding first 'erp' characters from wildcard:
/mnt/shared/project/var/log/[!e][!r][!p]*.log 
{
  su www-project www-data
  rotate 30
  daily
  missingok
  compress
  notifempty
  copytruncate
  dateext
}
3) run logrotate conf file /etc/logrotate.d/logs_erp by cron additionally at 18.25
under root account
25 18 * * * logrotate -f /etc/logrotate.d/logs_erp

понедельник, 3 января 2022 г.

четверг, 30 декабря 2021 г.

Magento 2 How to throw report error page (500 error) for testing purpose

 The goal is to get a report page for testing purpose 

So, we have to break magento somehow.

The fast way is:

1. pub/media is symlink to media folder

2. rename real media folder to media.bk

3. open PLP and enjoy the error

var/report will be:

Directory \"\/mnt\/data\/www\/project\/releases\/pub\/media\" cannot be created Warning!mkdir(): File exists" ...

четверг, 16 сентября 2021 г.

Linux Bash check disk space

df --output=pcent / | tail -n +2 | tr -cd '0-9\n'

output available percent without header and symbol '%' - only number

#!/bin/bash

for mnt in / /var/log /var/www /mnt/shared; do

  chk_avail=`df --output=pcent $mnt | tail -n +2 | tr -cd '0-9\n'`

  flg=`echo $(( 100 - $chk_avail ))`

  if [ $flg -lt 15 ]; then

    echo 'Dataserver lack of free space, only '$flg' percent available in '$mnt' partition' | mail -s 'Dataserver lack of free space' alerts@gmail.com

  fi

done



пятница, 23 апреля 2021 г.

Magento 2 Multistore one domain

domain.com/store1

domain.com/store2

  1. Admin Panel: Stores/Settings/Stores (table store for checking code for MAGE_RUN_CODE)
    website: base, store: store1_code, store view: store1
    website: base, store: store2_code, store view: store2
  2. Admin Panel: Configuration/Web/URL Options/Add Store Code to Urls - Yes
  3. NGINX: 

    .php

        fastcgi_param  MAGE_RUN_TYPE    $MAGE_RUN_TYPE;

        fastcgi_param  MAGE_RUN_CODE    $MAGE_RUN_CODE;

    http

    map $request_uri $MAGE_RUN_CODE {

        ~^/store1 store1;

        ~^/store2 store2;

    }

    server
        set $MAGE_RUN_TYPE store;

воскресенье, 14 марта 2021 г.

среда, 24 февраля 2021 г.

grep with wildcard

 If you have a file with data and you need only words which starts with ABCD- and three numbers at the end. You can use it

 egrep -ow ABCD-... the_file

-o, --only-matching

 -w, --word-regexp         force PATTERN to match only whole words

... - three any numbers


понедельник, 9 ноября 2020 г.

PHP-FPM via command line

1. Install apt install libfcgi0ldbl

2. Install apt install html2text

3. Sh script

SCRIPT_FILENAME=/path/to/site/php_info.php \
REQUEST_URI=/ \
QUERY_STRING= \
REQUEST_METHOD=GET \
cgi-fcgi -bind -connect /run/php/php7.3-fpm.sock

4. script.sh | html2text

We will get phpinfo() function output through php-fpm, not through php-cli