---------- Forwarded message ---------
От: Andrey Deykunov <deykunov(a)gmail.com>
Date: пн, 18 мая 2020 г. в 12:24
Subject: RPC command to close all WS connections.
To: Daniel-Constantin Mierla <miconda(a)gmail.com>
Hi Daniel,
We're using two nodes (active and passive) of our PBX server in production.
When an active node becomes passive, we should forcibly close all WS
connections, established by clients on this node. So, I've added
'ws.close_all' command to websocket module to let our failover service be
able closing WS connections remotely.
I've added the following code to ws_frame.c:
void ws_rpc_close_all(rpc_t *rpc, void *ctx)
{
ws_connection_t **list = NULL, **list_head = NULL;
ws_connection_t *wsc = NULL;
int ret;
list_head = wsconn_get_list();
if(!list_head)
return;
list = list_head;
wsc = *list_head;
while(wsc) {
LM_WARN("Closing connection\n");
ret = close_connection(&wsc, LOCAL_CLOSE, 1000
, str_status_normal_closure);
wsc = *(++list);
}
wsconn_put_list(list_head);
}
but I think this code may be unsafe and could corrupt shared
memory, because I've got some segfaults during failovers after adding this
command.
What do you think? Is it possible to close connections properly
and safety for shared memory?
Thanks,
Andrey
Environment:
```
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.6 LTS"
```
Kamailio installed from:
```
/etc/apt/sources.list
deb http://deb.kamailio.org/kamailio53 xenial main
deb-src http://deb.kamailio.org/kamailio53 xenial main
```
After Kamailio start, ownership of `/var/run/kamailio/` and related files looks like:
```
# ls -l /var/run/kamailio/
total 4
srw-rw---- 1 kamailio kamailio 0 May 20 15:41 kamailio_ctl
-rw-r--r-- 1 kamailio kamailio 5 May 20 15:41 kamailio.pid
prw-rw---- 1 root root 0 May 20 15:41 kamailio_rpc.fifo
srw-rw---- 1 root root 0 May 20 15:41 kamailio_rpc.sock
# ls -ld /var/run/kamailio/
drwxr-x--- 2 root root 120 May 20 15:41 /var/run/kamailio/
```
Note 'root' ownership.
This causes these errors during Kamailio stop and probabaly some other issues too.
```
May 20 16:11:24 sip01 /usr/sbin/kamailio[5919]: ERROR: jsonrpcs [jsonrpcs_fifo.c:599]: jsonrpc_fifo_destroy(): FIFO stat failed: Permission denied
May 20 16:11:24 sip01 /usr/sbin/kamailio[5919]: ERROR: jsonrpcs [jsonrpcs_sock.c:516]: jsonrpc_dgram_destroy(): socket stat failed: Permission denied
May 20 16:11:24 sip01 /usr/sbin/kamailio[5919]: ERROR: ctl [ctl.c:390]: mod_destroy(): ERROR: ctl: could not delete unix socket /var/run/kamailio//kamailio_ctl: Permission denied (13)
```
To get the ownership right I have to modify `/lib/systemd/system/kamailio.service`
and add:
```
User=kamailio
Group=kamailio
```
Now ownership after start looks like bellow and stops are clean too.
```
# ls -l /var/run/kamailio/
total 4
srw-rw---- 1 kamailio kamailio 0 May 20 15:52 kamailio_ctl
-rw-r--r-- 1 kamailio kamailio 5 May 20 15:52 kamailio.pid
prw-rw---- 1 kamailio kamailio 0 May 20 15:52 kamailio_rpc.fifo
srw-rw---- 1 kamailio kamailio 0 May 20 15:52 kamailio_rpc.sock
# ls -ld /var/run/kamailio/
drwxr-x--- 2 kamailio kamailio 120 May 20 15:52 /var/run/kamailio/
```
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/issues/2334
### Description
In our setup, we try to eliminate setup configuration in database and replace it with files. The advantage is, that we can maintain those files via puppet or ansible, and since we always rewrite the whole file, we don't have to take care about deleting obsolete entries. We can run different Kamailio versions without having problems with the version table when using the same database. And finally, we can stop all those local mysqld processes on a lot of machines.
Modules like the dispatcher module were easy to change. But the permissions module is not prepared to run without database, if you want to use `allow_trusted()` or `allow_source_address()` and similar. The only option to feed those functions with data is a database table.
### Expected behavior
We would like to place files for trusted and address into the Kamailio directory and have Kamailio read from those files during startup or after reload commands.
#### Actual observed behavior
Data for trusted and address have to reside inside a database.
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/issues/2037