kamailio: Kamailio 6.0.1 uci config and init script fixes

bump pkg_memory 2MiB -> 3MiB.
space -> tab convert kamailio.init file
refactor kamailio.init check_listen() for clarity
cfg_target: append /
quote uci config values
chown kamailio:kamailio -R /etc/kamailio/*
debug_level 0
stderr 0

Signed-off-by: Paul Donald <newtwen+github@gmail.com>
This commit is contained in:
Paul Donald 2025-04-20 03:56:56 +02:00
parent 2a1b0e1121
commit 6c9fae756c
3 changed files with 132 additions and 106 deletions

View File

@ -10,7 +10,7 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=kamailio PKG_NAME:=kamailio
PKG_VERSION:=6.0.1 PKG_VERSION:=6.0.1
PKG_RELEASE:=1 PKG_RELEASE:=2
PKG_SOURCE_URL:=https://github.com/kamailio/kamailio/archive/refs/tags/ PKG_SOURCE_URL:=https://github.com/kamailio/kamailio/archive/refs/tags/
PKG_SOURCE:=$(PKG_VERSION).tar.gz PKG_SOURCE:=$(PKG_VERSION).tar.gz
@ -263,6 +263,8 @@ endef
define Package/kamailio define Package/kamailio
$(call Package/kamailio/Default) $(call Package/kamailio/Default)
TITLE:=Mature and flexible open source SIP server, v$(PKG_VERSION) TITLE:=Mature and flexible open source SIP server, v$(PKG_VERSION)
USER:=kamailio
GROUP:=kamailio
USERID:=kamailio=380:kamailio=380 USERID:=kamailio=380:kamailio=380
MENU:=1 MENU:=1
endef endef
@ -300,6 +302,7 @@ endef
define Package/kamailio/postinst define Package/kamailio/postinst
#!/bin/sh #!/bin/sh
chown "$(USER)":"$(GROUP)" "/etc/kamailio" -R
if [ -z "$${IPKG_INSTROOT}" ]; then if [ -z "$${IPKG_INSTROOT}" ]; then
echo echo
echo "o-------------------------------------------------------------------o" echo "o-------------------------------------------------------------------o"
@ -412,7 +415,7 @@ MAKE_FLAGS += \
LIBDIR=lib \ LIBDIR=lib \
PREFIX=/usr \ PREFIX=/usr \
cfg_prefix="$(PKG_INSTALL_DIR)" \ cfg_prefix="$(PKG_INSTALL_DIR)" \
cfg_target=/etc/kamailio \ cfg_target=/etc/kamailio/ \
group_include="standard" \ group_include="standard" \
include_modules="$$(INCL_MODULES) $(EXTRA_MODULES)" \ include_modules="$$(INCL_MODULES) $(EXTRA_MODULES)" \
quiet=verbose \ quiet=verbose \

View File

@ -1,22 +1,25 @@
config kamailio 'general' config kamailio 'general'
option enabled 0 option enabled '0'
option user kamailio option user 'kamailio'
option group kamailio option group 'kamailio'
# Amount of shared and private memory to allocate in MByte: # Amount of shared and private memory to allocate in MByte:
option shm_memory 8 option shm_memory '8'
option pkg_memory 2 option pkg_memory '3'
option cfg_file /etc/kamailio/kamailio.cfg option cfg_file /etc/kamailio/kamailio.cfg
# The lists "listen" and "listen6" basically have the same option stderr '0'
# effect - each list entry will be added to the Kamailio command option debug_level '0'
# line ("-l address"). However, the init script will try to # list listen(6) have the same effect - each list entry is added to the
# Kamailio command line ("-l address"). The init script will try to
# resolve any interface specifier into an IPv4 ("listen") or # resolve any interface specifier into an IPv4 ("listen") or
# IPv6 ("listen6") address before starting Kamailio. These lists # IPv6 ("listen6") address before starting Kamailio. These list listen(6)
# may be helpful when using dynamic IPs. # may be helpful when using dynamic IPs.
#list listen udp:wan:5060 # Examples:
#list listen udp:192.168.1.1:5060 # list listen 'udp:wan:5060'
#list listen6 udp:wan:5060 # list listen 'udp:192.168.1.1:5060'
# Any other option can be put between the quotes below: # list listen6 'udp:wan:5060'
# list listen6 'udp:[::1]:5060'
# Any other Kamailio start parameter can be put in the options quotes below:
#option options "" #option options ""
config kamailio 'hotplug' config kamailio 'hotplug'

View File

@ -19,63 +19,71 @@ check_listen() {
local value="$1" local value="$1"
local type="$2" local type="$2"
local address local proto host port address result
local has_proto=0
local one two three
local tmp
[ -z "$value" ] && { [ -z "$value" ] && {
$LOG_ERR empty $type entry $LOG_ERR empty $type entry
return 1 return 1
} }
# IPv6 addresses need to be enclosed in square brackets. If there are # [IPv6] - pass through as-is
# square brackets in the listen entry, just copy it. case "$value" in
echo "$value" | grep "\[[0-9:A-Fa-f]*\]" &> /dev/null && { *\[*\]*)
options=$options" -l $value" options="$options -l $value"
return return
}
# Bail if more than 2 colons.
[ $(echo "$value" | awk -F ":" '{print NF-1}') -gt 2 ] && {
$LOG_ERR init script does not understand $type entry \""$value"\"
return 1
}
IFS=":" read one two three << EOF
$value
EOF
case "$one" in
udp|tcp|tls|sctp)
tmp="$two"
has_proto=1
;;
*)
tmp="$one"
;; ;;
esac esac
# Count colons. More than 2 means malformed
# Format: proto:host:port
if [ "$(echo "$value" | awk -F: '{print NF-1}')" -gt 2 ]; then
$LOG_ERR init script does not understand $type entry \""$value"\"
return 1
fi
# Parse proto (if present)
case "$value" in
udp:*|tcp:*|tls:*|sctp:*)
proto="${value%%:*}"
value="${value#*:}"
;;
esac
# Parse port (if present)
case "$value" in
*:* )
host="${value%%:*}"
port="${value#*:}"
;;
*)
host="$value"
port=""
;;
esac
# Resolve host to IP or interface
if [ "$type" = "listen" ]; then if [ "$type" = "listen" ]; then
network_get_ipaddr address "$tmp" || address="$tmp" network_get_ipaddr address "$host" || address="$host"
else else
network_get_ipaddr6 address "$tmp" && address="[$address]" || \ network_get_ipaddr6 address "$host" && address="[$address]" || address="$host"
address="$tmp"
fi fi
if [ -n "$three" ]; then # Reconstruct result
tmp="$one:$address:$three" if [ -n "$proto" ]; then
elif [ -n "$two" ]; then if [ -n "$port" ]; then
if [ $has_proto = 1 ]; then result="$proto:$address:$port"
tmp="$one:$address"
else else
tmp="$address:$two" result="$proto:$address"
fi fi
else else
tmp="$address" if [ -n "$port" ]; then
result="$address:$port"
else
result="$address"
fi
fi fi
options=$options" -l $tmp" options="$options -l $result"
} }
start_service() { start_service() {
@ -99,18 +107,24 @@ start_service() {
config_get user general user $NAME config_get user general user $NAME
config_get group general group $NAME config_get group general group $NAME
config_get shm_memory general shm_memory 8 config_get shm_memory general shm_memory 8
config_get pkg_memory general pkg_memory 2 config_get pkg_memory general pkg_memory 3
config_get cfg_file general cfg_file /etc/$NAME/$NAME.cfg config_get cfg_file general cfg_file /etc/$NAME/$NAME.cfg
config_get options general options config_get options general options
config_get_bool stderr general stderr 0
config_get debug_level general debug_level 0
. /lib/functions/network.sh . /lib/functions/network.sh
config_list_foreach general listen check_listen listen config_list_foreach general listen check_listen listen
config_list_foreach general listen6 check_listen listen6 config_list_foreach general listen6 check_listen listen6
if [ ! -d $RUNDIR ]; then if [ ! -d "$RUNDIR" ]; then
mkdir -p $RUNDIR mkdir -p "$RUNDIR"
chown "$user":"$group" $RUNDIR chown "$user":"$group" "$RUNDIR"
fi
if [ -d "/etc/kamailio" ]; then
chown "$user":"$group" /etc/kamailio/ -R
fi fi
procd_open_instance procd_open_instance
@ -123,9 +137,15 @@ start_service() {
$options \ $options \
-u "$user" \ -u "$user" \
-g "$group" \ -g "$group" \
-DD -E -DDD
# forward stderr to logd # If log_stderror=no (default) global parameter and -E is not provided, then it writes to syslog daemon
procd_set_param stderr 1 [ "$stderr" -eq '1' ] && procd_append_param command -E
procd_append_param command --debug $debug_level
# silence stderr (useful only for debug)
procd_set_param stderr 0
# forward stdout to logd
procd_set_param stdout 1
procd_close_instance procd_close_instance
} }