The purpose of this post is twofold: the first part is a tutorial on how to build and deploy a managed FreeSWITCH module, the second part is about on-demand log rotation support for FreeSWITCH in Windows environment.
- Clone the FS source (branch V1.8 in my case) and build it
- Locate FreeSWITCH.Managed.csproj under src/mod/languages/mod_managed/managed and build it
- Create new .Net project with a Class Library output type and .Net Framework 4.5 target framework.
- Reference the FreeSWITCH.Managed.dll built at step 2
- Create a new class and implement the FreeSWITCH.IApiPlugin interface
- Build and copy the output dll along with its dependencies (FreeSWITCH.Managed.dll and any other dependency you have added) to the FS mod/managed directory
- Enable mod_managed in FS modules.conf
- (Re)start FreeSwitch and check the log for the module loading
This was easy, but what is inside a module? There are a lot of module types I won’t go into detail I will give a very simple example instead. There is no built-in support for rotating the log files on a daily basis. This is accomplished by sending a HUP signal to the process
kill -HUP `cat /usr/local/freeswitch/run/freeswitch.pid`
Such a command is usually scheduled with CRON or a similar tool.
This won’t work on windows, here is where a custom module could help. After some source reading, it turned out that the signal translates into an internal event. So the module will be very simple: trigger the same event!
var evt = new Event("TRAP", null); evt.AddHeader("Trapped-Signal", "HUP"); evt.Fire();
The full source can be found at https://github.com/rucc/ModSigHup
Usage from FS cli:
Usage from windows cli:
fs_cli.exe -p secret -x "managed sighup"
For the best results remove the rollover and maximum-rotate params from logfile.conf