kamailio-5.x: convert init to procd

This commit

  - updates init script to use procd
  - adds a default user 'kamailio' (kamailio will switch to this user)
  - introduces uci init config (instead of /etc/default/kamailio)

Signed-off-by: Sebastian Kemper <sebastian_ml@gmx.net>
This commit is contained in:
Sebastian Kemper 2018-11-05 21:50:44 +01:00
parent 72cb5b8350
commit ebaa99518a
4 changed files with 73 additions and 48 deletions

View file

@ -241,11 +241,13 @@ endef
define Package/kamailio5
$(call Package/kamailio5/Default)
TITLE:=Mature and flexible open source SIP server, v$(PKG_VERSION)
USERID:=kamailio=380:kamailio=380
MENU:=1
endef
define Package/kamailio5/conffiles
/etc/default/kamailio
/etc/config/kamailio
/etc/init.d/kamailio
/etc/kamailio/kamailio.cfg
/etc/kamailio/kamctlrc
endef
@ -260,10 +262,10 @@ $(foreach c,kamailio.cfg kamctlrc,$(call Package/kamailio5/install/conffile,$(1)
$(CP) \
$(PKG_INSTALL_DIR)/usr/lib/kamailio/lib{srdb1,srdb2,srutils}.so* \
$(1)/usr/lib/kamailio/
$(INSTALL_DIR) $(1)/etc/default
$(INSTALL_DIR) $(1)/etc/config
$(INSTALL_CONF) \
./files/kamailio.default \
$(1)/etc/default/kamailio
./files/kamailio.config \
$(1)/etc/config/kamailio
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_BIN) \
./files/kamailio.init \

View file

@ -0,0 +1,12 @@
config kamailio 'general'
option enabled 0
option user kamailio
option group kamailio
# Amount of shared and private memory to allocate in MByte:
option shm_memory 8
option pkg_memory 2
option cfg_file /etc/kamailio/kamailio.cfg
# Any other option can be put between the quotes below:
#option options ""

View file

@ -1,14 +0,0 @@
#
# Kamailio startup options
#
# Set to yes to enable kamailio, once configured properly.
#RUN_KAMAILIO=yes
# Amount of shared and private memory to allocate
# for the running Kamailio server (in Mb)
#SHM_MEMORY=64
#PKG_MEMORY=4
# Config file
#CFGFILE=/etc/kamailio/kamailio.cfg

View file

@ -1,38 +1,63 @@
#!/bin/sh /etc/rc.common
# Copyright (C) 2014 OpenWrt.org
# Copyright (C) 2014 - 2018 OpenWrt.org
START=99
BINFILE=/usr/sbin/kamailio
PIDFILE=/var/run/kamailio.pid
DEFAULTS=/etc/default/kamailio
CFGFILE=/etc/kamailio/kamailio.cfg
SHM_MEMORY=8
PKG_MEMORY=2
RUN_KAMAILIO=no
NAME=kamailio
COMMAND=/usr/sbin/$NAME
start() {
# Load startup options if available
if [ -f $DEFAULTS ]; then
. $DEFAULTS
fi
RUNDIR=/var/run/$NAME
PIDFILE=$RUNDIR/$NAME.pid
if [ "$RUN_KAMAILIO" != "yes" ]; then
echo "[WARNING] Kamailio not yet configured. Edit /etc/default/kamailio first."
else
start-stop-daemon -S -x $BINFILE -b -- -P $PIDFILE -f $CFGFILE -m $SHM_MEMORY -M $PKG_MEMORY
echo "[INFO] Kamailio has succesfully started."
fi
LOG_ERR="/usr/bin/logger -p user.err -s -t $NAME"
USE_PROCD=1
#PROCD_DEBUG=1
start_service() {
local enabled
local user
local group
local shm_memory
local pkg_memory
local cfg_file
local options
config_load $NAME
config_get_bool enabled general enabled 0
if [ $enabled -eq 0 ]; then
$LOG_ERR service not enabled in /etc/config/$NAME
exit 1
fi
config_get user general user $NAME
config_get group general group $NAME
config_get shm_memory general shm_memory 8
config_get pkg_memory general pkg_memory 2
config_get cfg_file general cfg_file /etc/$NAME/$NAME.cfg
config_get options general options
if [ ! -d $RUNDIR ]; then
mkdir -p $RUNDIR
chown "$user":"$group" $RUNDIR
fi
procd_open_instance
procd_set_param command $COMMAND
procd_append_param command \
-P $PIDFILE \
-f "$cfg_file" \
-m "$shm_memory" \
-M "$pkg_memory" \
$options \
-u "$user" \
-g "$group" \
-DD -E
# forward stderr to logd
procd_set_param stderr 1
procd_close_instance
}
stop() {
start-stop-daemon -K -x $BINFILE -p $PIDFILE -q
rm -rf $PID_FILE
}
restart(){
echo "[INFO] Restarting kamailio. Waiting 5 seconds before start."
stop
sleep 5
start
}