From ebaa99518ae5d4bf2278290c96a2462f4dddc893 Mon Sep 17 00:00:00 2001 From: Sebastian Kemper Date: Mon, 5 Nov 2018 21:50:44 +0100 Subject: [PATCH] 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 --- net/kamailio-5.x/Makefile | 10 +-- net/kamailio-5.x/files/kamailio.config | 12 ++++ net/kamailio-5.x/files/kamailio.default | 14 ---- net/kamailio-5.x/files/kamailio.init | 85 ++++++++++++++++--------- 4 files changed, 73 insertions(+), 48 deletions(-) create mode 100644 net/kamailio-5.x/files/kamailio.config delete mode 100644 net/kamailio-5.x/files/kamailio.default diff --git a/net/kamailio-5.x/Makefile b/net/kamailio-5.x/Makefile index 32d82af..e5aa478 100644 --- a/net/kamailio-5.x/Makefile +++ b/net/kamailio-5.x/Makefile @@ -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 \ diff --git a/net/kamailio-5.x/files/kamailio.config b/net/kamailio-5.x/files/kamailio.config new file mode 100644 index 0000000..1f91f85 --- /dev/null +++ b/net/kamailio-5.x/files/kamailio.config @@ -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 "" + diff --git a/net/kamailio-5.x/files/kamailio.default b/net/kamailio-5.x/files/kamailio.default deleted file mode 100644 index 1fc875d..0000000 --- a/net/kamailio-5.x/files/kamailio.default +++ /dev/null @@ -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 diff --git a/net/kamailio-5.x/files/kamailio.init b/net/kamailio-5.x/files/kamailio.init index 38bba51..75a8302 100644 --- a/net/kamailio-5.x/files/kamailio.init +++ b/net/kamailio-5.x/files/kamailio.init @@ -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 -}