Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new global configuration directive shutdown_script. #1

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/man/man5/keepalived.conf.5
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ and
smtp_connect_timeout 30 # integer, seconds
router_id my_hostname # string identifying the machine,
# (doesn't have to be hostname).

# Script to run on keepalived shutdown
shutdown_script "/bin/true arg1 arg2"
}


Expand Down
7 changes: 7 additions & 0 deletions keepalived/core/global_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ email_handler(vector strvec)
free_strvec(email_vec);
}

static void
shutdown_script_handler (vector strvec) {
FREE_PTR(data->shutdown_script);
data->shutdown_script = set_value(strvec);
}

void
global_init_keywords(void)
{
Expand All @@ -92,4 +98,5 @@ global_init_keywords(void)
install_keyword("smtp_server", &smtpip_handler);
install_keyword("smtp_connect_timeout", &smtpto_handler);
install_keyword("notification_email", &email_handler);
install_keyword("shutdown_script", &shutdown_script_handler);
}
30 changes: 30 additions & 0 deletions keepalived/core/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include "signals.h"
#include "pidfile.h"
#include "logger.h"
#include "global_parser.h"
#include "notify.h"

/* global var */
char *conf_file = NULL; /* Configuration file */
Expand Down Expand Up @@ -94,6 +96,15 @@ sighup(void *v, int sig)
kill(checkers_child, SIGHUP);
}

vector main_init_keywords(void) {
vector keywords;

/* global definitions mapping */
global_init_keywords();

return keywords;
}

/* Terminate handler */
void
sigend(void *v, int sig)
Expand All @@ -102,6 +113,21 @@ sigend(void *v, int sig)

/* register the terminate thread */
log_message(LOG_INFO, "Terminating on signal");


/* do we have any shutdown script to run? */
if (
data != NULL &&
data->shutdown_script != NULL &&
strlen(data->shutdown_script) > 0
) {
log_message(
LOG_INFO,
"Running shutdown script: '%s'", data->shutdown_script
);
notify_exec(data->shutdown_script);
}

thread_add_terminate_event(master);

if (vrrp_child > 0) {
Expand Down Expand Up @@ -323,6 +349,10 @@ main(int argc, char **argv)
goto end;
}

/* Parse configuration file */
data = alloc_global_data();
init_data(conf_file, main_init_keywords);

/* daemonize process */
if (!(debug & 2))
xdaemon(0, 0, 0);
Expand Down
1 change: 1 addition & 0 deletions keepalived/include/global_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ typedef struct _conf_data {
struct sockaddr_storage smtp_server;
long smtp_connection_to;
list email;
char *shutdown_script;
} conf_data_t;

/* Global vars exported */
Expand Down