📄 mod_caucho.c
字号:
ap_get_server_port(r), now); } LOG(("%s:%d:caucho_request(): session index: %d\n", __FILE__, __LINE__, session_index)); if (! host) { ERR(("%s:%d:caucho_request(): no host: %p\n", __FILE__, __LINE__, host)); return HTTP_SERVICE_UNAVAILABLE; } else if (! cse_open_connection(&s, &host->cluster, session_index, backup_index, now, r->pool)) { ERR(("%s:%d:caucho_request(): no connection: cluster(%p)\n", __FILE__, __LINE__, &host->cluster)); return HTTP_SERVICE_UNAVAILABLE; } srun = s.cluster_srun->srun; apr_thread_mutex_lock(srun->lock); srun->active_sockets++; apr_thread_mutex_unlock(srun->lock); code = write_request(&s, r, config, session_index, backup_index); apr_thread_mutex_lock(srun->lock); srun->active_sockets--; apr_thread_mutex_unlock(srun->lock); /* on failure, do not failover but simply fail */ if (code == HMUX_QUIT) cse_recycle(&s, now); else cse_close(&s, "no reuse"); if (code != HMUX_QUIT && code != HMUX_EXIT) { ERR(("%s:%d:caucho_request(): protocol failure code:%d\n", __FILE__, __LINE__, code)); return HTTP_SERVICE_UNAVAILABLE; } else if (r->status == HTTP_SERVICE_UNAVAILABLE) { return HTTP_SERVICE_UNAVAILABLE; } else { /* * See pages like jms/index.xtp int status = r->status; r->status = HTTP_OK; return status; */ return OK; }}/** * Print the statistics for each JVM. */static voidjvm_status(cluster_t *cluster, request_rec *r){ int i; stream_t s; ap_rputs("<center><table border=2 width='80%'>\n", r); ap_rputs("<tr><th width=\"30%\">Host</th>\n", r); ap_rputs(" <th>Active</th>\n", r); ap_rputs(" <th>Pooled</th>\n", r); ap_rputs(" <th>Connect<br>Timeout</th>\n", r); ap_rputs(" <th>Idle<br>Time</th>\n", r); ap_rputs(" <th>Recover<br>Time</th>\n", r); ap_rputs("</tr>\n", r); for (; cluster; cluster = cluster->next) { for (i = 0; i < cluster->srun_capacity; i++) { cluster_srun_t *cluster_srun = cluster->srun_list + i; srun_t *srun = cluster_srun->srun; int port; int pool_count; if (! srun) continue; port = srun->port; pool_count = ((srun->conn_head - srun->conn_tail + CONN_POOL_SIZE) % CONN_POOL_SIZE); ap_rputs("<tr>", r); if (! cse_open(&s, cluster, cluster_srun, r->pool, 0)) { ap_rprintf(r, "<td bgcolor='#ff6666'>%d. %s:%d%s (down)</td>", cluster_srun->index + 1, srun->hostname ? srun->hostname : "localhost", port, cluster_srun->is_backup ? "*" : ""); } else { ap_rprintf(r, "<td bgcolor='#66ff66'>%d. %s:%d%s (ok)</td>", cluster_srun->index + 1, srun->hostname ? srun->hostname : "localhost", port, cluster_srun->is_backup ? "*" : ""); } /* This needs to be close, because cse_open doesn't use recycle. */ cse_close(&s, "caucho-status"); LOG(("%s:%d:jvm_status(): close\n", __FILE__, __LINE__)); ap_rprintf(r, "<td align=right>%d</td><td align=right>%d</td>", srun->active_sockets, pool_count); ap_rprintf(r, "<td align=right>%d</td><td align=right>%d</td><td align=right>%d</td>", srun->connect_timeout, srun->live_time, srun->dead_time); ap_rputs("</tr>\n", r); } } ap_rputs("</table></center>\n", r);}static voidcaucho_host_status(request_rec *r, config_t *config, resin_host_t *host){ web_app_t *app; location_t *loc; unsigned int now = (unsigned int) (r->request_time / 1000000); /* check updates as appropriate */ cse_match_host(config, host->name, host->port, now); if (host->canonical == host) ap_rprintf(r, "<h2>"); else ap_rprintf(r, "<h3>"); if (! host->has_data) ap_rprintf(r, "Unconfigured "); if (host->canonical != host) ap_rprintf(r, "Alias "); if (! *host->name) ap_rprintf(r, "Default Virtual Host"); else if (host->port) ap_rprintf(r, "Virtual Host: %s:%d", host->name, host->port); else ap_rprintf(r, "Virtual Host: %s", host->name); if (host->canonical == host) { } else if (! host->canonical) ap_rprintf(r, " -> <font color='red'>null</font>"); else if (host->canonical->port) ap_rprintf(r, " -> %s:%d", host->canonical->name, host->canonical->port); else if (! host->canonical->name[0]) ap_rprintf(r, " -> default"); else ap_rprintf(r, " -> %s", host->canonical->name); if (host->canonical == host) ap_rprintf(r, "</h2>"); else ap_rprintf(r, "</h3>"); if (host->error_message[0]) ap_rprintf(r, "<h3 color='red'>Error: %s</h3>\n", host->error_message); ap_rprintf(r, "<p style='margin-left:2em'>"); if (host->config_source[0]) { ap_rprintf(r, "<b>Source:</b> %s<br />\n", host->config_source); } ap_rprintf(r, "<b>Last-Update:</b> %s</p><br />\n", ctime(&host->last_update)); ap_rprintf(r, "</p>\n"); if (host->canonical == host) { jvm_status(&host->cluster, r); ap_rputs("<p><center><table border=2 cellspacing=0 cellpadding=2 width='80%'>\n", r); ap_rputs("<tr><th width=\"50%\">web-app\n", r); ap_rputs(" <th>url-pattern\n", r); app = host->applications; for (; app; app = app->next) { if (! app->has_data) { ap_rprintf(r, "<tr bgcolor='#ffcc66'><td>%s<td>unconfigured</tr>\n", *app->context_path ? app->context_path : "/"); } for (loc = app->locations; loc; loc = loc->next) { if (! strcasecmp(loc->prefix, "/META-INF") || ! strcasecmp(loc->prefix, "/WEB-INF")) continue; ap_rprintf(r, "<tr bgcolor='#ffcc66'><td>%s<td>%s%s%s%s%s</tr>\n", *app->context_path ? app->context_path : "/", loc->prefix, ! loc->is_exact && ! loc->suffix ? "/*" : loc->suffix && loc->prefix[0] ? "/" : "", loc->suffix ? "*" : "", loc->suffix ? loc->suffix : "", loc->ignore ? " (ignore)" : ""); } } ap_rputs("</table></center>\n", r); }}/** * Print a summary of the configuration so users can understand what's * going on. Ping the server to check that it's up. */static intcaucho_status(request_rec *r){ config_t *config; resin_host_t *host; time_t now = time(0); if (! r->handler || strcmp(r->handler, "caucho-status")) return DECLINED; config = cse_get_module_config(r); if (! config) return DECLINED; r->content_type = "text/html"; if (r->header_only) return OK; ap_rputs("<html><title>Status : Caucho Servlet Engine</title>\n", r); ap_rputs("<body bgcolor=white>\n", r); ap_rputs("<h1>Status : Caucho Servlet Engine</h1>\n", r); if (! config) return OK; if (config->error) ap_rprintf(r, "<h2 color='red'>Error : %s</h2>\n", config->error); ap_rprintf(r, "<table border='0'>"); ap_rprintf(r, "<tr><td><b>Start Time</b></td><td>%s</td></tr>\n", ctime(&config->start_time)); ap_rprintf(r, "<tr><td><b>Now</b></td><td>%s</td></tr>\n", ctime(&now)); ap_rprintf(r, "<tr><td><b>Session Cookie</b></td><td>'%s'</td></tr>\n", config->session_cookie); ap_rprintf(r, "<tr><td><b>Session URL</b></td><td>'%s'</td></tr>\n", config->session_url_prefix); ap_rprintf(r, "<tr><td><b>Config Check Interval</b></b></td><td>%ds</td></tr>\n", config->update_interval); if (config->config_path && config->config_path[0]) { ap_rprintf(r, "<tr><td><b>Config Cache File</b></td><td>%s</td></tr>\n", config->config_path); } ap_rprintf(r, "</table>"); ap_rprintf(r, "<h2>Configuration Cluster</h2>\n"); jvm_status(&config->config_cluster, r); host = config ? config->hosts : 0; for (; host; host = host->next) { if (host != host->canonical) { continue; } caucho_host_status(r, config, host); } if (config->manual_host) caucho_host_status(r, config, config->manual_host); ap_rputs("<hr>", r); ap_rprintf(r, "<em>%s<em>", VERSION); ap_rputs("</body></html>\n", r); return OK;}/** * Strip the ;jsessionid */static intcse_strip(request_rec *r){ config_t *config = cse_get_module_config(r); const char *uri = r->uri; if (config == NULL || ! uri) return DECLINED; if (config->session_url_prefix) { char *new_uri; new_uri = strstr(uri, config->session_url_prefix); if (new_uri) { *new_uri = 0; /* Strip session encoding from static files. */ if (r->filename) { char *url_rewrite = strstr(r->filename, config->session_url_prefix); if (url_rewrite) { *url_rewrite = 0; /* if (stat(r->filename, &r->finfo) < 0) r->finfo.st_mode = 0; */ } } apr_table_setn(r->headers_out, "Location", ap_construct_url(r->pool, r->uri, r)); return HTTP_MOVED_PERMANENTLY; } } return DECLINED;}/** * Look at the request to see if Resin should handle it. */static intcse_dispatch(request_rec *r){ config_t *config = cse_get_module_config(r); const char *host_name = ap_get_server_name(r); int port = ap_get_server_port(r); const char *uri = r->uri; resin_host_t *host; unsigned int now = (unsigned int) (r->request_time / 1000000); int len; if (config == NULL || ! uri) return DECLINED; LOG(("%s:%d:cse_dispatch(): [%d] host %s\n", __FILE__, __LINE__, getpid(), host_name ? host_name : "null")); len = strlen(uri); /* move back below host */ if (config->enable_caucho_status && len >= sizeof("/caucho-status") - 1 && ! strcmp(uri + len - sizeof("/caucho-status") + 1, "/caucho-status")) { r->handler = "caucho-status"; return caucho_status(r); } /* Check for exact virtual host match */ host = cse_match_request(config, host_name, port, uri, 0, now); if (host || (r->handler && ! strcmp(r->handler, "caucho-request"))) { LOG(("%s:%d:cse_dispatch(): [%d] match %s:%s\n", __FILE__, __LINE__, getpid(), host_name ? host_name : "null", uri)); return caucho_request(r, config, host, now); } else if (r->handler && ! strcmp(r->handler, "caucho-status")) { return caucho_status(r); } if (config->session_url_prefix) { return cse_strip(r); } return DECLINED;}/* * Only needed configuration is pointer to resin.conf */static command_rec caucho_commands[] = { AP_INIT_TAKE12("ResinConfigServer", resin_config_server_command, NULL, RSRC_CONF|ACCESS_CONF, "Adds a configuration server."), AP_INIT_TAKE12("ResinHost", cse_host_command, NULL, RSRC_CONF|ACCESS_CONF, "Configures a cluster host for manual configuration."), AP_INIT_TAKE12("ResinBackup", cse_backup_command, NULL, RSRC_CONF|ACCESS_CONF, "Configures a cluster host for manual configuration."), AP_INIT_TAKE1("ResinConfigCacheDirectory", resin_config_cache_command, NULL, RSRC_CONF|ACCESS_CONF, "Configures the saved configuration file."), AP_INIT_TAKE1("ResinSessionCookie", resin_session_cookie_command, NULL, RSRC_CONF|ACCESS_CONF, "Configures the session cookie."), AP_INIT_TAKE1("ResinSessionSticky", resin_session_sticky_command, NULL, RSRC_CONF|ACCESS_CONF, "Configures the session sticky."), AP_INIT_TAKE1("ResinSessionUrlPrefix", resin_session_url_prefix_command, NULL, RSRC_CONF|ACCESS_CONF, "Configures the session url."), AP_INIT_TAKE1("CauchoStatus", caucho_status_command, NULL, RSRC_CONF|ACCESS_CONF, "Adds a configuration server."), AP_INIT_TAKE12("CauchoHost", cse_host_command, NULL, RSRC_CONF|ACCESS_CONF, "Configures a cluster host for manual configuration."), AP_INIT_TAKE12("CauchoBackup", cse_backup_command, NULL, RSRC_CONF|ACCESS_CONF, "Configures a cluster host for manual configuration."), AP_INIT_TAKE1("CauchoConfigCacheDirectory", resin_config_cache_command, NULL, RSRC_CONF|ACCESS_CONF, "Configures the saved configuration file."), {NULL}};static intprefork_post_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *dummy, server_rec *ptemp){ g_start_time = time(0); ap_add_version_component(p, VERSION); return OK;}static void caucho_register_hooks(apr_pool_t *p){ ap_hook_post_config(prefork_post_config, NULL, NULL, APR_HOOK_MIDDLE); ap_hook_handler(cse_dispatch, NULL, NULL, APR_HOOK_FIRST);}/* Dispatch list for API hooks */module AP_MODULE_DECLARE_DATA caucho_module = { STANDARD20_MODULE_STUFF, cse_create_dir_config, /* create per-dir config structures */ cse_merge_dir_config, /* merge per-dir config structures */ cse_create_server_config, /* create per-server config structures */ cse_merge_server_config, /* merge per-server config structures */ caucho_commands, /* table of config file commands */ caucho_register_hooks /* register hooks */};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -