glchen 发表于 2009-5-15 10:20:01

ACE_Service_Config如何配置使得修改配置不用重启

大家好。
我用ACE_Service_Config做日志服务,现在已经可以根据文件大小限制自动切换日志文件了。但是,按照书上的说明,我修改svc.conf中的日志级别,譬如说 -p ~TRACE禁用TRACE级别的日志,但是除非我重启程序,否则不会生效。

请问是怎么回事呢?
谢谢!

modern 发表于 2009-5-15 11:22:33

可以参考源代码:service_config.cpp(197)
在指定-s参数配置的时候,有特别的说明,
// There's no point in dealing with this on NT since it
// doesn't really support signals very well...
在windows下由于对对信号的处理不是很好,因此没做任何操作。
在unix系列平台上使用系统提供SIGHUP处理。

当然ACE也提供了windows下的处理办法的,可以由自己定时检查配置文件是否发生变化。
如果发生变化住的调用ACE_Service_Config::reconfigure即可。

glchen 发表于 2009-5-15 11:32:19

原帖由 modern 于 2009-5-15 11:22 发表 http://www.acejoy.com/bbs/images/common/back.gif
可以参考源代码:service_config.cpp(197)
在指定-s参数配置的时候,有特别的说明,
// There's no point in dealing with this on NT since it
// doesn't really support signals very well...
在windows下由于对对信号 ...

谢谢你的回复。按你的意思是默认的情况下,在windows上是做不到不重启就生效了?

我修改了程序,简单的做了这样的测试:
在console输入一个字符的时候,调用reconfigure,但是发现这样一调用,ace_reactor的事件循环就被终止了?!

modern 发表于 2009-5-15 11:56:59

这个需要跟一下代码了,看看那里导致事件循环被终止了。
在reconfigure处打断点,跟进去,才知道哦~

modern 发表于 2009-5-15 12:55:22

可以参考APG(19.5节)
We have learned how service configuration directives are processed at program start-up via the ACE_Service_Config::open() method. So how do these configuration directives get processed after that point? As we saw in the example programs in this chapter, after the Service Configurator framework is initialized, control often resides in the Reactor framework's event loop. There are two ways to make ACE reprocess the same service configuration file—or set of files—used when ACE_Service_Config::open() was called.

On systems that have POSIX signal capability, send the process a SIGHUP signal. For this to work, the program must be executing the Reactor event loop. As this is often the case, the requirement is not usually a problem. Note that the signal number to use for this can be changed when the program starts, by specifying the -s command line option (see Table 19.1).

The program itself can call ACE_Service_Config::reconfigure() directly. This is the favored option on Windows, as POSIX signals are not available, and can also be used for programs that are not running the Reactor event loop. To make this more automatic on Windows, it's possible to create a file/directory change event, register the event handle with the ACE_WFMO_Reactor, and use the event callback to do the reconfiguration.

Both of these options will reprocess the service configuration file(s) previously processed via ACE_Service_Config::open(). Therefore, the usual practice is to comment out the static and/or dynamic service initialization directives and add—or uncomment, if previously added—the desired remove directives, save the file(s), and trigger the reconfiguration.

glchen 发表于 2009-5-15 13:16:05

原帖由 modern 于 2009-5-15 12:55 发表 http://www.acejoy.com/bbs/images/common/back.gif
可以参考APG(19.5节)
We have learned how service configuration directives are processed at program start-up via the ACE_Service_Config::open() method. So how do these configuration directives get process ...


是的,我看了中文版本的 这一段了。
上面说用ACE_WFMO_Reactor监视文件/目录变更事件,但是也没说怎么个实现,我一下子找不到头绪。文件/目录变更事件ace里面有定一个这种事件的mask吗?

而且我还很奇怪:
1. 如果我不跑ACE_Reactor::instance()->run_event_loop(),那么它就不会在文件到达指定大小时帮我换文件。这个是因为要在handle_timeout里面处理,倒也可以理解;
2. 但是,我发现reactor一定要跑在主线程里面,如果我单独开一个线程来跑reactor的event loop,那么他也不能帮忙检查文件上限的配置。

modern 发表于 2009-5-15 13:29:47

1.Reactor的事件循环式一定要跑的,原因如你所说
2.reactor可以不跑在主线程里,一般的用法是使用task启动一个线程,
然后在运行事件循环之前插入下面的代码
ACE_Reactor::instance()->owner(ACE_OS::thr_self ());

glchen 发表于 2009-5-15 14:20:17

原帖由 modern 于 2009-5-15 13:29 发表 http://www.acejoy.com/bbs/images/common/back.gif
1.Reactor的事件循环式一定要跑的,原因如你所说
2.reactor可以不跑在主线程里,一般的用法是使用task启动一个线程,
然后在运行事件循环之前插入下面的代码
ACE_Reactor::instance()->owner(ACE_OS::thr_self ()); ...

谢谢你的信息。
我集成task_base,在那个线程的svc里面:
ACE_Reactor::instance()->owner(ACE_OS::thr_self ());
ACE_Reactor::instance()->run_reactor_event_loop();

就可以不用在主线程跑reactor event loop了,也可以帮我监视log的大小限制了。

但是还是有个问题:
我现在不指望能自动监视我对svc.conf的修改了,而是在main里面,来了个getchar(),每当对svc.conf做了修改之后,就要在console上输入一个字符,比如r,然后我就
if('r' == getchar())
{
    ACE_Service_Config::reconfigure();
}
结果程序crash了。。。

终端行是:
ACE_Reactor::run_reactor_event_loop (REACTOR_EVENT_HOOK eh)
{
...
while (1)
    {
      int const result = this->implementation_->handle_events ();
      ...
   }
}

modern 发表于 2009-5-15 14:58:25

为甚么不能自动监视呀,书上已经提供了一个办法了,当然办法不局限于此,也可以顺便拿reactor的定时器,主动检查,文件是否改变。
To make this more automatic on Windows, it's possible to create a file/directory change event, register the event handle with the ACE_WFMO_Reactor, and use the event callback to do the reconfiguration。

glchen 发表于 2009-5-15 16:57:42

原帖由 modern 于 2009-5-15 14:58 发表 http://www.acejoy.com/bbs/images/common/back.gif
为甚么不能自动监视呀,书上已经提供了一个办法了,当然办法不局限于此,也可以顺便拿reactor的定时器,主动检查,文件是否改变。
To make this more automatic on Windows, it's possible to create a file/directory change...

是啊,书上说了这段,我也看到了。
但是,要监视文件的修改,要给reactor注册什么事件mask呢?

谢谢!
页: [1] 2
查看完整版本: ACE_Service_Config如何配置使得修改配置不用重启