mirror of
https://github.com/limosek/zaf.git
synced 2025-11-01 18:17:37 +01:00
Repaired tmp and cache directory init and clean
This commit is contained in:
@@ -1,36 +1,29 @@
|
||||
# Zaf cache related functions
|
||||
|
||||
zaf_cache_init(){
|
||||
[ -z "$ZAF_CACHE_DIR" ] && ZAF_CACHE_DIR=${ZAF_TMP_BASE}c
|
||||
if [ -n "$ZAF_CACHE_DIR" ]; then
|
||||
mkdir -p "$ZAF_CACHE_DIR"
|
||||
if zaf_is_root; then
|
||||
zaf_trc "Cache: Changing perms to $ZAF_CACHE_DIR (zabbix/$ZAF_ZABBIX_GID/0770)"
|
||||
chown $ZAF_FILES_UID "$ZAF_CACHE_DIR"
|
||||
chgrp $ZAF_FILES_GID "$ZAF_CACHE_DIR"
|
||||
chmod $ZAF_FILES_UMASK "$ZAF_CACHE_DIR"
|
||||
fi
|
||||
if [ -w $ZAF_CACHE_DIR ]; then
|
||||
zaf_trc "Cache: Removing stale entries"
|
||||
(cd $ZAF_CACHE_DIR && find ./ -type f -name '*.info' -mmin +1 | \
|
||||
while read line ; do
|
||||
rm -f $line $(basename $line .info)
|
||||
done
|
||||
)
|
||||
else
|
||||
zaf_err "Cache dir is not accessible! Become root or member of $ZAF_FILES_GID group!"
|
||||
fi
|
||||
[ -z "$ZAF_CACHE_DIR" ] && ZAF_CACHE_DIR=${ZAF_TMP_DIR}/zafc
|
||||
if [ -w $ZAF_CACHE_DIR ]; then
|
||||
zaf_trc "Cache: Removing stale entries"
|
||||
(cd $ZAF_CACHE_DIR && find ./ -type f -name '*.info' -mmin +1 2>/dev/null | \
|
||||
while read line ; do
|
||||
rm -f $line $(basename $line .info)
|
||||
done
|
||||
)
|
||||
else
|
||||
zaf_err "Cache dir not set."
|
||||
zaf_dbg "Cache dir $ZAF_CACHE_DIR is not accessible! Disabling cache."
|
||||
fi
|
||||
}
|
||||
|
||||
zaf_cache_clean(){
|
||||
if [ -n "$ZAF_CACHE_DIR" ]; then
|
||||
zaf_wrn "Removing cache entries"
|
||||
rm -rf "$ZAF_CACHE_DIR"
|
||||
(cd $ZAF_CACHE_DIR && find ./ -type f -name '*.info' 2>/dev/null | \
|
||||
while read line ; do
|
||||
rm -f $line $(basename $line .info)
|
||||
done
|
||||
)
|
||||
else
|
||||
zaf_err "Cache dir not set."
|
||||
zaf_dbg "Cache dir not set. Disabling cache."
|
||||
fi
|
||||
zaf_cache_init
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ zaf_get_plugin_url() {
|
||||
# $1 - control
|
||||
zaf_plugin_info() {
|
||||
local control="$1"
|
||||
local items
|
||||
|
||||
! [ -f "$control" ] && zaf_err "Control file $control not found."
|
||||
plugin=$(zaf_ctrl_get_global_block <"${control}" | zaf_block_get_option Plugin)
|
||||
@@ -62,9 +63,12 @@ zaf_plugin_info() {
|
||||
[ -n "$phome" ] && echo "Home: $phome"
|
||||
echo
|
||||
if zaf_is_plugin "$(basename $plugin)"; then
|
||||
echo -n "Defined items: "; zaf_list_plugin_items $plugin
|
||||
echo -n "Test items: "; zaf_list_plugin_items $plugin test
|
||||
echo -n "Precache items: "; zaf_list_plugin_items $plugin precache
|
||||
items=$(zaf_list_plugin_items $plugin)
|
||||
[ -n "$items" ] && echo -n "Defined items: "; echo $items
|
||||
items=$(zaf_list_plugin_items $plugin test)
|
||||
[ -n "$items" ] && echo -n "Test items: "; echo $items
|
||||
items=$(zaf_list_plugin_items $plugin precache)
|
||||
[ -n "$items" ] && echo -n "Precache items: "; echo $items
|
||||
else
|
||||
echo "Items: $pitems"
|
||||
fi
|
||||
@@ -227,6 +231,7 @@ zaf_list_plugin_items() {
|
||||
zaf_item_info() {
|
||||
local plugin
|
||||
local item
|
||||
local param
|
||||
|
||||
plugin=$(echo $1 | cut -d '.' -f 1)
|
||||
item=$(echo $1 | cut -d '.' -f 2-)
|
||||
@@ -237,9 +242,10 @@ zaf_item_info() {
|
||||
echo "Parameters:"
|
||||
zaf_ctrl_get_item_option $ZAF_PLUGINS_DIR/$plugin/control.zaf "$item" "Parameters" ; echo
|
||||
echo "Testparameters:"
|
||||
zaf_ctrl_get_item_option $ZAF_PLUGINS_DIR/$plugin/control.zaf "$item" "Testparameters" ; echo
|
||||
zaf_ctrl_get_item_option $ZAF_PLUGINS_DIR/$plugin/control.zaf "$item" "Testparameters"; echo
|
||||
echo "Precache:"
|
||||
zaf_ctrl_get_item_option $ZAF_PLUGINS_DIR/$plugin/control.zaf "$item" "Precache" ; echo
|
||||
zaf_ctrl_get_item_option $ZAF_PLUGINS_DIR/$plugin/control.zaf "$item" "Precache"; echo
|
||||
grep "UserParameter=$1" $ZAF_AGENT_CONFIGD/zaf_${plugin}.conf
|
||||
else
|
||||
zaf_err "No such item $item."
|
||||
fi
|
||||
|
||||
@@ -45,6 +45,11 @@ zaf_debug_init() {
|
||||
[ -n "$1" ] && export ZAF_LOG_STDERR="-s"
|
||||
}
|
||||
|
||||
zaf_tmp_init() {
|
||||
[ -z "$ZAF_TMP_DIR" ] && ZAF_TMP_DIR=/tmp/
|
||||
! [ -w "$ZAF_TMP_DIR" ] && zaf_err "Tmp dir $ZAF_TMP_DIR is not writable."
|
||||
}
|
||||
|
||||
zaf_version(){
|
||||
echo $ZAF_VERSION
|
||||
}
|
||||
@@ -242,23 +247,6 @@ zaf_date_add() {
|
||||
date -d "$1 seconds" "+%Y-%m-%d %H:%M:%S" 2>/dev/null || date -d "$(expr $(date +%s) + $1)" -D %s "+%Y-%m-%d %H:%M:%S"
|
||||
}
|
||||
|
||||
zaf_tmp_init() {
|
||||
[ -z "$ZAF_TMP_BASE" ] && ZAF_TMP_BASE=/tmp/zaf
|
||||
ZAF_TMP_DIR="${ZAF_TMP_BASE}-$(zaf_random)"
|
||||
mkdir -p $ZAF_TMP_DIR
|
||||
if zaf_is_root; then
|
||||
chown $ZAF_FILES_UID "$ZAF_TMP_DIR"
|
||||
chgrp $ZAF_FILES_GID "$ZAF_TMP_DIR"
|
||||
chmod $ZAF_FILES_UMASK "$ZAF_TMP_DIR"
|
||||
fi
|
||||
# If debug is on, do not remove tmp dir
|
||||
if [ "$ZAF_DEBUG" -le 3 ]; then
|
||||
trap "rm -rf ${ZAF_TMP_DIR}" EXIT
|
||||
else
|
||||
trap 'zaf_wrn "Leaving $ZAF_TMP_DIR" contents due to ZAF_DEBUG.' EXIT
|
||||
fi
|
||||
}
|
||||
|
||||
# Create temp file and return its name
|
||||
# $1 prefix or empty
|
||||
zaf_tmpfile() {
|
||||
|
||||
Reference in New Issue
Block a user