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

@ -16,116 +16,136 @@ USE_PROCD=1
#PROCD_DEBUG=1 #PROCD_DEBUG=1
check_listen() { 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
} ;;
esac
# Bail if more than 2 colons. # Count colons. More than 2 means malformed
[ $(echo "$value" | awk -F ":" '{print NF-1}') -gt 2 ] && { # Format: proto:host:port
$LOG_ERR init script does not understand $type entry \""$value"\" if [ "$(echo "$value" | awk -F: '{print NF-1}')" -gt 2 ]; then
return 1 $LOG_ERR init script does not understand $type entry \""$value"\"
} return 1
fi
IFS=":" read one two three << EOF # Parse proto (if present)
$value case "$value" in
EOF udp:*|tcp:*|tls:*|sctp:*)
proto="${value%%:*}"
value="${value#*:}"
;;
esac
case "$one" in # Parse port (if present)
udp|tcp|tls|sctp) case "$value" in
tmp="$two" *:* )
has_proto=1 host="${value%%:*}"
;; port="${value#*:}"
*) ;;
tmp="$one" *)
;; host="$value"
esac port=""
;;
esac
if [ "$type" = "listen" ]; then # Resolve host to IP or interface
network_get_ipaddr address "$tmp" || address="$tmp" if [ "$type" = "listen" ]; then
else network_get_ipaddr address "$host" || address="$host"
network_get_ipaddr6 address "$tmp" && address="[$address]" || \ else
address="$tmp" network_get_ipaddr6 address "$host" && address="[$address]" || address="$host"
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 result="$proto:$address"
tmp="$address:$two" fi
fi else
else if [ -n "$port" ]; then
tmp="$address" result="$address:$port"
fi else
result="$address"
fi
fi
options=$options" -l $tmp" options="$options -l $result"
} }
start_service() { start_service() {
local enabled local enabled
local user local user
local group local group
local shm_memory local shm_memory
local pkg_memory local pkg_memory
local cfg_file local cfg_file
local options local options
config_load $NAME config_load $NAME
config_get_bool enabled general enabled 0 config_get_bool enabled general enabled 0
if [ $enabled -eq 0 ]; then if [ $enabled -eq 0 ]; then
$LOG_ERR service not enabled in /etc/config/$NAME $LOG_ERR service not enabled in /etc/config/$NAME
return 1 return 1
fi fi
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 fi
procd_open_instance if [ -d "/etc/kamailio" ]; then
procd_set_param command $COMMAND chown "$user":"$group" /etc/kamailio/ -R
procd_append_param command \ fi
-P $PIDFILE \
-f "$cfg_file" \ procd_open_instance
-m "$shm_memory" \ procd_set_param command $COMMAND
-M "$pkg_memory" \ procd_append_param command \
$options \ -P $PIDFILE \
-u "$user" \ -f "$cfg_file" \
-g "$group" \ -m "$shm_memory" \
-DD -E -M "$pkg_memory" \
# forward stderr to logd $options \
procd_set_param stderr 1 -u "$user" \
procd_close_instance -g "$group" \
-DDD
# If log_stderror=no (default) global parameter and -E is not provided, then it writes to syslog daemon
[ "$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
} }