From: Sebastian Kemper Date: Sun, 26 Aug 2018 10:35:11 +0000 (+0200) Subject: freeswitch-stable: replace defaults with uci X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=refs%2Fpull%2F367%2Fhead;p=feed%2Ftelephony.git freeswitch-stable: replace defaults with uci This commit replaces /etc/default/freeswitch with /etc/config/freeswitch. This way the init and hotplug configuration can be done with uci instead of having to edit a file. This also does away with the busybox ntpd warning. ntpd uses the same configuration in system and it looks like busybox's ntpd is not used when ntpd is installed. Lastly some log strings are amended to start with a lowercase letter. Signed-off-by: Sebastian Kemper --- diff --git a/net/freeswitch-stable/Makefile b/net/freeswitch-stable/Makefile index 7e8ff6b..264e7ca 100644 --- a/net/freeswitch-stable/Makefile +++ b/net/freeswitch-stable/Makefile @@ -10,7 +10,7 @@ include $(TOPDIR)/rules.mk PRG_NAME:=freeswitch PKG_NAME:=$(PRG_NAME)-stable PKG_VERSION:=1.8.1 -PKG_RELEASE:=5 +PKG_RELEASE:=6 PKG_MAINTAINER:=Sebastian Kemper PKG_SOURCE_PROTO:=git @@ -400,7 +400,7 @@ endef define Package/$(PKG_NAME)/conffiles $(FS_STABLE_SYSCONF_DIR)/$(PRG_NAME) -$(FS_STABLE_SYSCONF_DIR)/default/$(PRG_NAME) +$(FS_STABLE_SYSCONF_DIR)/config/$(PRG_NAME) $(FS_STABLE_SYSCONF_DIR)/init.d/$(PRG_NAME) endef @@ -413,13 +413,13 @@ $(call Package/$(PKG_NAME)/install/lib,$(1),lib$(PRG_NAME)) $(INSTALL_DIR) $(1)$(FS_STABLE_IMAGES_DIR) $(INSTALL_DIR) $(1)$(FS_STABLE_SCRIPTS_DIR) $(INSTALL_DIR) $(1)$(FS_STABLE_SOUNDS_DIR) - $(INSTALL_DIR) $(1)$(FS_STABLE_SYSCONF_DIR)/default + $(INSTALL_DIR) $(1)$(FS_STABLE_SYSCONF_DIR)/config $(INSTALL_DIR) $(1)$(FS_STABLE_SYSCONF_DIR)/init.d $(INSTALL_DIR) $(1)$(FS_STABLE_TLS_DIR) $(INSTALL_BIN) ./files/$(PRG_NAME).init \ $(1)$(FS_STABLE_SYSCONF_DIR)/init.d/$(PRG_NAME) - $(INSTALL_CONF) ./files/$(PRG_NAME).default \ - $(1)$(FS_STABLE_SYSCONF_DIR)/default/$(PRG_NAME) + $(INSTALL_CONF) ./files/$(PRG_NAME).config \ + $(1)$(FS_STABLE_SYSCONF_DIR)/config/$(PRG_NAME) endef define Package/$(PKG_NAME)/postinst @@ -427,14 +427,14 @@ define Package/$(PKG_NAME)/postinst if [ -z "$${IPKG_INSTROOT}" ]; then # Prevent $(PRG_NAME) from auto-starting after an upgrade. The modules may # not be upgraded yet and the user configuration may need a revision. - sed -i '/^ENABLE_FREESWITCH="yes"/s/^/#/' \ - $(FS_STABLE_SYSCONF_DIR)/default/$(PRG_NAME) + uci set freeswitch.general.enabled=0 + uci commit freeswitch echo echo "o-------------------------------------------------------------------o" echo "| FreeSWITCH note |" echo "o-------------------------------------------------------------------o" - echo "| Edit /etc/default/freeswitch to change basic init configuration. |" + echo "| Edit /etc/config/freeswitch to change basic init configuration. |" echo "o-------------------------------------------------------------=^_^=-o" echo fi @@ -465,7 +465,7 @@ if [ -z "$${IPKG_INSTROOT}" ]; then echo "o-------------------------------------------------------------------o" echo "| FreeSWITCH hotplug note |" echo "o-------------------------------------------------------------------o" - echo "| See /etc/default/freeswitch for hotplug hints. |" + echo "| See /etc/config/freeswitch for hotplug hints. |" echo "o-------------------------------------------------------------=^_^=-o" echo fi diff --git a/net/freeswitch-stable/files/freeswitch.config b/net/freeswitch-stable/files/freeswitch.config new file mode 100644 index 0000000..66f8891 --- /dev/null +++ b/net/freeswitch-stable/files/freeswitch.config @@ -0,0 +1,22 @@ + +config freeswitch 'general' + option enabled '0' + option user 'freeswitch' + option group 'freeswitch' + option options '-nonat -np' + option change_perm '0' + +config freeswitch 'directories' + option cache '/tmp/freeswitch/cache' + option db '/tmp/freeswitch/db' + option log '/tmp/freeswitch/log' + option recordings '/tmp/freeswitch/recordings' + option storage '/tmp/freeswitch/storage' + option temp '/tmp/freeswitch/temp' + +config freeswitch 'hotplug' + #option interface 'wan' + #option mount_point '/mnt/usb' + option ntpd '0' + option timeout '60' + diff --git a/net/freeswitch-stable/files/freeswitch.default b/net/freeswitch-stable/files/freeswitch.default deleted file mode 100644 index cfea494..0000000 --- a/net/freeswitch-stable/files/freeswitch.default +++ /dev/null @@ -1,44 +0,0 @@ -### FreeSWITCH configuration ### - -# Uncomment once you verified your configuration, otherwise the init script will -# not start FreeSWITCH. -#ENABLE_FREESWITCH="yes" - -#FS_USER=freeswitch -#FS_GROUP=freeswitch - -#FS_DIR_CACHE="/tmp/freeswitch/cache" - -# Don't point FS_DIR_DB toward a flash drive, e.g. the flash drive of your -# router. FreeSWITCH will be writing constantly to its databases, which would -# degrade the flash over time. Point it to a tmpfs destination like /dev/shm or -# /tmp instead in order for the writes to go to RAM. -#FS_DIR_DB="/tmp/freeswitch/db" - -#FS_DIR_LOG="/tmp/freeswitch/log" -#FS_DIR_RECORDINGS="/tmp/freeswitch/recordings" -#FS_DIR_STORAGE="/tmp/freeswitch/storage" -#FS_DIR_TEMP="/tmp/freeswitch/temp" - -# The following is added to the command line when starting FreeSWITCH: -OPTIONS="-nonat -np" - -### Hotplug configuration ### - -# Only used by the FreeSWITCH hotplug script (available in a seperate package). - -# Provide the interface that needs to change its state to "up" (if unset the -# hotplug script does nothing): -#FS_HOTPLUG_INTERFACE="wan" - -# You can add conditions which need to be met before FreeSWITCH is started. - -# Uncomment to check if something is mounted here: -#FS_HOTPLUG_MOUNTPOINT="/mnt/usb" - -# Uncomment to check if ntpd is running and has set the system time: -#FS_HOTPLUG_NTPD="check" - -# Uncomment to change the default timeout of 60 seconds that the hotplug script -# waits for a condition to turn from false to true: -#FS_HOTPLUG_TIMEOUT="20" diff --git a/net/freeswitch-stable/files/freeswitch.hotplug b/net/freeswitch-stable/files/freeswitch.hotplug index 4a6a2c1..10778cb 100644 --- a/net/freeswitch-stable/files/freeswitch.hotplug +++ b/net/freeswitch-stable/files/freeswitch.hotplug @@ -1,7 +1,6 @@ #!/bin/sh FS=freeswitch -DEFAULT=/etc/default/$FS LOGGER="/usr/bin/logger -t ${FS}-hotplug" LOG_ERR="$LOGGER -p user.err --" LOG_NOTICE="$LOGGER -p user.notice --" @@ -9,7 +8,10 @@ LOG_WARN="$LOGGER -p user.warn --" [ "$ACTION" = ifup ] || exit 0 -[ -f $DEFAULT ] && . $DEFAULT +. /lib/functions.sh +config_load $FS + +config_get FS_HOTPLUG_INTERFACE hotplug interface [ -n "$FS_HOTPLUG_INTERFACE" ] || exit 0 @@ -17,20 +19,24 @@ LOG_WARN="$LOGGER -p user.warn --" pgrep $FS &> /dev/null if [ $? -eq 0 ]; then - $LOG_NOTICE Stopping $FS + $LOG_NOTICE stopping $FS /etc/init.d/$FS stop &> /dev/null pgrep $FS &> /dev/null if [ $? -eq 0 ]; then - $LOG_ERR Failed to stop $FS + $LOG_ERR failed to stop $FS exit 1 else $LOG_NOTICE $FS stopped fi fi +config_get FS_HOTPLUG_TIMEOUT hotplug timeout + [ "$FS_HOTPLUG_TIMEOUT" -gt 0 ] 2> /dev/null || unset FS_HOTPLUG_TIMEOUT TIMEOUT="${FS_HOTPLUG_TIMEOUT:-60}" +config_get FS_HOTPLUG_MOUNTPOINT hotplug mount_point + # Mount condition, idea lifted from OpenWrt wiki [ -n "$FS_HOTPLUG_MOUNTPOINT" ] && { @@ -60,7 +66,7 @@ TIMEOUT="${FS_HOTPLUG_TIMEOUT:-60}" if [ -n "$notReady" ]; then $LOG_ERR "$mnt" still not mounted - $LOG_ERR Not starting $FS + $LOG_ERR not starting $FS exit 1 else $LOG_NOTICE "$mnt" mounted @@ -68,8 +74,10 @@ TIMEOUT="${FS_HOTPLUG_TIMEOUT:-60}" } +config_get_bool FS_HOTPLUG_NTPD hotplug ntpd 0 + # ntpd condition -[ -n "$FS_HOTPLUG_NTPD" ] && { +[ $FS_HOTPLUG_NTPD -eq 1 ] && { type ntpq &> /dev/null [ $? -eq 0 ] || { @@ -85,14 +93,9 @@ TIMEOUT="${FS_HOTPLUG_TIMEOUT:-60}" notReady=start timeout=$TIMEOUT - result=$(uci get 'system.ntp.enabled' 2> /dev/null) - [ "$result" -eq 1 ] 2> /dev/null && { - $LOG_WARN BusyBox NTP client _and_ ntpd running - } - while [ -n "$notReady" -a $timeout -gt 0 ]; do if [ "$notReady" != start ]; then - $LOG_NOTICE System time not in sync yet, timeout in $timeout s + $LOG_NOTICE system time not in sync yet, timeout in $timeout s sleep 5 timeout=$(($timeout-5)) fi @@ -102,7 +105,7 @@ TIMEOUT="${FS_HOTPLUG_TIMEOUT:-60}" result=$(ntpq -c 'timeout 300' -c 'rv 0 stratum' 2> /dev/null | \ awk -F '=' '{print $2}' | grep -o -E '^[0-9]+') if [ -z $result ]; then - $LOG_WARN Failed to extract stratum from ntpd + $LOG_WARN failed to extract stratum from ntpd notReady="unable to extract stratum" else $LOG_NOTICE ntpd stratum $result @@ -110,7 +113,7 @@ TIMEOUT="${FS_HOTPLUG_TIMEOUT:-60}" result=$(ntpq -c 'timeout 300' -c 'rv 0 offset' 2> /dev/null \ | awk -F '=' '{print $2}' | grep -o -E '^-?[0-9]+') if [ -z $result ]; then - $LOG_WARN Failed to extract offset from ntpd + $LOG_WARN failed to extract offset from ntpd notReady="unable to extract offset" else # "-0" looks stupid, so remove "-" @@ -126,11 +129,11 @@ TIMEOUT="${FS_HOTPLUG_TIMEOUT:-60}" done if [ -n "$notReady" ]; then - $LOG_ERR System time still not in sync - $LOG_ERR Not starting $FS + $LOG_ERR system time still not in sync + $LOG_ERR not starting $FS exit 1 else - $LOG_NOTICE System time in sync + $LOG_NOTICE system time in sync fi } @@ -140,8 +143,8 @@ TIMEOUT="${FS_HOTPLUG_TIMEOUT:-60}" sleep 1 pgrep $FS &>/dev/null if [ $? -eq 0 ]; then - $LOG_NOTICE Started $FS due to \"ifup "$INTERFACE"\" event + $LOG_NOTICE started $FS due to \"ifup "$INTERFACE"\" event else - $LOG_ERR Start of $FS due to \"ifup "$INTERFACE"\" event failed + $LOG_ERR start of $FS due to \"ifup "$INTERFACE"\" event failed exit 1 fi diff --git a/net/freeswitch-stable/files/freeswitch.init b/net/freeswitch-stable/files/freeswitch.init index a46df7d..eb064d4 100644 --- a/net/freeswitch-stable/files/freeswitch.init +++ b/net/freeswitch-stable/files/freeswitch.init @@ -8,37 +8,50 @@ USE_PROCD=1 #PROCD_DEBUG=1 FS=freeswitch -DEFAULT=/etc/default/$FS LOGGER="/usr/bin/logger -p user.err -s -t $FS" -OPTIONS= -PROG=/usr/bin/$FS -TIMEOUT=30 -[ -f $DEFAULT ] && . $DEFAULT +# used in both start_service() and stop_service() +fs_dir_run=/var/run/$FS -fs_user="${FS_USER:-$FS}" -fs_group="${FS_GROUP:-$FS}" +start_service() { + local change_perm + local dir + local enabled -fs_dir_etc="/etc/$FS" -fs_dir_localstate="/var/lib/$FS" -fs_dir_run="/var/run/$FS" + local fs_user + local fs_group -fs_dir_cache="${FS_DIR_CACHE:-/tmp/$FS/cache}" -fs_dir_db="${FS_DIR_DB:-/tmp/$FS/db}" -fs_dir_log="${FS_DIR_LOG:-/tmp/$FS/log}" -fs_dir_recordings="${FS_DIR_RECORDINGS:-/tmp/$FS/recordings}" -fs_dir_storage="${FS_DIR_STORAGE:-/tmp/$FS/storage}" -fs_dir_temp="${FS_DIR_TEMP:-/tmp/$FS/temp}" + local fs_dir_cache + local fs_dir_db + local fs_dir_etc=/etc/$FS + local fs_dir_localstate=/var/lib/$FS + local fs_dir_log + local fs_dir_recordings + local fs_dir_storage + local fs_dir_temp -start_service() { - local dir= + local OPTIONS + + local PROG=/usr/bin/$FS + + config_load $FS - if [ "$ENABLE_FREESWITCH" != yes ]; then - $LOGGER User configuration incomplete - not starting $FS - $LOGGER Check ENABLE_FREESWITCH in $DEFAULT + config_get_bool enabled general enabled 0 + if [ $enabled -eq 0 ]; then + $LOGGER service not enabled in /etc/config/$FS exit 1 fi + config_get fs_user general user $FS + config_get fs_group general group $FS + + config_get fs_dir_cache directories cache /tmp/$FS/cache + config_get fs_dir_db directories db /tmp/$FS/db + config_get fs_dir_log directories log /tmp/$FS/log + config_get fs_dir_recordings directories recordings /tmp/$FS/recordings + config_get fs_dir_storage directories storage /tmp/$FS/storage + config_get fs_dir_temp directories temp /tmp/$FS/temp + for dir in "$fs_dir_cache" "$fs_dir_db" "$fs_dir_localstate" \ "$fs_dir_log" "$fs_dir_recordings" "$fs_dir_run" "$fs_dir_storage" \ "$fs_dir_temp" @@ -50,10 +63,13 @@ start_service() { } done - #[ -d "$fs_dir_etc" ] && { - # find "$fs_dir_etc" -type f -exec chown root:"$fs_group" {} \; - # find "$fs_dir_etc" -type f -exec chmod 640 {} \; - #} + config_get_bool change_perm general change_perm 0 + [ $change_perm -eq 1 ] && [ -d "$fs_dir_etc" ] && { + find "$fs_dir_etc" -type f -exec chown root:"$fs_group" {} \; + find "$fs_dir_etc" -type f -exec chmod 640 {} \; + } + + config_get OPTIONS general options procd_open_instance # starting with full path seems cleaner judging by 'ps' output @@ -79,8 +95,9 @@ start_service() { } stop_service() { - local retval= - local mypid= + local retval + local mypid + local TIMEOUT=30 local timeout=$TIMEOUT pgrep $FS &> /dev/null @@ -124,8 +141,8 @@ stop_service() { done [ $retval -ne 1 ] && { - $LOGGER Application seems to hang - $LOGGER Sending SIGKILL + $LOGGER application seems to hang + $LOGGER sending SIGKILL kill -SIGKILL $mypid 2>/dev/null sleep 3 pgrep $FS | grep -w $mypid &>/dev/null @@ -133,7 +150,7 @@ stop_service() { } [ $retval -ne 1 ] && { - $LOGGER Failed to stop $FS + $LOGGER failed to stop $FS exit 1 } }