Introduce astcachedir, to be used for temporary bucket files

As described in the issue, /tmp is not a suitable location for a
large amount of cached media files, since most distributions make
/tmp a RAM-based tmpfs mount with limited capacity.

I opted for a location that can be configured separately, as opposed
to using a subdirectory of spooldir, given the different storage
profile (transient files vs files that might stay there indefinitely).

This commit just makes the cache directory configurable, and changes
the default location from /tmp to /var/cache/asterisk.

ASTERISK-29143

Change-Id: Ic54e95199405abacd9e509cef5f08fa14c510b5d
This commit is contained in:
lvl 2020-10-29 12:25:27 +01:00 committed by Friendly Automation
parent c8b6340023
commit b08427134f
14 changed files with 36 additions and 4 deletions

View File

@ -49,6 +49,7 @@ DESTDIR?=$(INSTALL_PATH)
export DESTDIR
export INSTALL_PATH # Additional prefix for the following paths
export ASTCACHEDIR
export ASTETCDIR # Path for config files
export ASTVARRUNDIR
export ASTSPOOLDIR
@ -555,7 +556,7 @@ update:
NEWHEADERS=$(notdir $(wildcard include/asterisk/*.h))
OLDHEADERS=$(filter-out $(NEWHEADERS) $(notdir $(DESTDIR)$(ASTHEADERDIR)),$(notdir $(wildcard $(DESTDIR)$(ASTHEADERDIR)/*.h)))
INSTALLDIRS="$(ASTLIBDIR)" "$(ASTMODDIR)" "$(ASTSBINDIR)" "$(ASTETCDIR)" "$(ASTVARRUNDIR)" \
INSTALLDIRS="$(ASTLIBDIR)" "$(ASTMODDIR)" "$(ASTSBINDIR)" "$(ASTCACHEDIR)" "$(ASTETCDIR)" "$(ASTVARRUNDIR)" \
"$(ASTSPOOLDIR)" "$(ASTSPOOLDIR)/dictate" "$(ASTSPOOLDIR)/meetme" \
"$(ASTSPOOLDIR)/monitor" "$(ASTSPOOLDIR)/system" "$(ASTSPOOLDIR)/tmp" \
"$(ASTSPOOLDIR)/voicemail" "$(ASTSPOOLDIR)/recording" \
@ -779,7 +780,8 @@ define INSTALL_CONFIGS
done ; \
if [ "$(OVERWRITE)" = "y" ]; then \
echo "Updating asterisk.conf" ; \
sed -e 's|^astetcdir.*$$|astetcdir => $(ASTETCDIR)|' \
sed -e 's|^astcachedir.*$$|astcachedir => $(ASTCACHEDIR)|' \
-e 's|^astetcdir.*$$|astetcdir => $(ASTETCDIR)|' \
-e 's|^astmoddir.*$$|astmoddir => $(ASTMODDIR)|' \
-e 's|^astvarlibdir.*$$|astvarlibdir => $(ASTVARLIBDIR)|' \
-e 's|^astdbdir.*$$|astdbdir => $(ASTDBDIR)|' \
@ -1041,6 +1043,7 @@ uninstall-all: _uninstall uninstall-headers
rm -rf "$(DESTDIR)$(ASTSPOOLDIR)"
rm -rf "$(DESTDIR)$(ASTETCDIR)"
rm -rf "$(DESTDIR)$(ASTLOGDIR)"
rm -rf "$(DESTDIR)$(ASTCACHEDIR)"
menuconfig: menuselect

View File

@ -26,6 +26,7 @@ trap cleanup_tmp 0
src="$1"
dst="$2"
sed <"$src" \
-e "s|__ASTERISK_CACHE_DIR__|$ASTCACHEDIR|g" \
-e "s|__ASTERISK_DATA_DIR__|$ASTDATADIR|g" \
-e "s|__ASTERISK_DB_DIR__|$ASTDBDIR|g" \
-e "s|__ASTERISK_ETC_DIR__|$ASTETCDIR|g" \

View File

@ -7,6 +7,7 @@ cat << END
*/
#define DEFAULT_CONFIG_FILE "${INSTALL_PATH}${ASTCONFPATH}"
#define DEFAULT_CACHE_DIR "${INSTALL_PATH}${ASTCACHEDIR}"
#define DEFAULT_CONFIG_DIR "${INSTALL_PATH}${ASTETCDIR}"
#define DEFAULT_MODULE_DIR "${INSTALL_PATH}${ASTMODDIR}"
#define DEFAULT_AGI_DIR "${INSTALL_PATH}${AGI_DIR}"

View File

@ -32,6 +32,7 @@ LOCAL_CFLAGS=`echo $CFLAGS | ${EXTREGEX} 's/-pipe\s*//g' | ${EXTREGEX} 's/-[Wmp]
cat <<EOF > "$PPATH/asterisk.pc"
install_prefix=$INSTALL_PREFIX
version_number=$ASTERISKVERSIONNUM
cachedir=$ASTCACHEDIR
etcdir=$ASTETCDIR
libdir=$ASTLIBDIR
varlibdir=$ASTVARLIBDIR

View File

@ -1,4 +1,5 @@
[directories](!)
astcachedir => /var/cache/asterisk
astetcdir => /etc/asterisk
astmoddir => /usr/lib/asterisk/modules
astvarlibdir => /var/lib/asterisk

3
configure vendored
View File

@ -1295,6 +1295,7 @@ BUILD_OS
BUILD_VENDOR
BUILD_CPU
BUILD_PLATFORM
astcachedir
astvarrundir
astlogdir
astspooldir
@ -4660,6 +4661,7 @@ $as_echo "$ac_cv_safe_to_define___extensions__" >&6; }
# System default paths
astsbindir='${sbindir}'
astcachedir='${localstatedir}/cache/asterisk'
astetcdir='${sysconfdir}/asterisk'
astheaderdir='${includedir}/asterisk'
astlibdir='${libdir}'
@ -4728,6 +4730,7 @@ $as_echo "#define _DARWIN_UNLIMITED_SELECT 1" >>confdefs.h
;;
solaris*)
if test ${prefix} = 'NONE'; then
astcachedir=/var/cache/asterisk
astetcdir=/var/etc/asterisk
astsbindir=/opt/asterisk/sbin
astlibdir=/opt/asterisk/lib

View File

@ -34,6 +34,7 @@ AC_USE_SYSTEM_EXTENSIONS dnl note- does not work on FreeBSD
# System default paths
AC_SUBST([astsbindir], ['${sbindir}'])dnl
AC_SUBST([astcachedir], ['${localstatedir}/cache/asterisk'])dnl
AC_SUBST([astetcdir], ['${sysconfdir}/asterisk'])dnl
AC_SUBST([astheaderdir], ['${includedir}/asterisk'])dnl
AC_SUBST([astlibdir], ['${libdir}'])dnl
@ -98,6 +99,7 @@ case "${host_os}" in
;;
solaris*)
if test ${prefix} = 'NONE'; then
astcachedir=/var/cache/asterisk
astetcdir=/var/etc/asterisk
astsbindir=/opt/asterisk/sbin
astlibdir=/opt/asterisk/lib

View File

@ -0,0 +1,9 @@
Subject: Core
The location where the media cache stores its temporary files
is no longer hardcoded to /tmp but can now be configured separately
via the astcachedir config variable in asterisk.conf.
The default location for astcachedir is now /var/cache/asterisk
instead of /tmp, please make sure to manually cleanup and/or
migrate the temporary files in /tmp after upgrading.

View File

@ -18,6 +18,7 @@
#ifndef _ASTERISK_PATHS_H
#define _ASTERISK_PATHS_H
extern const char *ast_config_AST_CACHE_DIR;
extern const char *ast_config_AST_CONFIG_DIR;
extern const char *ast_config_AST_CONFIG_FILE;
extern const char *ast_config_AST_MODULE_DIR;

View File

@ -73,6 +73,7 @@
#include "asterisk/json.h"
#include "asterisk/file.h"
#include "asterisk/module.h"
#include "asterisk/paths.h"
/*! \brief Number of buckets for the container of schemes */
#define SCHEME_BUCKETS 53
@ -899,7 +900,7 @@ int ast_bucket_file_temporary_create(struct ast_bucket_file *file)
{
int fd;
ast_copy_string(file->path, "/tmp/bucket-XXXXXX", sizeof(file->path));
snprintf(file->path, sizeof(file->path), "%s/bucket-XXXXXX", ast_config_AST_CACHE_DIR);
fd = mkstemp(file->path);
if (fd < 0) {

View File

@ -98,6 +98,7 @@ char record_cache_dir[AST_CACHE_DIR_LEN] = DEFAULT_TMP_DIR;
char ast_defaultlanguage[MAX_LANGUAGE] = DEFAULT_LANGUAGE;
struct _cfg_paths {
char cache_dir[PATH_MAX];
char config_dir[PATH_MAX];
char module_dir[PATH_MAX];
char spool_dir[PATH_MAX];
@ -125,6 +126,7 @@ struct _cfg_paths {
};
static struct _cfg_paths cfg_paths = {
.cache_dir = DEFAULT_CACHE_DIR,
.config_dir = DEFAULT_CONFIG_DIR,
.module_dir = DEFAULT_MODULE_DIR,
.spool_dir = DEFAULT_SPOOL_DIR,
@ -145,6 +147,7 @@ static struct _cfg_paths cfg_paths = {
.ctl_file = "asterisk.ctl",
};
const char *ast_config_AST_CACHE_DIR = cfg_paths.cache_dir;
const char *ast_config_AST_CONFIG_DIR = cfg_paths.config_dir;
const char *ast_config_AST_CONFIG_FILE = cfg_paths.config_file;
const char *ast_config_AST_MODULE_DIR = cfg_paths.module_dir;
@ -254,7 +257,9 @@ void load_asterisk_conf(void)
}
for (v = ast_variable_browse(cfg, "directories"); v; v = v->next) {
if (!strcasecmp(v->name, "astetcdir")) {
if (!strcasecmp(v->name, "astcachedir")) {
ast_copy_string(cfg_paths.cache_dir, v->value, sizeof(cfg_paths.cache_dir));
} else if (!strcasecmp(v->name, "astetcdir")) {
ast_copy_string(cfg_paths.config_dir, v->value, sizeof(cfg_paths.config_dir));
} else if (!strcasecmp(v->name, "astspooldir")) {
ast_copy_string(cfg_paths.spool_dir, v->value, sizeof(cfg_paths.spool_dir));

View File

@ -327,6 +327,8 @@ const char *ast_str_retrieve_variable(struct ast_str **str, ssize_t maxlen, stru
s = ast_str_buffer(*str);
} else if (!strcmp(var, "SYSTEMNAME")) {
s = ast_config_AST_SYSTEM_NAME;
} else if (!strcmp(var, "ASTCACHEDIR")) {
s = ast_config_AST_CACHE_DIR;
} else if (!strcmp(var, "ASTETCDIR")) {
s = ast_config_AST_CONFIG_DIR;
} else if (!strcmp(var, "ASTMODDIR")) {

View File

@ -97,6 +97,7 @@ ASTMODDIR = @astmoddir@
ASTMANDIR = @astmandir@
astvarlibdir = @astvarlibdir@
ASTVARLIBDIR = @astvarlibdir@
ASTCACHEDIR = @astcachedir@
ASTDATADIR = @astdatadir@
ASTDBDIR = @astdbdir@
ASTKEYDIR = @astkeydir@

View File

@ -24,6 +24,7 @@ fi
set +e
if [ x"$USER_GROUP" != x ] ; then
chown -R $USER_GROUP $DESTDIR/var/cache/asterisk
chown -R $USER_GROUP $DESTDIR/var/lib/asterisk
chown -R $USER_GROUP $DESTDIR/var/spool/asterisk
chown -R $USER_GROUP $DESTDIR/var/log/asterisk