Menu Close

Upgrade Kamailio 3.1.2 to 3.2 – debian lenny

Migration from 3.1.2 to Kamailio 3.2 requires upgrade of installed packages, database structures and configuration file.

Upgrade of Packages

First, we have to add correct debian repository of kamailio version 3.2. So open your source list file

vim /etc/apt/source.list

and add:

for ”Debian Lenny”

deb http://deb.kamailio.org/kamailio32 lenny main
deb-src http://deb.kamailio.org/kamailio32 lenny main

for ”Debian Squeeze”.

deb http://deb.kamailio.org/kamailio32 squeeze main
deb-src http://deb.kamailio.org/kamailio32 squeeze main

Then, if we did not do before, add GPG key

wget http://deb.kamailio.org/kamailiodebkey.gpg
apt-key add kamailiodebkey.gpg

and we may debian update packages list

apt-get update

After update we can start main upgrade

pstest:/home/palo# apt-get upgrade kamailio
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages have been kept back:
  bind9-host dnsutils kamailio kamailio-cpl-modules kamailio-mysql-modules
  kamailio-presence-modules kamailio-tls-modules libbind9-50 libdns55
  libisccc50 libisccfg50 liblwres50
The following packages will be upgraded:
  apache2 apache2-doc apache2-mpm-prefork apache2-utils apache2.2-common
  aptitude base-files curl dhcp3-client dhcp3-common dpkg exim4 exim4-base
  exim4-config exim4-daemon-light git-core klibc-utils libapache2-mod-php5
  libapr1 libc6 libc6-dev libc6-i386 libcurl3 libcurl3-gnutls libfreetype6
  libklibc libkrb53 libldap-2.4-2 libmysqlclient15off libperl5.10 libpng12-0
  libpq5 libssl0.9.8 libxml2 libxml2-dev linux-image-2.6.26-2-amd64
  linux-libc-dev locales man-db mysql-client mysql-client-5.0 mysql-common
  mysql-server mysql-server-5.0 openssl perl perl-base perl-modules php5
  php5-common php5-gd php5-mcrypt php5-mysql phpmyadmin tzdata
55 upgraded, 0 newly installed, 0 to remove and 12 not upgraded.
Need to get 113MB of archives.
After this operation, 3592kB disk space will be freed.
Do you want to continue [Y/n]? y

 During upgrade we are asked for keeping config files:

 Configuration file `/etc/kamailio/kamailio.cfg'
 ==> Modified (by you or by a script) since installation.
 ==> Package distributor has shipped an updated version.
   What would you like to do about it ?  Your options are:
    Y or I  : install the package maintainer's version
    N or O  : keep your currently-installed version
      D     : show the differences between the versions
      Z     : background this process to examine the situation
 The default action is to keep your current version.
*** kamailio.cfg (Y/I/N/O/D/Z) [default=N] ? N

Configuration file `/etc/kamailio/kamctlrc'
 ==> Modified (by you or by a script) since installation.
 ==> Package distributor has shipped an updated version.
   What would you like to do about it ?  Your options are:
    Y or I  : install the package maintainer's version
    N or O  : keep your currently-installed version
      D     : show the differences between the versions
      Z     : background this process to examine the situation
 The default action is to keep your current version.
*** kamctlrc (Y/I/N/O/D/Z) [default=N] ?

Configuration file `/etc/default/kamailio'
 ==> Modified (by you or by a script) since installation.
 ==> Package distributor has shipped an updated version.
   What would you like to do about it ?  Your options are:
    Y or I  : install the package maintainer's version
    N or O  : keep your currently-installed version
      D     : show the differences between the versions
      Z     : background this process to examine the situation
 The default action is to keep your current version.
*** kamailio (Y/I/N/O/D/Z) [default=N] ?
Installing new version of config file /etc/init.d/kamailio ...
Not starting Kamailio: invalid configuration file!

At the last line of the output we may see that the Kamailio server is not starting automatically due to errors inside of the Kamailio config file. This is the result of modification between 3.1 and 3.2 release, where rtp proxy configuration and mysql tables are affected. And in my case, as I’m using rtpproxy I have to correct it.

0(27417) ERROR: <core> [cfg.y:3365]: cfg. parser: failed to find command force_rtp_proxy
 0(27417) : <core> [cfg.y:3504]: parse error in config file /etc/kamailio/kamailio.cfg, line 795, column 19: unknown command, missing loadmodule?

 0(27417) ERROR: <core> [cfg.y:3365]: cfg. parser: failed to find command force_rtp_proxy
 0(27417) : <core> [cfg.y:3504]: parse error in config file /etc/kamailio/kamailio.cfg, line 873, column 19: unknown command, missing loadmodule?

ERROR: bad config file (2 errors)

invoke-rc.d: initscript kamailio, action "start" failed.
dpkg: error processing kamailio (--configure):
 subprocess post-installation script returned error exit status 1
dpkg: dependency problems prevent configuration of kamailio-mysql-modules:
 kamailio-mysql-modules depends on kamailio (= 3.2.0+lenny1); however:
  Package kamailio is not configured yet.
dpkg: error processing kamailio-mysql-modules (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of kamailio-tls-modules:
 kamailio-tls-modules depends on kamailio (= 3.2.0+lenny1); however:
  Package kamailio is not configured yet.
dpkg: error processing kamailio-tls-modules (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of kamailio-presence-modules:
 kamailio-presence-modules depends on kamailio (= 3.2.0+lenny1); however:
  Package kamailio is not configured yet.
dpkg: error processing kamailio-presence-modules (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of kamailio-cpl-modules:
 kamailio-cpl-modules depends on kamailio (= 3.2.0+lenny1); however:
  Package kamailio is not configured yet.
dpkg: error processing kamailio-cpl-modules (--configure):
 dependency problems - leaving unconfigured
Errors were encountered while processing:
 kamailio
 kamailio-mysql-modules
 kamailio-tls-modules
 kamailio-presence-modules
 kamailio-cpl-modules
E: Sub-process /usr/bin/dpkg returned an error code (1)

Upgrade Mysql tables

Kamailio in version 3.2 change database structures, therefore we have to upgrade DB tables of Kamailio 3.1.2 to a new one. Therefore connect to your mysql database which is utilizied by our Kamamilio server:

pstest:/home/palo# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 144
Server version: 5.0.51a-24+lenny5 (Debian)

mysql> connect kamailio
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Connection id:    145
Current database: kamailio

and paste script with SQL commands (made for MySQL) to update the structure of existing tables in v3.1.x for v3.2.0:

ALTER TABLE acc MODIFY callid VARCHAR(255) DEFAULT '' NOT NULL;
ALTER TABLE missed_calls MODIFY callid VARCHAR(255) DEFAULT '' NOT NULL;
 
INSERT INTO version (table_name, table_version) VALUES ('dialog_vars','1');
CREATE TABLE dialog_vars (
    id INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY NOT NULL,
    hash_entry INT(10) UNSIGNED NOT NULL,
    hash_id INT(10) UNSIGNED NOT NULL,
    dialog_key VARCHAR(128) NOT NULL,
    dialog_value VARCHAR(512) NOT NULL
) ENGINE=MyISAM;
CREATE INDEX hash_idx ON dialog_vars (hash_entry, hash_id);
 
UPDATE version SET table_version=2 WHERE table_name="htable";
ALTER TABLE htable MODIFY key_value VARCHAR(128) DEFAULT '' NOT NULL;
ALTER TABLE htable ADD COLUMN expires INT DEFAULT 0 NOT NULL;
 
UPDATE version SET table_version=2 WHERE table_name="lcr_gw";
ALTER TABLE lcr_gw DROP INDEX lcr_id_ip_addr_port_hostname_idx;
ALTER TABLE lcr_gw ADD prefix VARCHAR(16) DEFAULT NULL;
ALTER TABLE lcr_gw MODIFY tag VARCHAR(64) DEFAULT NULL;
CREATE INDEX lcr_id_idx ON lcr_gw (lcr_id);
 
ALTER TABLE active_watchers MODIFY callid VARCHAR(255) NOT NULL,
 
UPDATE version SET table_version=7 WHERE table_name="pua";
ALTER TABLE pua MODIFY pres_id VARCHAR(255) NOT NULL;
ALTER TABLE pua MODIFY call_id VARCHAR(255) NOT NULL;
 
UPDATE version SET table_version=1 WHERE table_name="rls_presentity";
ALTER TABLE rls_presentity MODIFY content_type VARCHAR(255) NOT NULL;
ALTER TABLE rls_presentity MODIFY callid VARCHAR(255) NOT NULL;
ALTER TABLE rls_presentity MODIFY contact VARCHAR(128) NOT NULL;
 
UPDATE version SET table_version=3 WHERE table_name="sip_trace";
ALTER TABLE sip_trace ADD COLUMN time_us INT UNSIGNED DEFAULT 0 NOT NULL;
ALTER TABLE sip_trace MODIFY msg MEDIUMTEXT NOT NULL;
 
UPDATE version SET table_version=4 WHERE table_name="xcap";
ALTER TABLE xcap MODIFY doc MEDIUMBLOB NOT NULL;
ALTER TABLE xcap MODIFY doc_uri VARCHAR(255) NOT NULL;

 the output should look like:

mysql> ALTER TABLE acc MODIFY callid VARCHAR(255) DEFAULT '' NOT NULL;
ALTER TABLE pua MODIFY pres_id VARCHAR(255) NOT NULL;
ALTER TABLE pua MODIFY call_id VARCHAR(255) NOT NULL;

UPDATE version SET table_version=1 WHERE table_name="rls_presentity";
ALTER TABLE rls_presentity MODIFY content_type VARCHAR(255) NOT NULL;
ALTER TABLE rls_presentity MODIFY callid VARCHAR(255) NOT NULL;
ALTER TABLE rls_presentity MODIFY contact VARCHAR(128) NOT NULL;

UPDATE version SET table_version=3 WHERE table_name="sip_trace";
ALTER TABLE sip_trace ADD COLUMN time_us INT UNSIGNED DEFAULT 0 NOT NULL;
ALTER TABLE sip_trace MODIFY msg MEDIUMTEXT NOT NULL;

UPDATE version SET table_version=4 WHERE table_name="xcap";
ALTER TABLE xcap MODIFY doc MEDIUMBLOB NOT NULL;
ALTER TABLE xcap MODIFY doc_uri VARCHAR(255) NOT NULL;Query OK, 0 rows affected (0.04 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> ALTER TABLE missed_calls MODIFY callid VARCHAR(255) DEFAULT '' NOT NULL;
Query OK, 0 rows affected (0.01 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql>
mysql> INSERT INTO version (table_name, table_version) VALUES ('dialog_vars','1');
Query OK, 1 row affected (0.03 sec)

mysql> CREATE TABLE dialog_vars (
    ->     id INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY NOT NULL,
    ->     hash_entry INT(10) UNSIGNED NOT NULL,
    ->     hash_id INT(10) UNSIGNED NOT NULL,
    ->     dialog_key VARCHAR(128) NOT NULL,
    ->     dialog_value VARCHAR(512) NOT NULL
    -> ) ENGINE=MyISAM;
Query OK, 0 rows affected (0.01 sec)

mysql> CREATE INDEX hash_idx ON dialog_vars (hash_entry, hash_id);
Query OK, 0 rows affected (0.00 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql>
mysql> UPDATE version SET table_version=2 WHERE table_name="htable";
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> ALTER TABLE htable MODIFY key_value VARCHAR(128) DEFAULT '' NOT NULL;
Query OK, 0 rows affected (0.01 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> ALTER TABLE htable ADD COLUMN expires INT DEFAULT 0 NOT NULL;
Query OK, 0 rows affected (0.01 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql>
mysql> UPDATE version SET table_version=2 WHERE table_name="lcr_gw";
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> ALTER TABLE lcr_gw DROP INDEX lcr_id_ip_addr_port_hostname_idx;
Query OK, 0 rows affected (0.00 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> ALTER TABLE lcr_gw ADD prefix VARCHAR(16) DEFAULT NULL;
Query OK, 0 rows affected (0.01 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> ALTER TABLE lcr_gw MODIFY tag VARCHAR(64) DEFAULT NULL;
Query OK, 0 rows affected (0.01 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> CREATE INDEX lcr_id_idx ON lcr_gw (lcr_id);
Query OK, 0 rows affected (0.00 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql>
mysql> ALTER TABLE active_watchers MODIFY callid VARCHAR(255) NOT NULL,
    ->
    -> UPDATE version SET table_version=7 WHERE table_name="pua";
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'UPDATE version SET table_version=7 WHERE table_name="pua"' at line 3
mysql> ALTER TABLE pua MODIFY pres_id VARCHAR(255) NOT NULL;
Query OK, 0 rows affected (0.01 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> ALTER TABLE pua MODIFY call_id VARCHAR(255) NOT NULL;
Query OK, 0 rows affected (0.00 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql>
mysql> UPDATE version SET table_version=1 WHERE table_name="rls_presentity";
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> ALTER TABLE rls_presentity MODIFY content_type VARCHAR(255) NOT NULL;
Query OK, 0 rows affected (0.01 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> ALTER TABLE rls_presentity MODIFY callid VARCHAR(255) NOT NULL;
ERROR 1054 (42S22): Unknown column 'callid' in 'rls_presentity'
mysql> ALTER TABLE rls_presentity MODIFY contact VARCHAR(128) NOT NULL;
ERROR 1054 (42S22): Unknown column 'contact' in 'rls_presentity'
mysql>
mysql> UPDATE version SET table_version=3 WHERE table_name="sip_trace";
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> ALTER TABLE sip_trace ADD COLUMN time_us INT UNSIGNED DEFAULT 0 NOT NULL;
Query OK, 0 rows affected (0.00 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> ALTER TABLE sip_trace MODIFY msg MEDIUMTEXT NOT NULL;
Query OK, 0 rows affected (0.00 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql>
mysql> UPDATE version SET table_version=4 WHERE table_name="xcap";
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> ALTER TABLE xcap MODIFY doc MEDIUMBLOB NOT NULL;
Query OK, 9 rows affected (0.04 sec)
Records: 9  Duplicates: 0  Warnings: 0

mysql> ALTER TABLE xcap MODIFY doc_uri VARCHAR(255) NOT NULL;
Query OK, 9 rows affected (0.00 sec)
Records: 9  Duplicates: 0  Warnings: 0

mysql>

Modification of kamailio configuration file

Finally we have to modify the Kamailio configuration file, because when we try to run kamailio following messages are printed.

pstest:/home/palo# /etc/init.d/kamailio start
Not starting Kamailio: invalid configuration file!

 0(27459) ERROR: <core> [cfg.y:3365]: cfg. parser: failed to find command force_rtp_proxy
 0(27459) : <core> [cfg.y:3504]: parse error in config file /etc/kamailio/kamailio.cfg, line 795, column 19: unknown command, missing loadmodule?

 0(27459) ERROR: <core> [cfg.y:3365]: cfg. parser: failed to find command force_rtp_proxy
 0(27459) : <core> [cfg.y:3504]: parse error in config file /etc/kamailio/kamailio.cfg, line 873, column 19: unknown command, missing loadmodule?

ERROR: bad config file (2 errors)

They inform us about using non existing functions used for NAT travesal with RTPproxy. The official migration guide notes:

modules/rtpproxy

  • force_rtp_proxy() removed

    • use rtpproxy_offer() when it is SDP offer (mainly on INVITE request) and rtpproxy_answer() when it is SDP answer (mainly on INVITE replies)

    • new alternative is to use rtpproxy_manage() which does the detection of SDP offer/answer internally

We need to open kamailio.cfg

vim /etc/kamailio/kamailio.cfg

and change appropriate lines. In default kamailio.cfg there are for SIP methods (INVITE) inside of RTPPROXY router logic:

# RTPProxy control
route[RTPPROXY] {
#!ifdef WITH_NAT
        if (is_method("BYE")) {
                unforce_rtp_proxy();
        } else if (is_method("INVITE")){
                rtpproxy_offer();
#               force_rtp_proxy();
        }
        if (!has_totag()) add_rr_param(";nat=yes");
#!endif
        return;
}

 and for replies on onrely_route logic

# Sample onreply route
onreply_route[REPLY_ONE] {
        xdbg("incoming reply\n");
#!ifdef WITH_NAT
        if ((isflagset(FLT_NATS) || isbflagset(FLB_NATB))
                        && status=~"(183)|(2[0-9][0-9])") {
#               force_rtp_proxy();
                rtpproxy_answer();
        }
        if (isbflagset("6")) {
                fix_nated_contact();
        }
#!endif
}

Now we should start and run kamailio service:

pstest:/home/palo# /etc/init.d/kamailio start
Starting Kamailio:
loading modules under /usr/lib/kamailio/modules_k/:/usr/lib/kamailio/modules/
Listening on
             udp: 158.193.139.51:5060
             udp: 2001:4118:300:122:58EC:FCFF:FE3A:17F4:5060
             tcp: 158.193.139.51:5060
             tcp: 2001:4118:300:122:58EC:FCFF:FE3A:17F4:5060
Aliases:
             tcp: pstest:5060
             tcp: pstest.ps.sip.uniza.sk:5060
             udp: pstest:5060
             udp: pstest.ps.sip.uniza.sk:5060
             *: ps.sip.uniza.sk:*

kamailio started.

 Note

If you are using LCR modules, check how to migrate your installation at official migration guide.

Rate this post

Leave a Reply

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

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.