Exemple #1
0
static void mod_mapcache_child_init(apr_pool_t *pool, server_rec *s)
{
  int rv;
  mapcache_server_cfg* cfg = ap_get_module_config(s->module_config, &mapcache_module);
#ifdef APR_HAS_THREADS
  apr_thread_mutex_create(&thread_mutex,APR_THREAD_MUTEX_DEFAULT,pool);
#endif
  rv = mapcache_connection_pool_create(&(cfg->cp),pool);
  ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, "creating a mapcache connection pool for server");
  if(rv!=APR_SUCCESS) {
    ap_log_error(APLOG_MARK, APLOG_CRIT, 0, s, "failed to create mapcache connection pool");
  }
}
static char *
ngx_http_mapcache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
  mapcache_context *ctx = conf;
  ngx_str_t *value;
  value = cf->args->elts;
  char *conffile = (char*)value[1].data;
  ctx->config = mapcache_configuration_create(ctx->pool);
  mapcache_configuration_parse(ctx,conffile,ctx->config,1);
  if(GC_HAS_ERROR(ctx)) {
    ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,ctx->get_error_message(ctx));
    return NGX_CONF_ERROR;
  }
  mapcache_configuration_post_config(ctx, ctx->config);
  if(GC_HAS_ERROR(ctx)) {
    ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,ctx->get_error_message(ctx));
    return NGX_CONF_ERROR;
  }
  mapcache_connection_pool_create(&ctx->connection_pool,ctx->pool);
  ctx->config->non_blocking = 1;

  ngx_http_core_loc_conf_t  *clcf;

  clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);
  clcf->handler = ngx_http_mapcache_handler;

  pathinfo_index = ngx_http_get_variable_index(cf, &pathinfo_str);
  if (pathinfo_index == NGX_ERROR) {
    return NGX_CONF_ERROR;
  }
  urlprefix_index = ngx_http_get_variable_index(cf, &urlprefix_str);
  if (urlprefix_index == NGX_ERROR) {
    return NGX_CONF_ERROR;
  }

  return NGX_CONF_OK;
}
Exemple #3
0
static void load_config(mapcache_context *ctx, char *filename)
{
  apr_file_t *f;
  apr_finfo_t finfo;
  mapcache_cfg *old_cfg;
  mapcache_cfg *cfg;
  if((apr_file_open(&f, filename, APR_FOPEN_READ, APR_UREAD | APR_GREAD,
                    global_pool)) == APR_SUCCESS) {
    apr_file_info_get(&finfo, APR_FINFO_MTIME, f);
    apr_file_close(f);
  } else {
    if(!ctx->pool) ctx->pool = global_pool;
    ctx->set_error(ctx,500,"failed to open config file %s",filename);
    return;
  }
  if(ctx->config) {
    //we already have a loaded configuration, check that the config file hasn't changed
    if(finfo.mtime > mtime) {
      ctx->log(ctx,MAPCACHE_INFO,"config file has changed, reloading");
    } else {
      return;
    }
  }
  mtime = finfo.mtime;

  /* either we have no config, or it has changed */

  old_cfg = ctx->config;
  apr_pool_create(&tmp_config_pool,global_pool);

  cfg = mapcache_configuration_create(tmp_config_pool);
  ctx->config = cfg;
  ctx->pool = tmp_config_pool;

  mapcache_configuration_parse(ctx,conffile,cfg,1);
  if(GC_HAS_ERROR(ctx)) goto failed_load;
  mapcache_configuration_post_config(ctx, cfg);
  if(GC_HAS_ERROR(ctx)) goto failed_load;
  if(mapcache_config_services_enabled(ctx,cfg) <= 0) {
    ctx->set_error(ctx,500,"no mapcache <service>s configured/enabled, no point in continuing.");
    goto failed_load;
  }

  /* no error, destroy the previous pool if we are reloading the config */
  if(config_pool) {
    apr_pool_destroy(config_pool);
  }
  config_pool = tmp_config_pool;
  mapcache_connection_pool_create(&ctx->connection_pool, config_pool);

  return;

failed_load:
  /* we failed to load the config file */
  if(config_pool) {
    /* we already have a running configuration, keep it and only log the error to not
     * interrupt the already running service */
    ctx->log(ctx,MAPCACHE_ERROR,"failed to reload config file %s: %s", conffile,ctx->get_error_message(ctx));
    ctx->clear_errors(ctx);
    ctx->config = old_cfg;
    ctx->pool = config_pool;
    apr_pool_destroy(tmp_config_pool);
  }

}