From 8e5a83eede277b5f7e35982c8b1cc6ceae42c1af Mon Sep 17 00:00:00 2001 From: Ramil Valitov Date: Wed, 5 Aug 2020 23:59:19 +0300 Subject: [PATCH] Feature/cache location (#50) --- tests/all.sh | 14 +++++++++-- zabbix/zabbix_php_fpm_discovery.sh | 40 ++++++++++++++++++++++++++++-- 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/tests/all.sh b/tests/all.sh index e802fb3..1c1bf93 100644 --- a/tests/all.sh +++ b/tests/all.sh @@ -50,6 +50,15 @@ LIST_OF_SERVICES="" # Used for section folding in Travis CI SECTION_UNIQUE_ID="" +#Parent directory where all cache files are located in the OS +CACHE_ROOT="/var/cache" + +#Name of the private directory to store the cache files +CACHE_DIR_NAME="zabbix-php-fpm" + +#Full path to directory to store cache files +CACHE_DIRECTORY="$CACHE_ROOT/$CACHE_DIR_NAME" + # ---------------------------------- # Colors # ---------------------------------- @@ -518,8 +527,9 @@ oneTimeSetUp() { #Called before every test setUp() { #Delete all cache files - sudo rm -f "/etc/zabbix/php_fpm_results.cache" - sudo rm -f "/etc/zabbix/php_fpm_pending.cache" + if [[ -d "$CACHE_DIRECTORY" ]]; then + sudo find "$CACHE_DIRECTORY" -type f -exec rm '{}' \; + fi } #Called after every test diff --git a/zabbix/zabbix_php_fpm_discovery.sh b/zabbix/zabbix_php_fpm_discovery.sh index bde2f0e..476fe15 100644 --- a/zabbix/zabbix_php_fpm_discovery.sh +++ b/zabbix/zabbix_php_fpm_discovery.sh @@ -25,6 +25,15 @@ USE_SLEEP_TIMEOUT="" #Sleep timeout in seconds SLEEP_TIMEOUT="0.5" +#Parent directory where all cache files are located in the OS +CACHE_ROOT="/var/cache" + +#Name of the private directory to store the cache files +CACHE_DIR_NAME="zabbix-php-fpm" + +#Full path to directory to store cache files +CACHE_DIRECTORY="$CACHE_ROOT/$CACHE_DIR_NAME" + #Checking all the required executables S_PS=$(type -P ps) S_GREP=$(type -P grep) @@ -118,18 +127,42 @@ if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then exit 1 fi +if [[ ! -d "$CACHE_ROOT" ]]; then + ${S_ECHO} "The OS cache directory '$CACHE_ROOT' not found in the system." + exit 1 +fi + +function createCacheDirectory() { + if [[ ! -d "$CACHE_DIRECTORY" ]]; then + mkdir "$CACHE_DIRECTORY" + fi + if [[ ! -d "$CACHE_DIRECTORY" ]]; then + return 1 + fi + + chmod 700 "$CACHE_DIRECTORY" + return 0 +} + +createCacheDirectory +EXIT_CODE=$? +if [[ ${EXIT_CODE} -ne 0 ]]; then + ${S_ECHO} "Failed to create cache directory '$CACHE_DIRECTORY'." + exit 1 +fi + #Local directory LOCAL_DIR=$(${S_DIRNAME} "$0") #Cache file for pending pools, used to store execution state #File format: # -PENDING_FILE="$LOCAL_DIR/php_fpm_pending.cache" +PENDING_FILE="$CACHE_DIRECTORY/php_fpm_pending.cache" #Cache file with list of active pools, used to store execution state #File format: # -RESULTS_CACHE_FILE="$LOCAL_DIR/php_fpm_results.cache" +RESULTS_CACHE_FILE="$CACHE_DIRECTORY/php_fpm_results.cache" #Path to status script, another script of this bundle STATUS_SCRIPT="$LOCAL_DIR/zabbix_php_fpm_status.sh" @@ -331,6 +364,9 @@ function DeletePoolFromPendingList() { } function SavePrintResults() { + #Checking and creating cache directory just in case: + createCacheDirectory + #Saving pending list: if [[ -f $PENDING_FILE ]] && [[ ! -w $PENDING_FILE ]]; then echo "Error: write permission is not granted to user $ACTIVE_USER for cache file $PENDING_FILE"