#! /bin/sh /usr/share/dpatch/dpatch-run ## zap_restart.dpatch by Tzafrir Cohen ## ## All lines beginning with `## DP:' are a description of the patch. ## DP: Adds a CLI command "zap restart" that destroys all zaptel channels and ## DP: re-loads zaptel configuration from scratch. ## DP: Thus we have a "reload" for zaptel @DPATCH@ --- asterisk-1.2.6/channels/chan_zap.c 2006-04-09 02:40:48.000000000 +0300 +++ asterisk-new/channels/chan_zap.c 2006-04-09 04:15:46.000000000 +0300 @@ -9656,6 +9656,47 @@ return RESULT_FAILURE; } +static int setup_zap(int reload); +static int zap_restart(void) +{ + if (option_verbose > 0) + ast_verbose(VERBOSE_PREFIX_1 "Destroying channels and reloading zaptel configuration.\n"); + while (iflist) { + if (option_debug) + ast_log(LOG_DEBUG, "Destroying zaptel channel no. %d\n", iflist->channel); + /* Also updates iflist: */ + destroy_channel(NULL, iflist, 1); + } + if (option_debug) + ast_log(LOG_DEBUG, "Channels destroyed. Now re-reading config.\n"); + if (setup_zap(0) != 0) { + ast_log(LOG_WARNING, "Reload channels from zap config failed!\n"); + return 1; + } + return 0; +} + +static int zap_restart_cmd(int fd, int argc, char **argv) +{ + if (argc != 2) { + return RESULT_SHOWUSAGE; + } + + if (zap_restart() != 0) + return RESULT_FAILURE; + return RESULT_SUCCESS; +} + +static int action_zaprestart(struct mansession *s, struct message *m) +{ + if (zap_restart() != 0) { + astman_send_error(s, m, "Failed rereading zaptel configuration"); + return 1; + } + astman_send_ack(s, m, "ZapRestart: Success"); + return 0; +} + static int zap_show_channels(int fd, int argc, char **argv) { #define FORMAT "%7s %-10.10s %-15.15s %-10.10s %-20.20s\n" @@ -9965,6 +10005,10 @@ "Usage: zap destroy channel \n" " DON'T USE THIS UNLESS YOU KNOW WHAT YOU ARE DOING. Immediately removes a given channel, whether it is in use or not\n"; +static char zap_restart_usage[] = + "Usage: zap restart\n" + " fully restarts the zaptel channels: destroys them all and then re-reads from config.\n"; + static struct ast_cli_entry zap_cli[] = { { { "zap", "show", "cadences", NULL }, handle_zap_show_cadences, "List cadences", zap_show_cadences_help }, @@ -9974,6 +10018,8 @@ "Show information on a channel", show_channel_usage }, { {"zap", "destroy", "channel", NULL}, zap_destroy_channel, "Destroy a channel", destroy_channel_usage }, + { {"zap", "restart", NULL}, zap_restart_cmd, + "Fully restart zaptel channels", zap_restart_usage }, { {"zap", "show", "status", NULL}, zap_show_status, "Show all Zaptel cards status", zap_show_status_usage }, };