summaryrefslogtreecommitdiff
path: root/server-tools/instance-manager
diff options
context:
space:
mode:
authorunknown <knielsen@mysql.com>2006-05-18 11:56:50 +0200
committerunknown <knielsen@mysql.com>2006-05-18 11:56:50 +0200
commit1875f3155cab7ded3cf80cdc78b086a023aad774 (patch)
tree898111e646cb542afbc154fb8cba54d0605e12f7 /server-tools/instance-manager
parentde0e4a9a8fe58ff025554d6fe3db1641b3c9ffe4 (diff)
parent798e910bad712f24144a04403bcc46de04ead643 (diff)
downloadmariadb-git-1875f3155cab7ded3cf80cdc78b086a023aad774.tar.gz
Merge mysql.com:/usr/local/mysql/tmp_merge
into mysql.com:/usr/local/mysql/merge-5.1 mysql-test/lib/mtr_process.pl: Auto merged mysql-test/mysql-test-run.pl: Auto merged mysql-test/r/sp-error.result: Auto merged mysql-test/r/sp.result: Auto merged mysql-test/r/trigger-grant.result: Auto merged mysql-test/r/trigger.result: Auto merged mysql-test/t/sp.test: Auto merged mysql-test/t/trigger-grant.test: Auto merged mysql-test/t/trigger.test: Auto merged server-tools/instance-manager/options.h: Auto merged sql/field_conv.cc: Auto merged sql/item.cc: Auto merged sql/item.h: Auto merged sql/item_func.h: Auto merged sql/sql_base.cc: Auto merged sql/sql_insert.cc: Auto merged sql/share/errmsg.txt: Auto merged sql/sql_parse.cc: Auto merged sql/sql_yacc.yy: Auto merged server-tools/instance-manager/options.cc: Manual merge sql/item_func.cc: Manual merge sql/mysql_priv.h: Manual merge sql/sp_head.cc: Manual merge sql/sql_table.cc: Manual merge
Diffstat (limited to 'server-tools/instance-manager')
-rw-r--r--server-tools/instance-manager/manager.cc13
-rw-r--r--server-tools/instance-manager/manager.h2
-rw-r--r--server-tools/instance-manager/mysqlmanager.cc8
-rw-r--r--server-tools/instance-manager/options.cc57
-rw-r--r--server-tools/instance-manager/options.h1
5 files changed, 77 insertions, 4 deletions
diff --git a/server-tools/instance-manager/manager.cc b/server-tools/instance-manager/manager.cc
index 95f9029f648..90d9d04cd36 100644
--- a/server-tools/instance-manager/manager.cc
+++ b/server-tools/instance-manager/manager.cc
@@ -35,12 +35,12 @@
#endif
-static int create_pid_file(const char *pid_file_name)
+int create_pid_file(const char *pid_file_name, int pid)
{
if (FILE *pid_file= my_fopen(pid_file_name,
O_WRONLY | O_CREAT | O_BINARY, MYF(0)))
{
- fprintf(pid_file, "%d\n", (int) getpid());
+ fprintf(pid_file, "%d\n", (int) pid);
my_fclose(pid_file, MYF(0));
return 0;
}
@@ -138,8 +138,13 @@ void manager(const Options &options)
if (user_map.load(options.password_file_name))
return;
- /* write pid file */
- if (create_pid_file(options.pid_file_name))
+ /* write Instance Manager pid file */
+
+ log_info("IM pid file: '%s'; PID: %d.",
+ (const char *) options.pid_file_name,
+ (int) manager_pid);
+
+ if (create_pid_file(options.pid_file_name, manager_pid))
return;
sigset_t mask;
diff --git a/server-tools/instance-manager/manager.h b/server-tools/instance-manager/manager.h
index 12ed6b3b1ff..3ddf292132e 100644
--- a/server-tools/instance-manager/manager.h
+++ b/server-tools/instance-manager/manager.h
@@ -20,4 +20,6 @@ struct Options;
void manager(const Options &options);
+int create_pid_file(const char *pid_file_name, int pid);
+
#endif // INCLUDES_MYSQL_INSTANCE_MANAGER_MANAGER_H
diff --git a/server-tools/instance-manager/mysqlmanager.cc b/server-tools/instance-manager/mysqlmanager.cc
index d0b2cf2666c..ef714099de7 100644
--- a/server-tools/instance-manager/mysqlmanager.cc
+++ b/server-tools/instance-manager/mysqlmanager.cc
@@ -338,6 +338,14 @@ spawn:
/* Here we return to main, and fall into manager */
break;
default: // parent, success
+ pid= getpid(); /* Get our pid. */
+
+ log_info("Angel pid file: '%s'; PID: %d.",
+ (const char *) options.angel_pid_file_name,
+ (int) pid);
+
+ create_pid_file(Options::angel_pid_file_name, pid);
+
while (child_status == CHILD_OK && is_terminated == 0)
sigsuspend(&zeromask);
diff --git a/server-tools/instance-manager/options.cc b/server-tools/instance-manager/options.cc
index 85fea76c079..8de592f59b6 100644
--- a/server-tools/instance-manager/options.cc
+++ b/server-tools/instance-manager/options.cc
@@ -44,6 +44,7 @@ const char *Options::user= 0; /* No default value */
const char *default_password_file_name= QUOTE(DEFAULT_PASSWORD_FILE_NAME);
const char *default_log_file_name= QUOTE(DEFAULT_LOG_FILE_NAME);
const char *Options::config_file= QUOTE(DEFAULT_CONFIG_FILE);
+const char *Options::angel_pid_file_name= NULL;
#endif
const char *Options::log_file_name= default_log_file_name;
const char *Options::pid_file_name= QUOTE(DEFAULT_PID_FILE_NAME);
@@ -61,6 +62,9 @@ bool Options::is_forced_default_file= 0;
const char *Options::default_dbug_option= "d:t:i:O,im.trace";
#endif
+static const char * const ANGEL_PID_FILE_SUFFIX= ".angel.pid";
+static const int ANGEL_PID_FILE_SUFFIX_LEN= strlen(ANGEL_PID_FILE_SUFFIX);
+
/*
List of options, accepted by the instance manager.
List must be closed with empty option.
@@ -75,6 +79,7 @@ enum options {
#ifndef __WIN__
OPT_RUN_AS_SERVICE,
OPT_USER,
+ OPT_ANGEL_PID_FILE,
#else
OPT_INSTALL_SERVICE,
OPT_REMOVE_SERVICE,
@@ -91,6 +96,13 @@ static struct my_option my_long_options[] =
{ "help", '?', "Display this help and exit.",
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0 },
+#ifndef __WIN__
+ { "angel-pid-file", OPT_ANGEL_PID_FILE, "Pid file for angel process.",
+ (gptr *) &Options::angel_pid_file_name,
+ (gptr *) &Options::angel_pid_file_name,
+ 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
+#endif
+
{ "bind-address", OPT_BIND_ADDRESS, "Bind address to use for connection.",
(gptr *) &Options::bind_address, (gptr *) &Options::bind_address,
0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
@@ -312,6 +324,46 @@ int Options::load(int argc, char **argv)
get_one_option)) != 0)
goto err;
+#ifndef __WIN__
+ if (Options::run_as_service)
+ {
+ if (Options::angel_pid_file_name == NULL)
+ {
+ /*
+ Calculate angel pid file on the IM pid file basis: replace the
+ extension (everything after the last dot) of the pid file basename to
+ '.angel.pid'.
+ */
+
+ char *angel_pid_file_name;
+ char *base_name_ptr;
+ char *ext_ptr;
+
+ angel_pid_file_name= (char *) malloc(strlen(Options::pid_file_name) +
+ ANGEL_PID_FILE_SUFFIX_LEN);
+
+ strcpy(angel_pid_file_name, Options::pid_file_name);
+
+ base_name_ptr= strrchr(angel_pid_file_name, '/');
+
+ if (!base_name_ptr)
+ base_name_ptr= angel_pid_file_name + 1;
+
+ ext_ptr= strrchr(base_name_ptr, '.');
+ if (ext_ptr)
+ *ext_ptr= 0;
+
+ strcat(angel_pid_file_name, ANGEL_PID_FILE_SUFFIX);
+
+ Options::angel_pid_file_name= angel_pid_file_name;
+ }
+ else
+ {
+ Options::angel_pid_file_name= strdup(Options::angel_pid_file_name);
+ }
+ }
+#endif
+
return 0;
err:
@@ -323,6 +375,11 @@ void Options::cleanup()
/* free_defaults returns nothing */
if (Options::saved_argv != NULL)
free_defaults(Options::saved_argv);
+
+#ifndef __WIN__
+ if (Options::run_as_service)
+ free((void *) Options::angel_pid_file_name);
+#endif
}
#ifdef __WIN__
diff --git a/server-tools/instance-manager/options.h b/server-tools/instance-manager/options.h
index 06818288606..00a50a2acdb 100644
--- a/server-tools/instance-manager/options.h
+++ b/server-tools/instance-manager/options.h
@@ -35,6 +35,7 @@ struct Options
#else
static char run_as_service; /* handle_options doesn't support bool */
static const char *user;
+ static const char *angel_pid_file_name;
#endif
static bool is_forced_default_file;
static const char *log_file_name;