Moved daemonization earlier to ensure that libmysqld is used by one process only.
This commit is contained in:
149
core/gateway.c
149
core/gateway.c
@ -238,7 +238,6 @@ char ddopt[1024];
|
|||||||
int l;
|
int l;
|
||||||
|
|
||||||
l = atexit(skygw_logmanager_exit);
|
l = atexit(skygw_logmanager_exit);
|
||||||
l = atexit(mysql_library_end);
|
|
||||||
|
|
||||||
if (l != 0) {
|
if (l != 0) {
|
||||||
fprintf(stderr, "Couldn't register exit function.\n");
|
fprintf(stderr, "Couldn't register exit function.\n");
|
||||||
@ -246,6 +245,81 @@ char ddopt[1024];
|
|||||||
|
|
||||||
atexit(datadir_cleanup);
|
atexit(datadir_cleanup);
|
||||||
|
|
||||||
|
|
||||||
|
for (n = 0; n < argc; n++)
|
||||||
|
{
|
||||||
|
if (strcmp(argv[n], "-d") == 0)
|
||||||
|
{
|
||||||
|
/** Debug mode, maxscale runs in this same process */
|
||||||
|
daemon_mode = 0;
|
||||||
|
}
|
||||||
|
if (strncmp(argv[n], "-c", 2) == 0)
|
||||||
|
{
|
||||||
|
int s=2;
|
||||||
|
|
||||||
|
while (argv[n][s] == 0 && s<10) s++;
|
||||||
|
|
||||||
|
if (s==10) {
|
||||||
|
skygw_log_write(
|
||||||
|
NULL, LOGFILE_ERROR,
|
||||||
|
"Fatal : missing file name. \n"
|
||||||
|
"Unable to find a MaxScale configuration file, "
|
||||||
|
"either install one in /etc/MaxScale.cnf, "
|
||||||
|
"$MAXSCALE_HOME/etc/MaxScale.cnf "
|
||||||
|
"or use the -c option with configuration file name. "
|
||||||
|
"Exiting.\n");
|
||||||
|
}
|
||||||
|
cnf_file = &argv[n][s];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maxscale must be daemonized before opening files, initializing
|
||||||
|
* embedded MariaDB and in general, as early as possible.
|
||||||
|
*/
|
||||||
|
if (daemon_mode == 1)
|
||||||
|
{
|
||||||
|
if (sigfillset(&sigset) != 0) {
|
||||||
|
skygw_log_write(NULL,
|
||||||
|
LOGFILE_ERROR,
|
||||||
|
"sigfillset() error %s\n",
|
||||||
|
strerror(errno));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sigdelset(&sigset, SIGHUP) != 0) {
|
||||||
|
skygw_log_write(NULL,
|
||||||
|
LOGFILE_ERROR,
|
||||||
|
"sigdelset(SIGHUP) error %s\n",
|
||||||
|
strerror(errno));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sigdelset(&sigset, SIGTERM) != 0) {
|
||||||
|
skygw_log_write(NULL,
|
||||||
|
LOGFILE_ERROR,
|
||||||
|
"sigdelset(SIGTERM) error %s\n",
|
||||||
|
strerror(errno));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sigprocmask(SIG_SETMASK, &sigset, NULL) != 0) {
|
||||||
|
skygw_log_write(NULL,
|
||||||
|
LOGFILE_ERROR,
|
||||||
|
"sigprocmask() error %s\n",
|
||||||
|
strerror(errno));
|
||||||
|
}
|
||||||
|
|
||||||
|
signal_set(SIGHUP, sighup_handler);
|
||||||
|
signal_set(SIGTERM, sigterm_handler);
|
||||||
|
|
||||||
|
gw_daemonize();
|
||||||
|
}
|
||||||
|
|
||||||
|
l = atexit(mysql_library_end);
|
||||||
|
|
||||||
|
if (l != 0) {
|
||||||
|
fprintf(stderr, "Couldn't register exit function.\n");
|
||||||
|
}
|
||||||
|
|
||||||
if ((home = getenv("MAXSCALE_HOME")) != NULL)
|
if ((home = getenv("MAXSCALE_HOME")) != NULL)
|
||||||
{
|
{
|
||||||
sprintf(mysql_home, "%s/mysql", home);
|
sprintf(mysql_home, "%s/mysql", home);
|
||||||
@ -295,33 +369,6 @@ char ddopt[1024];
|
|||||||
skygw_logmanager_init(NULL, 3, argv);
|
skygw_logmanager_init(NULL, 3, argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for (n = 0; n < argc; n++)
|
|
||||||
{
|
|
||||||
if (strcmp(argv[n], "-d") == 0)
|
|
||||||
{
|
|
||||||
// Debug mode
|
|
||||||
daemon_mode = 0;
|
|
||||||
}
|
|
||||||
if (strncmp(argv[n], "-c", 2) == 0)
|
|
||||||
{
|
|
||||||
int s=2;
|
|
||||||
|
|
||||||
while (argv[n][s] == 0 && s<10) s++;
|
|
||||||
|
|
||||||
if (s==10) {
|
|
||||||
skygw_log_write(
|
|
||||||
NULL, LOGFILE_ERROR,
|
|
||||||
"Fatal : missing file name. \n"
|
|
||||||
"Unable to find a MaxScale configuration file, either "
|
|
||||||
"install one in /etc/MaxScale.cnf, $MAXSCALE_HOME/etc/MaxScale.cnf "
|
|
||||||
"or use the -c option with configuration file name. Exiting.\n");
|
|
||||||
}
|
|
||||||
cnf_file = &argv[n][s];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cnf_file == NULL) {
|
if (cnf_file == NULL) {
|
||||||
skygw_log_write(
|
skygw_log_write(
|
||||||
NULL, LOGFILE_ERROR,
|
NULL, LOGFILE_ERROR,
|
||||||
@ -344,10 +391,15 @@ char ddopt[1024];
|
|||||||
if (mysql_library_init(num_elements, server_options, server_groups))
|
if (mysql_library_init(num_elements, server_options, server_groups))
|
||||||
{
|
{
|
||||||
skygw_log_write_flush(
|
skygw_log_write_flush(
|
||||||
NULL, LOGFILE_ERROR,
|
NULL,
|
||||||
"Fatal : mysql_library_init failed, %s. This is mandatory component, required "
|
LOGFILE_ERROR,
|
||||||
"by router services and the MaxScale core, the MaxScale can't continue without it. Exiting.\n"
|
"Fatal : mysql_library_init failed, %s. This is mandatory "
|
||||||
"%s : %d\n", mysql_error(NULL), __FILE__, __LINE__);
|
"component, required by router services and the MaxScale core, "
|
||||||
|
"the MaxScale can't continue without it. Exiting.\n"
|
||||||
|
"%s : %d\n",
|
||||||
|
mysql_error(NULL),
|
||||||
|
__FILE__,
|
||||||
|
__LINE__);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -359,34 +411,11 @@ char ddopt[1024];
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
skygw_log_write(NULL, LOGFILE_MESSAGE, "SkySQL Gateway (C) SkySQL Ab 2013\n");
|
skygw_log_write(NULL, LOGFILE_MESSAGE, "SkySQL MaxScale (C) SkySQL Ab 2013\n");
|
||||||
|
skygw_log_write_flush(NULL,
|
||||||
if (daemon_mode == 1)
|
LOGFILE_MESSAGE,
|
||||||
{
|
"MaxScale is starting, PID %i\n",
|
||||||
if (sigfillset(&sigset) != 0) {
|
getpid());
|
||||||
skygw_log_write(NULL, LOGFILE_ERROR, "sigfillset() error %s\n", strerror(errno));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sigdelset(&sigset, SIGHUP) != 0) {
|
|
||||||
skygw_log_write(NULL, LOGFILE_ERROR, "sigdelset(SIGHUP) error %s\n", strerror(errno));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sigdelset(&sigset, SIGTERM) != 0) {
|
|
||||||
skygw_log_write(NULL, LOGFILE_ERROR, "sigdelset(SIGTERM) error %s\n", strerror(errno));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sigprocmask(SIG_SETMASK, &sigset, NULL) != 0) {
|
|
||||||
skygw_log_write(NULL, LOGFILE_ERROR, "sigprocmask() error %s\n", strerror(errno));
|
|
||||||
}
|
|
||||||
|
|
||||||
signal_set(SIGHUP, sighup_handler);
|
|
||||||
signal_set(SIGTERM, sigterm_handler);
|
|
||||||
|
|
||||||
gw_daemonize();
|
|
||||||
}
|
|
||||||
|
|
||||||
skygw_log_write(NULL, LOGFILE_MESSAGE, "MaxScale is starting, PID %i\n", getpid());
|
|
||||||
|
|
||||||
poll_init();
|
poll_init();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user