mirror of
https://github.com/limosek/zaf.git
synced 2024-11-22 02:19:06 +01:00
Repaired tmp and cache directory init and clean
This commit is contained in:
parent
4bdeaf9f9a
commit
ca4f170ca3
19
install.sh
19
install.sh
@ -180,7 +180,8 @@ zaf_configure(){
|
|||||||
fi
|
fi
|
||||||
zaf_get_option ZAF_GIT "Git is installed" "$ZAF_GIT" "$INSTALL_MODE"
|
zaf_get_option ZAF_GIT "Git is installed" "$ZAF_GIT" "$INSTALL_MODE"
|
||||||
zaf_get_option ZAF_CURL_INSECURE "Insecure curl (accept all certificates)" "1" "$INSTALL_MODE"
|
zaf_get_option ZAF_CURL_INSECURE "Insecure curl (accept all certificates)" "1" "$INSTALL_MODE"
|
||||||
zaf_get_option ZAF_TMP_BASE "Tmp directory prefix (\$USER will be added)" "/tmp/zaf" "$INSTALL_MODE"
|
zaf_get_option ZAF_TMP_DIR "Tmp directory" "/tmp/" "$INSTALL_MODE"
|
||||||
|
zaf_get_option ZAF_CACHE_DIR "Cache directory" "/tmp/zafc" "$INSTALL_MODE"
|
||||||
zaf_get_option ZAF_LIB_DIR "Libraries directory" "/usr/lib/zaf" "$INSTALL_MODE"
|
zaf_get_option ZAF_LIB_DIR "Libraries directory" "/usr/lib/zaf" "$INSTALL_MODE"
|
||||||
zaf_get_option ZAF_BIN_DIR "Directory to put binaries" "/usr/bin" "$INSTALL_MODE"
|
zaf_get_option ZAF_BIN_DIR "Directory to put binaries" "/usr/bin" "$INSTALL_MODE"
|
||||||
zaf_get_option ZAF_PLUGINS_DIR "Plugins directory" "${ZAF_LIB_DIR}/plugins" "$INSTALL_MODE"
|
zaf_get_option ZAF_PLUGINS_DIR "Plugins directory" "${ZAF_LIB_DIR}/plugins" "$INSTALL_MODE"
|
||||||
@ -214,7 +215,8 @@ zaf_configure(){
|
|||||||
zaf_set_option ZAF_AGENT_PKG "${ZAF_AGENT_PKG}"
|
zaf_set_option ZAF_AGENT_PKG "${ZAF_AGENT_PKG}"
|
||||||
zaf_set_option ZAF_GIT "${ZAF_GIT}"
|
zaf_set_option ZAF_GIT "${ZAF_GIT}"
|
||||||
zaf_set_option ZAF_CURL_INSECURE "${ZAF_CURL_INSECURE}"
|
zaf_set_option ZAF_CURL_INSECURE "${ZAF_CURL_INSECURE}"
|
||||||
zaf_set_option ZAF_TMP_BASE "$ZAF_TMP_BASE"
|
zaf_set_option ZAF_TMP_DIR "$ZAF_TMP_DIR"
|
||||||
|
zaf_set_option ZAF_CACHE_DIR "$ZAF_CACHE_DIR"
|
||||||
zaf_set_option ZAF_LIB_DIR "$ZAF_LIB_DIR"
|
zaf_set_option ZAF_LIB_DIR "$ZAF_LIB_DIR"
|
||||||
zaf_set_option ZAF_BIN_DIR "$ZAF_BIN_DIR"
|
zaf_set_option ZAF_BIN_DIR "$ZAF_BIN_DIR"
|
||||||
zaf_set_option ZAF_PLUGINS_DIR "$ZAF_PLUGINS_DIR"
|
zaf_set_option ZAF_PLUGINS_DIR "$ZAF_PLUGINS_DIR"
|
||||||
@ -240,6 +242,17 @@ zaf_configure(){
|
|||||||
zaf_configure_agent $ZAF_AGENT_OPTIONS "$@"
|
zaf_configure_agent $ZAF_AGENT_OPTIONS "$@"
|
||||||
zaf_add_agent_option "Include" "$ZAF_AGENT_CONFIGD"
|
zaf_add_agent_option "Include" "$ZAF_AGENT_CONFIGD"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if ! [ -d $ZAF_CACHE_DIR ]; then
|
||||||
|
mkdir -p "$ZAF_CACHE_DIR"
|
||||||
|
if zaf_is_root && [ -n "$ZAF_FILES_UID" ] && [ -n "$ZAF_FILES_GID" ]; then
|
||||||
|
zaf_wrn "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
|
||||||
|
fi
|
||||||
|
zaf_cache_init
|
||||||
}
|
}
|
||||||
|
|
||||||
zaf_install_all() {
|
zaf_install_all() {
|
||||||
@ -327,7 +340,6 @@ export ZAF_DIR="$ZAF_TMP_DIR/zaf"
|
|||||||
|
|
||||||
zaf_debug_init stderr
|
zaf_debug_init stderr
|
||||||
zaf_tmp_init
|
zaf_tmp_init
|
||||||
zaf_cache_init
|
|
||||||
|
|
||||||
# Read options as config for ZAF
|
# Read options as config for ZAF
|
||||||
for pair in "$@"; do
|
for pair in "$@"; do
|
||||||
@ -337,6 +349,7 @@ for pair in "$@"; do
|
|||||||
eval "C_${option}='$value'"
|
eval "C_${option}='$value'"
|
||||||
zaf_wrn "Overriding $option from cmdline."
|
zaf_wrn "Overriding $option from cmdline."
|
||||||
done
|
done
|
||||||
|
[ -z "$C_ZAF_TMP_DIR" ] && C_ZAF_TMP_DIR="/tmp/"
|
||||||
|
|
||||||
case $1 in
|
case $1 in
|
||||||
interactive)
|
interactive)
|
||||||
|
@ -1,36 +1,29 @@
|
|||||||
# Zaf cache related functions
|
# Zaf cache related functions
|
||||||
|
|
||||||
zaf_cache_init(){
|
zaf_cache_init(){
|
||||||
[ -z "$ZAF_CACHE_DIR" ] && ZAF_CACHE_DIR=${ZAF_TMP_BASE}c
|
[ -z "$ZAF_CACHE_DIR" ] && ZAF_CACHE_DIR=${ZAF_TMP_DIR}/zafc
|
||||||
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
|
if [ -w $ZAF_CACHE_DIR ]; then
|
||||||
zaf_trc "Cache: Removing stale entries"
|
zaf_trc "Cache: Removing stale entries"
|
||||||
(cd $ZAF_CACHE_DIR && find ./ -type f -name '*.info' -mmin +1 | \
|
(cd $ZAF_CACHE_DIR && find ./ -type f -name '*.info' -mmin +1 2>/dev/null | \
|
||||||
while read line ; do
|
while read line ; do
|
||||||
rm -f $line $(basename $line .info)
|
rm -f $line $(basename $line .info)
|
||||||
done
|
done
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
zaf_err "Cache dir is not accessible! Become root or member of $ZAF_FILES_GID group!"
|
zaf_dbg "Cache dir $ZAF_CACHE_DIR is not accessible! Disabling cache."
|
||||||
fi
|
|
||||||
else
|
|
||||||
zaf_err "Cache dir not set."
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
zaf_cache_clean(){
|
zaf_cache_clean(){
|
||||||
if [ -n "$ZAF_CACHE_DIR" ]; then
|
if [ -n "$ZAF_CACHE_DIR" ]; then
|
||||||
zaf_wrn "Removing cache entries"
|
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
|
else
|
||||||
zaf_err "Cache dir not set."
|
zaf_dbg "Cache dir not set. Disabling cache."
|
||||||
fi
|
fi
|
||||||
zaf_cache_init
|
zaf_cache_init
|
||||||
}
|
}
|
||||||
|
@ -45,6 +45,7 @@ zaf_get_plugin_url() {
|
|||||||
# $1 - control
|
# $1 - control
|
||||||
zaf_plugin_info() {
|
zaf_plugin_info() {
|
||||||
local control="$1"
|
local control="$1"
|
||||||
|
local items
|
||||||
|
|
||||||
! [ -f "$control" ] && zaf_err "Control file $control not found."
|
! [ -f "$control" ] && zaf_err "Control file $control not found."
|
||||||
plugin=$(zaf_ctrl_get_global_block <"${control}" | zaf_block_get_option Plugin)
|
plugin=$(zaf_ctrl_get_global_block <"${control}" | zaf_block_get_option Plugin)
|
||||||
@ -62,9 +63,12 @@ zaf_plugin_info() {
|
|||||||
[ -n "$phome" ] && echo "Home: $phome"
|
[ -n "$phome" ] && echo "Home: $phome"
|
||||||
echo
|
echo
|
||||||
if zaf_is_plugin "$(basename $plugin)"; then
|
if zaf_is_plugin "$(basename $plugin)"; then
|
||||||
echo -n "Defined items: "; zaf_list_plugin_items $plugin
|
items=$(zaf_list_plugin_items $plugin)
|
||||||
echo -n "Test items: "; zaf_list_plugin_items $plugin test
|
[ -n "$items" ] && echo -n "Defined items: "; echo $items
|
||||||
echo -n "Precache items: "; zaf_list_plugin_items $plugin precache
|
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
|
else
|
||||||
echo "Items: $pitems"
|
echo "Items: $pitems"
|
||||||
fi
|
fi
|
||||||
@ -227,6 +231,7 @@ zaf_list_plugin_items() {
|
|||||||
zaf_item_info() {
|
zaf_item_info() {
|
||||||
local plugin
|
local plugin
|
||||||
local item
|
local item
|
||||||
|
local param
|
||||||
|
|
||||||
plugin=$(echo $1 | cut -d '.' -f 1)
|
plugin=$(echo $1 | cut -d '.' -f 1)
|
||||||
item=$(echo $1 | cut -d '.' -f 2-)
|
item=$(echo $1 | cut -d '.' -f 2-)
|
||||||
@ -237,9 +242,10 @@ zaf_item_info() {
|
|||||||
echo "Parameters:"
|
echo "Parameters:"
|
||||||
zaf_ctrl_get_item_option $ZAF_PLUGINS_DIR/$plugin/control.zaf "$item" "Parameters" ; echo
|
zaf_ctrl_get_item_option $ZAF_PLUGINS_DIR/$plugin/control.zaf "$item" "Parameters" ; echo
|
||||||
echo "Testparameters:"
|
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:"
|
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
|
else
|
||||||
zaf_err "No such item $item."
|
zaf_err "No such item $item."
|
||||||
fi
|
fi
|
||||||
|
@ -45,6 +45,11 @@ zaf_debug_init() {
|
|||||||
[ -n "$1" ] && export ZAF_LOG_STDERR="-s"
|
[ -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(){
|
zaf_version(){
|
||||||
echo $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"
|
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
|
# Create temp file and return its name
|
||||||
# $1 prefix or empty
|
# $1 prefix or empty
|
||||||
zaf_tmpfile() {
|
zaf_tmpfile() {
|
||||||
|
Loading…
Reference in New Issue
Block a user