Author: mhabersack
Date: 2007-07-18 19:26:17 -0400 (Wed, 18 Jul 2007)
New Revision: 82257

Modified:
   trunk/mod_mono/ChangeLog
   trunk/mod_mono/man/mod_mono.8.in
   trunk/mod_mono/src/mod_mono.c
   trunk/mod_mono/src/mod_mono.h
Log:
2007-07-19  Marek Habersack  <[EMAIL PROTECTED]>

        * src/mod_mono.c (mono_execute_request): added support for
        restarting backends which disappeared.
        (mono_cmds): defined two new configuration directives:
        MonoXSPStartAttempts and MonoXSPStartWaitTime, used by code
        introduced above.
        
        * man/mod_mono.8.in: added documentation for the two new
        directives.


Modified: trunk/mod_mono/ChangeLog
===================================================================
--- trunk/mod_mono/ChangeLog    2007-07-18 23:23:30 UTC (rev 82256)
+++ trunk/mod_mono/ChangeLog    2007-07-18 23:26:17 UTC (rev 82257)
@@ -1,11 +1,22 @@
-2007-07-18  Marek Habersack  <[EMAIL PROTECTED]>
+2007-07-19  Marek Habersack  <[EMAIL PROTECTED]>
 
-       * src/mod_mono.c (mono_child_init): if APR has uid/gid support and
+       * src/mod_mono.c (mono_execute_request): added support for
+       restarting backends which disappeared.
+       (mono_cmds): defined two new configuration directives:
+       MonoXSPStartAttempts and MonoXSPStartWaitTime, used by code
+       introduced above.
+       
+       * man/mod_mono.8.in: added documentation for the two new
+       directives.
+
+2007-07-18  Marek Habersack  <[EMAIL PROTECTED]>
+
+       * src/mod_mono.c: if APR has uid/gid support and
        we're not compiling for WIN32, start the backends from the module
        post config handler, it avoids launching of many backends on
        startup.
 
-2007-07-14  Marek Habersack  <[EMAIL PROTECTED]>
+2007-07-14  Marek Habersack  <[EMAIL PROTECTED]>
 
        * src/mod_mono.c (do_command): added error logging
        (write_data): as above
@@ -15,7 +26,7 @@
        for non-zero status codes (the status code is ignored for Apache <
        2.0).
 
-2007-06-20  Marek Habersack  <[EMAIL PROTECTED]>
+2007-06-20  Marek Habersack  <[EMAIL PROTECTED]>
 
        * src/mod_mono.c (send_initial_data): added support for
        ServerAlias directive. Patch from Juraj Skripsky

Modified: trunk/mod_mono/man/mod_mono.8.in
===================================================================
--- trunk/mod_mono/man/mod_mono.8.in    2007-07-18 23:23:30 UTC (rev 82256)
+++ trunk/mod_mono/man/mod_mono.8.in    2007-07-18 23:26:17 UTC (rev 82257)
@@ -55,16 +55,27 @@
 if it's not already running. If set to False, most of these directives are
 useless.
 Default value: True
+.TP 
+.I "MonoXSPStartAttempts"
+Number of times mod_mono will attempt to start a backend which
+died. Value cannot be lower than 0.
+Default value: 3
 .TP
-.I MonoExecutablePath (Obsoleted, ignored)
+.I "MonoXSPStartWaitTime"
+Number of seconds to wait after starting the backend. This is to let
+the backend initialize properly before attempting to connect to
+it. Value cannot be lower than 2.
+Default value: 2
+.TP
+.I "MonoExecutablePath (Obsoleted, ignored)"
 Don't use this. It is ignored and has been left here for compatibility 
purposes.
 Default value: "/usr/bin/mono"
 .TP
-.I MonoPath
+.I "MonoPath"
 This value will be used to set the MONO_PATH environment variable.
 Default value: ""
 .TP
-.I MonoServerPath
+.I "MonoServerPath"
 The full path to the mod-mono-server script.
 Default value: "/usr/bin/mod-mono-server"
 .TP
@@ -73,7 +84,7 @@
 used to emulate windows I/O. It's used to set MONO_SHARED_DIR.
 Default value: "/tmp"
 .TP
-.I MonoDocumentRootDir
+.I "MonoDocumentRootDir"
 The directory passed in --root argument when launching mod-mono-server.
 .TP
 .I "MonoMaxCPUTime"
@@ -90,38 +101,38 @@
 is not available on your system, the directive will be ignored.
 Default value: system default
 .TP
-.I MonoApplications
+.I "MonoApplications"
 .TP
-.I AddMonoApplications
+.I "AddMonoApplications"
 This value will be passed to mod-mono-server.exe in the
 --applications option. See xsp(1) manual page for details.
 .TP
-.I MonoApplicationsConfigFile
+.I "MonoApplicationsConfigFile"
 The argument passed in --appconfigfile argument to mod-mono-server.
 Default value: NULL.
 .TP
-.I MonoApplicationsConfigDir
+.I "MonoApplicationsConfigDir"
 The argument passed in --appconfigdir argument to mod-mono-server.
 Default value: config/mod-mono-applications
 .PP
 Note that you must specify at least one of MonoApplications,
 MonoApplicationsConfigFile and MonoApplicationsConfigDir.
 .TP
-.I MonoAutoApplication
+.I "MonoAutoApplication"
 Enables or disables automatic ASP.NET applications discovery. By default
 it is enabled if you have no application configured. Otherwise, it's
 disabled. The possible values are 'enabled' or 'disabled'.
 .TP
-.I MonoDebug
+.I "MonoDebug"
 Runs mono in debug mode, which produces stack traces with line numbers.
 Default value: false.
 .TP
-.I MonoSetServerAlias
+.I "MonoSetServerAlias"
 Takes a server alias name. This is to be used inside <Directory> or
 <Location>.
 Default value: 'default' if the directive is not used.
 .TP
-.I MonoSetEnv
+.I "MonoSetEnv"
 Takes a string of 'name=value' pairs separated by semicolons. For each
 pair, it calls setenv (name, value) before running mod-mono-server.
 .SH SAMPLE CONFIGURATION

Modified: trunk/mod_mono/src/mod_mono.c
===================================================================
--- trunk/mod_mono/src/mod_mono.c       2007-07-18 23:23:30 UTC (rev 82256)
+++ trunk/mod_mono/src/mod_mono.c       2007-07-18 23:26:17 UTC (rev 82257)
@@ -32,8 +32,6 @@
 #include "mod_mono.h"
 #include "unixd.h"
 
-static int send_table (apr_pool_t *pool, apr_table_t *table, apr_socket_t 
*sock);
-
 DEFINE_MODULE (mono_module);
 
 /* Configuration pool. Cleared on restart. */
@@ -75,6 +73,8 @@
        char status; /* One of the FORK_* in the enum above.
                      * Don't care if run_xsp is "false" */
        char is_virtual; /* is the server virtual? */
+  char *start_attempts;
+  char *start_wait_time;
 } xsp_data;
 
 typedef struct {
@@ -89,6 +89,9 @@
        char *client_block_buffer;
 } request_data;
 
+static int send_table (apr_pool_t *pool, apr_table_t *table, apr_socket_t 
*sock);
+static void start_xsp (module_cfg *config, int is_restart, char *alias);
+
 /* */
 static int
 search_for_alias (const char *alias, module_cfg *config)
@@ -186,7 +189,9 @@
        server->env_vars = NULL;
        server->status = FORK_NONE;
        server->is_virtual = is_virtual;
-
+  server->start_attempts = "3";
+  server->start_wait_time = "2";
+  
        nservers = config->nservers + 1;
        servers = config->servers;
        config->servers = apr_pcalloc (pool, sizeof (xsp_data) * nservers);
@@ -1158,15 +1163,15 @@
   if (apr_uid_current (&cur_uid, &cur_gid, pool) == APR_SUCCESS && cur_uid == 
0) {
     DEBUG_PRINT (0, "switching forked process group to %u", 
(unsigned)unixd_config.group_id);
     if (setgid (unixd_config.group_id) == -1)
-      ap_log_error (APLOG_MARK, APLOG_ALERT, errno, STATUS_AND_SERVER,
-                    "setgid: unable to set group id to %u",
-                    (unsigned)unixd_config.group_id);
+      ap_log_error (APLOG_MARK, APLOG_ALERT, STATUS_AND_SERVER,
+                    "setgid: unable to set group id to %u. %s",
+                    (unsigned)unixd_config.group_id, strerror (errno));
 
     DEBUG_PRINT (0, "switching forked process user to %s", 
unixd_config.user_name);
     if (setuid (unixd_config.user_id) == -1)
-      ap_log_error (APLOG_MARK, APLOG_ALERT, errno, STATUS_AND_SERVER,
-                    "setuid: unable to set user id to %u",
-                    (unsigned)unixd_config.user_id);
+      ap_log_error (APLOG_MARK, APLOG_ALERT, STATUS_AND_SERVER,
+                    "setuid: unable to set user id to %u. %s",
+                    (unsigned)unixd_config.user_id, strerror (errno));
   }
 #endif
   
@@ -1491,7 +1496,11 @@
        module_cfg *config;
        per_dir_config *dir_config = NULL;
        int idx;
-
+  xsp_data *conf;
+  int connect_attempts;
+  int start_wait_time;
+  char *socket_name = NULL;
+  
        config = ap_get_module_config (r->server->module_config, &mono_module);
        DEBUG_PRINT (2, "config = %d", (int) config);
        if (r->per_dir_config != NULL)
@@ -1519,11 +1528,37 @@
 #ifdef APACHE13
        sock = apr_pcalloc (r->pool, sizeof (apr_socket_t));
 #endif
-       rv = setup_socket (&sock, &config->servers [idx], r->pool);
-       DEBUG_PRINT (2, "After setup_socket");
-       if (rv != APR_SUCCESS)
-               return HTTP_SERVICE_UNAVAILABLE;
-
+  conf = &config->servers [idx];
+  if (conf->filename != NULL)
+    socket_name = conf->filename;
+  else
+    socket_name = get_default_socket_name (r->pool, conf->alias, SOCKET_FILE);
+  connect_attempts = atoi (conf->start_attempts);
+  start_wait_time = atoi (conf->start_wait_time);
+  if (connect_attempts < 0)
+    connect_attempts = 3;
+  if (start_wait_time < 2)
+    start_wait_time = 2;
+  
+  while (connect_attempts--) {
+    rv = setup_socket (&sock, conf, r->pool);
+    DEBUG_PRINT (2, "After setup_socket");
+    if (rv != APR_SUCCESS) {
+      if (rv != -1)
+        return HTTP_SERVICE_UNAVAILABLE;
+      DEBUG_PRINT (2, "No backend found, starting a new copy");
+      if (socket_name != NULL && unlink (socket_name) < 0 && errno != ENOENT)
+        ap_log_error (APLOG_MARK, APLOG_ALERT, STATUS_AND_SERVER,
+                      "Could not remove stale socket %s. %s. Further requests 
will probably fail.",
+                      socket_name, strerror (errno));
+      start_xsp (config, 0, config->servers [idx].alias);
+      /* give some time for warm-up */
+      DEBUG_PRINT (2, "Started new backend, sleeping %us to let it configure", 
(unsigned)start_wait_time);
+      apr_sleep (apr_time_from_sec (start_wait_time));
+    } else
+      break; /* connected */
+  }
+  
        DEBUG_PRINT (2, "Sending init data");
        if (send_initial_data (r, sock, auto_app) != 0) {
                int err = errno;
@@ -1920,6 +1955,14 @@
        "start mod-mono-server.exe if it's not already there. Default: True"
        ),
 
+MAKE_CMD12 (MonoXSPStartAttempts, start_attempts,
+            "Number of attempts to make when a backend is found to be dead. "
+            "Cannot be less than 0. Default: 3"),
+
+MAKE_CMD12 (MonoXSPStartWaitTime, start_wait_time,
+            "Number of seconds to wait for the backend to come up. Cannot be 
less "
+            "than 2. Default: 2"),
+
 MAKE_CMD12 (MonoExecutablePath, executable_path,
        "(Obsolete) If MonoRunXSP is True, this is the full path where mono is 
located. "
        "Default: /usr/bin/mono"

Modified: trunk/mod_mono/src/mod_mono.h
===================================================================
--- trunk/mod_mono/src/mod_mono.h       2007-07-18 23:23:30 UTC (rev 82256)
+++ trunk/mod_mono/src/mod_mono.h       2007-07-18 23:26:17 UTC (rev 82257)
@@ -52,7 +52,6 @@
 #include "http_log.h"
 #include "http_config.h"
 
-
 #ifdef APACHE13
 /* Functions needed for making Apache 1.3 module as similar
 as possible to Apache 2 module, reducing ifdefs in the code itself*/

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to