Writing a Managed FreeSWITCH Module to Add SigHup Support in Windows

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.

The official docs of mod_managed combined with the source of the Demo project give a good description of the process but a key point is missing. Here is what worked for me step-by-step

  1. Clone the FS source (branch V1.8 in my case) and build it
  2. Locate FreeSWITCH.Managed.csproj under src/mod/languages/mod_managed/managed and build it
  3. Create new .Net project with a Class Library output type and .Net Framework 4.5 target framework.
  4. Reference the FreeSWITCH.Managed.dll built at step 2
  5. Create a new class and implement the FreeSWITCH.IApiPlugin interface
  6. 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
  7. Enable mod_managed in FS modules.conf
  8. (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:

managed SigHup

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

Leave a Reply

Your email address will not be published. Required fields are marked *