Uptime counters (was RE: [Asterisk-Users] Bayonne and
Asterisk)
John Todd
jtodd at loligo.com
Thu Nov 20 09:05:32 MST 2003
At 9:37 AM -0500 11/20/03, Andrew Kohlsmith wrote:
>
>> You can not rotate logs with out dropping calls, and if logs get a
>> little over 2Gbs Asterisk will crashes...
>
>Why not? Why are the logfiles kept open for the entire life of Asterisk?
>Hell even my heavily loaded qmail server isn't this braindead in that
>regard.
>
>If * can be patched to open, write, close for every log write it is trivial
>to rotate logs:
>
>mv /path/to/logfile /path/to/logfile.old
>while fuser -s /path/to/logfile.old ; do sleep 1 ; done
>bzip2 -1 /path/to/logfile.old
>
>and you're done. mv does not change the inode, so asterisk does not notice
>it if it _is_ in the middle of a write, and the fuser do/while loop waits
>patiently until asterisk is done with the file. Next time Asterisk tries
>to open the file it will fail (since it doesn't exist) and will recreate
>it. Piece of cake.
>
>Regards,
>Andrew
Whoever said that Asterisk cannot rotate it's logfile without
dropping calls was incorrect. There is a command built into Asterisk
as of last month called "logger reload" - try:
asterisk -rx "logger reload"
See: http://bugs.digium.com/bug_view_page.php?bug_id=0000265
Or:
>From: markster at lists.digium.com
>To: asterisk-cvs at lists.digium.com
>Subject: [Asterisk-cvs] asterisk logger.c,1.4,1.5
>Date: Thu, 2 Oct 2003 02:38:59 -0400 (EDT)
>
>Update of /usr/cvsroot/asterisk
>In directory mongoose.digium.com:/tmp/cvs-serv31710
>
>Modified Files:
> logger.c
>Log Message:
>Add "logger reload" CLI (bug #345)
>
>
>Index: logger.c
>===================================================================
>RCS file: /usr/cvsroot/asterisk/logger.c,v
>retrieving revision 1.4
>retrieving revision 1.5
>diff -u -d -r1.4 -r1.5
>--- logger.c 8 Sep 2003 16:48:06 -0000 1.4
>+++ logger.c 2 Oct 2003 06:40:10 -0000 1.5
>@@ -21,6 +21,7 @@
> #include <asterisk/channel.h>
> #include <asterisk/config.h>
> #include <asterisk/term.h>
>+#include <asterisk/cli.h>
> #include <string.h>
> #include <stdlib.h>
> #include <errno.h>
>@@ -173,22 +174,22 @@
>
> }
>
>-static struct verb {
>- void (*verboser)(const char *string, int opos, int
>replacelast, int complete);
>- struct verb *next;
>-} *verboser = NULL;
>-
>-int init_logger(void)
>+int reload_logger(void)
> {
> char tmp[AST_CONFIG_MAX_PATH];
>+ ast_mutex_lock(&loglock);
>+ if (eventlog)
>+ fclose(eventlog);
> mkdir((char *)ast_config_AST_LOG_DIR, 0755);
> snprintf(tmp, sizeof(tmp), "%s/%s", (char
>*)ast_config_AST_LOG_DIR, EVENTLOG);
> eventlog = fopen((char *)tmp, "a");
>+ ast_mutex_unlock(&loglock);
>+
> if (eventlog) {
> init_logger_chain();
>- ast_log(LOG_EVENT, "Started Asterisk Event Logger\n");
>+ ast_log(LOG_EVENT, "Restarted Asterisk Event Logger\n");
> if (option_verbose)
>- ast_verbose("Asterisk Event Logger Started
>%s\n",(char *)tmp);
>+ ast_verbose("Asterisk Event Logger restarted\n");
> return 0;
> } else
> ast_log(LOG_ERROR, "Unable to create event log:
>%s\n", strerror(errno));
>@@ -196,28 +197,55 @@
> return -1;
> }
>
>-int reload_logger(void)
>+static int handle_logger_reload(int fd, int argc, char *argv[])
>+{
>+ if(reload_logger())
>+ {
>+ ast_cli(fd, "Failed to reloadthe logger\n");
>+ return RESULT_FAILURE;
>+ }
>+ else
>+ return RESULT_SUCCESS;
>+}
>+
>+static struct verb {
>+ void (*verboser)(const char *string, int opos, int
>replacelast, int complete);
>+ struct verb *next;
>+} *verboser = NULL;
>+
>+
>+static char logger_reload_help[] =
>+"Usage: logger reload\n"
>+" Reopens the log files. Use after a rotating the log files\n";
>+
>+static struct ast_cli_entry reload_logger_cli =
>+ { { "logger", "reload", NULL },
>+ handle_logger_reload, "Reopens the log files",
>+ logger_reload_help };
>+
>+
>+int init_logger(void)
> {
> char tmp[AST_CONFIG_MAX_PATH];
>- ast_mutex_lock(&loglock);
>- if (eventlog)
>- fclose(eventlog);
>+
>+ /* register the relaod logger cli command */
>+ ast_cli_register(&reload_logger_cli);
>+
> mkdir((char *)ast_config_AST_LOG_DIR, 0755);
> snprintf(tmp, sizeof(tmp), "%s/%s", (char
>*)ast_config_AST_LOG_DIR, EVENTLOG);
> eventlog = fopen((char *)tmp, "a");
>- ast_mutex_unlock(&loglock);
>-
> if (eventlog) {
> init_logger_chain();
>- ast_log(LOG_EVENT, "Restarted Asterisk Event Logger\n");
>+ ast_log(LOG_EVENT, "Started Asterisk Event Logger\n");
> if (option_verbose)
>- ast_verbose("Asterisk Event Logger restarted\n");
>+ ast_verbose("Asterisk Event Logger Started
>%s\n",(char *)tmp);
> return 0;
> } else
> ast_log(LOG_ERROR, "Unable to create event log:
>%s\n", strerror(errno));
> init_logger_chain();
> return -1;
> }
>+
>
> extern void ast_log(int level, const char *file, int line, const
>char *function, const char *fmt, ...)
> {
JT
More information about the asterisk-users
mailing list