https://www.freedesktop.org/software/systemd/man/sd_notify.html
sd_notify() may be called by a service to notify the service manager about state changes. It can be used to send arbitrary information, encoded in an environment-block-like string. Most importantly, it can be used for start-up completion notification.
I don't think someone will (re-)compile with systemd support in the core.
We should add a core api that executes callbacks on the events you need and then have a module setting them.
In this case I see the patches are minimal, so I can take care converting this PR to a use of a module with new core api callbacks. Then you can add more to it if needed in the future.
Great, thanks!
See the newly added systemdops module -- beware it was not tested! Feel free to improve/change it as you need, I did more or less the framework to avoid the need to re-compile the core with libsystemd dependency.
Closed #2139.
Feel free to improve/change it as you need
I will, thank you!
Trying to test @miconda's commits on top of the 5.3 branch--can't get Kamailio to notify systemd on startup. strace doesn't show anything attempting to send notification to systemd. I'll keep trying...
Trying to test @miconda's commits on top of the 5.3 branch--can't get Kamailio to notify systemd on startup. strace doesn't show anything attempting to send notification to systemd. I'll keep trying...
Looking through `main.c`, I think this is because `sr_corecb_void_exec(app_ready);` is not included in `if (dont_fork)`. The assumption with `Type=notify` is that we'd be using `kamailio -DD` where the main process isn't forked, correct?
I tested a bit more in Fedora 31, but couldn't get this to work as a module. Similar kamailio/systemd issues like #799, which I'll update there, subjectively.
Thanks again for working toward systemd integration.
I tested a bit more in Fedora 31, but couldn't get this to work as a module. Similar kamailio/systemd issues like #799, which I'll update there, subjectively.
Thanks again for working toward systemd integration.
Confirming that @linuxmaniac's initial patch does work with `kamailio -DD`.
I can confirm kamailio process reach `sr_corecb_void_exec(app_ready);` https://github.com/kamailio/kamailio/blob/master/src/main.c#L1793
But `ksr_sd_app_ready` not called. https://github.com/kamailio/kamailio/blob/master/src/modules/systemdops/syst...
May be that because `mod_register` for `systemdops_mod` is empty function and not make call of `r_event_register_cb`? https://github.com/kamailio/kamailio/blob/master/src/modules/systemdops/syst...
@amessina @sergey-safarov can you try with my 63884a7713af5a96114bf90c36cf63b3e553bcc5
Indeed I missed setting the callback pointers. I just pushed the commit: d4fc8b0168ba3de78e29deb7c7d7ed9b3fd29a36
Try again with the latest master.
@linuxmaniac - your patch tries to set the address of a static structure defined in core. That doesn't need to be allocated as a pointer, it is already defined.
I combined Victor commit and Daniel commit module registered now. Think need apply ```diff diff --git a/src/modules/systemdops/systemdops_mod.c b/src/modules/systemdops/systemdops_mod.c index 0ac15426d1..4672f47d1a 100644 --- a/src/modules/systemdops/systemdops_mod.c +++ b/src/modules/systemdops/systemdops_mod.c @@ -69,7 +69,8 @@ void ksr_sd_app_shutdown(void) int mod_register(char *path, int *dlflags, void *p1, void *p2) { sr_corecb_t *cbp = sr_corecb_get(); - if(cbp) { + if(!cbp) { + SYS_MEM_ERROR; return -1; } cbp->app_ready = ksr_sd_app_ready; ```
also systemd unit with `Type=notify` started properly.
Apparently no fully woken up ... indeed the condition on cbp was supposed to test if it is null. The SYS_MEM_ERR is not needed because there is no memory allocated. I pushed a commit to fix the condition.
@sergey-safarov - I pushed a commit that enable loading modules via command parameter, like `--loadmodule=systemdops.so`. Maybe this is an option if people want to have systemd notifications, because it can be added in the systemd unit file starting kamailio.
I had it in mind to add it for very long time, aiming to offer the option to modules to do callbacks before loading the configuration file for various needs (e.g., apply a template system to config file before parsing), but then we had support for defines. Now I thought this can be useful also in this particular case.
@miconda, @sergey-safarov, @linuxmaniac thank you. I confirm this now works atop branch 5.3 with the following in `/lib/systemd/system/kamailio.service` ``` [Unit] Description=Kamailio SIP Server Documentation=man:kamailio(8) https://www.kamailio.org/ After=network.target
[Service] Type=notify User=kamailio Environment=SHM_SIZE=128 PKG_SIZE=8 ExecStartPre=/usr/sbin/kamailio -c ExecStart=/usr/sbin/kamailio -DD -m $SHM_SIZE -M $PKG_SIZE ProtectHome=true Restart=on-failure RestartSec=30
[Install] WantedBy=multi-user.target ```
Now, onto #799 ...