Merge pull request #390 from micmac1/fs-init

freeswitch-stable: init/hotplug updates
This commit is contained in:
micmac1 2018-11-12 22:47:05 +01:00 committed by GitHub
commit d0a14b89b6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 129 additions and 200 deletions

View file

@ -10,7 +10,7 @@ include $(TOPDIR)/rules.mk
PRG_NAME:=freeswitch
PKG_NAME:=$(PRG_NAME)-stable
PKG_VERSION:=1.8.2
PKG_RELEASE:=1
PKG_RELEASE:=2
PKG_MAINTAINER:=Sebastian Kemper <sebastian_ml@gmx.net>
PKG_SOURCE:=$(PRG_NAME)-$(PKG_VERSION).tar.xz
@ -414,10 +414,13 @@ $(call Package/$(PKG_NAME)/install/lib,$(1),lib$(PRG_NAME))
$(INSTALL_DIR) $(1)$(FS_STABLE_SCRIPTS_DIR)
$(INSTALL_DIR) $(1)$(FS_STABLE_SOUNDS_DIR)
$(INSTALL_DIR) $(1)$(FS_STABLE_SYSCONF_DIR)/config
$(INSTALL_DIR) $(1)$(FS_STABLE_SYSCONF_DIR)/hotplug.d/iface
$(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_BIN) ./files/$(PRG_NAME).hotplug \
$(1)$(FS_STABLE_SYSCONF_DIR)/hotplug.d/iface/90-$(PRG_NAME)
$(INSTALL_CONF) ./files/$(PRG_NAME).config \
$(1)$(FS_STABLE_SYSCONF_DIR)/config/$(PRG_NAME)
endef
@ -425,49 +428,27 @@ endef
define Package/$(PKG_NAME)/postinst
#!/bin/sh
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.
uci set freeswitch.general.enabled=0
uci commit freeswitch
echo
echo "o-------------------------------------------------------------------o"
echo "| FreeSWITCH note |"
echo "o-------------------------------------------------------------------o"
echo "| Edit /etc/config/freeswitch to change basic init configuration. |"
echo "| |"
echo "| Also visit the Wiki at: |"
echo "| https://openwrt.org/docs/guide-user/services/voip/freeswitch |"
echo "o-------------------------------------------------------------=^_^=-o"
echo
fi
exit 0
endef
define Package/$(PKG_NAME)-misc-hotplug
$(call Package/$(PKG_NAME)/Default)
TITLE:=Hotplug script
DEPENDS:=$(PKG_NAME)
PKGARCH:=all
endef
define Package/$(PKG_NAME)-misc-hotplug/description
This package includes a hotplug script for FreeSWITCH.
endef
define Package/$(PKG_NAME)-misc-hotplug/install
$(INSTALL_DIR) $(1)$(FS_STABLE_SYSCONF_DIR)/hotplug.d/iface
$(INSTALL_BIN) ./files/$(PRG_NAME).hotplug \
$(1)$(FS_STABLE_SYSCONF_DIR)/hotplug.d/iface/99-$(PRG_NAME)
endef
define Package/$(PKG_NAME)-misc-hotplug/postinst
#!/bin/sh
if [ -z "$${IPKG_INSTROOT}" ]; then
echo
echo "o-------------------------------------------------------------------o"
echo "| FreeSWITCH hotplug note |"
echo "o-------------------------------------------------------------------o"
echo "| See /etc/config/freeswitch for hotplug hints. |"
echo "o-------------------------------------------------------------=^_^=-o"
echo
[ -f /etc/hotplug.d/iface/99-freeswitch ] && {
echo "o-------------------------------------------------------------------o"
echo "| WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING |"
echo "o-------------------------------------------------------------------o"
echo "| Please remove freeswitch-stable-misc-hotplug. The hotplug script |"
echo "| is now part of the main freeswitch-stable package. Please run: |"
echo "| |"
echo "| opkg remove freeswitch-stable-misc-hotplug |"
echo "o-------------------------------------------------------------=^_^=-o"
echo
}
fi
exit 0
endef
@ -939,7 +920,6 @@ endef
$(eval $(call BuildPackage,$(PKG_LIBFTDM)))
$(eval $(call BuildPackage,$(PKG_NAME)))
$(eval $(call BuildPackage,$(PKG_NAME)-misc-hotplug))
$(eval $(call BuildPackage,$(PKG_NAME)-misc-perl-esl))
$(eval $(call BuildPackage,$(PKG_NAME)-misc-python-esl))
$(eval $(call BuildPackage,$(PKG_NAME)-misc-timezones))

View file

@ -3,8 +3,9 @@ config freeswitch 'general'
option enabled '0'
option user 'freeswitch'
option group 'freeswitch'
option log_stderr '1'
option log_stdout '1'
option options '-nonat -np'
option change_perm '0'
config freeswitch 'directories'
option cache '/tmp/freeswitch/cache'

View file

@ -1,59 +1,51 @@
#!/bin/sh
FS=freeswitch
LOGGER="/usr/bin/logger -t ${FS}-hotplug"
NAME=freeswitch
COMMAND=/etc/init.d/$NAME
LOGGER="/usr/bin/logger -t $NAME-hotplug"
LOG_ERR="$LOGGER -p user.err --"
LOG_NOTICE="$LOGGER -p user.notice --"
LOG_WARN="$LOGGER -p user.warn --"
[ "$ACTION" = ifup ] || exit 0
. /lib/functions.sh
config_load $FS
config_load $NAME
config_get FS_HOTPLUG_INTERFACE hotplug interface
config_get interface hotplug interface
[ -n "$FS_HOTPLUG_INTERFACE" ] || exit 0
[ "$INTERFACE" = "$interface" ] || exit 0
[ "$INTERFACE" = "$FS_HOTPLUG_INTERFACE" ] || exit 0
pgrep $FS &> /dev/null
pidof $NAME &> /dev/null
if [ $? -eq 0 ]; then
$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
exit 1
else
$LOG_NOTICE $FS stopped
fi
$LOG_NOTICE stopping $NAME
$COMMAND stop &> /dev/null
fi
config_get FS_HOTPLUG_TIMEOUT hotplug timeout
config_get timeout hotplug timeout 60
[ "$FS_HOTPLUG_TIMEOUT" -gt 0 ] 2> /dev/null || unset FS_HOTPLUG_TIMEOUT
TIMEOUT="${FS_HOTPLUG_TIMEOUT:-60}"
[ "$timeout" -gt 0 ] 2> /dev/null || unset timeout
timeout="${timeout:-60}"
config_get FS_HOTPLUG_MOUNTPOINT hotplug mount_point
config_get mount_point hotplug mount_point
# Mount condition, idea lifted from OpenWrt wiki
[ -n "$FS_HOTPLUG_MOUNTPOINT" ] && {
# Mount condition, idea lifted from OpenWrt Wiki
[ -n "$mount_point" ] && {
if ! [ -d "$FS_HOTPLUG_MOUNTPOINT" ]; then
$LOG_ERR "$FS_HOTPLUG_MOUNTPOINT" not a valid mount point
if ! [ -d "$mount_point" ]; then
$LOG_ERR "$mount_point" not a valid mount point
exit 1
fi
mnt="$FS_HOTPLUG_MOUNTPOINT"
mnt="$mount_point"
notReady=start
timeout=$TIMEOUT
tmp_timeout=$timeout
while [ -n "$notReady" -a $timeout -gt 0 ]; do
while [ -n "$notReady" -a $tmp_timeout -gt 0 ]; do
if [ "$notReady" != start ]; then
$LOG_NOTICE "$mnt" not yet mounted, timeout in $timeout s
$LOG_NOTICE "$mnt" not yet mounted, timeout in $tmp_timeout s
sleep 5
timeout=$(($timeout-5))
tmp_timeout=$(($tmp_timeout-5))
fi
notReady=
@ -66,7 +58,7 @@ config_get FS_HOTPLUG_MOUNTPOINT hotplug mount_point
if [ -n "$notReady" ]; then
$LOG_ERR "$mnt" still not mounted
$LOG_ERR not starting $FS
$LOG_ERR not starting $NAME
exit 1
else
$LOG_NOTICE "$mnt" mounted
@ -74,10 +66,10 @@ config_get FS_HOTPLUG_MOUNTPOINT hotplug mount_point
}
config_get_bool FS_HOTPLUG_NTPD hotplug ntpd 0
config_get_bool ntpd hotplug ntpd 0
# ntpd condition
[ $FS_HOTPLUG_NTPD -eq 1 ] && {
[ $ntpd -eq 1 ] && {
type ntpq &> /dev/null
[ $? -eq 0 ] || {
@ -85,19 +77,19 @@ config_get_bool FS_HOTPLUG_NTPD hotplug ntpd 0
exit 1
}
pgrep ntpd &> /dev/null || {
pidof ntpd &> /dev/null || {
$LOG_ERR ntpd not running
exit 1
}
notReady=start
timeout=$TIMEOUT
tmp_timeout=$timeout
while [ -n "$notReady" -a $timeout -gt 0 ]; do
while [ -n "$notReady" -a $tmp_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 $tmp_timeout s
sleep 5
timeout=$(($timeout-5))
tmp_timeout=$(($tmp_timeout-5))
fi
notReady=
@ -105,7 +97,7 @@ config_get_bool FS_HOTPLUG_NTPD hotplug ntpd 0
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_ERR failed to extract stratum from ntpd
notReady="unable to extract stratum"
else
$LOG_NOTICE ntpd stratum $result
@ -113,7 +105,7 @@ config_get_bool FS_HOTPLUG_NTPD hotplug ntpd 0
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_ERR failed to extract offset from ntpd
notReady="unable to extract offset"
else
# "-0" looks stupid, so remove "-"
@ -130,7 +122,7 @@ config_get_bool FS_HOTPLUG_NTPD hotplug ntpd 0
if [ -n "$notReady" ]; then
$LOG_ERR system time still not in sync
$LOG_ERR not starting $FS
$LOG_ERR not starting $NAME
exit 1
else
$LOG_NOTICE system time in sync
@ -138,13 +130,12 @@ config_get_bool FS_HOTPLUG_NTPD hotplug ntpd 0
}
/etc/init.d/$FS start &> /dev/null
# Wait a bit in order for pgrep to be able to find the new process
$COMMAND start &> /dev/null
sleep 1
pgrep $FS &>/dev/null
pidof $NAME &>/dev/null
if [ $? -eq 0 ]; then
$LOG_NOTICE started $FS due to \"ifup "$INTERFACE"\" event
$LOG_NOTICE started $NAME due to \"ifup "$INTERFACE"\" event
else
$LOG_ERR start of $FS due to \"ifup "$INTERFACE"\" event failed
$LOG_ERR start of $NAME due to \"ifup "$INTERFACE"\" event failed
exit 1
fi

View file

@ -7,150 +7,88 @@ USE_PROCD=1
#PROCD_DEBUG=1
FS=freeswitch
LOGGER="/usr/bin/logger -p user.err -s -t $FS"
NAME=freeswitch
COMMAND=/usr/bin/$NAME
# used in both start_service() and stop_service()
fs_dir_run=/var/run/$FS
LOGGER="/usr/bin/logger -p user.err -s -t $NAME"
start_service() {
local change_perm
local dir
local enabled
local fs_user
local fs_group
local user
local group
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
local log_stderr
local log_stdout
local OPTIONS
local dir_cache
local dir_db
local dir_etc=/etc/$NAME
local dir_localstate=/var/lib/$NAME
local dir_log
local dir_recordings
local dir_run=/var/run/$NAME
local dir_storage
local dir_temp
local PROG=/usr/bin/$FS
local options
config_load $FS
config_load $NAME
config_get_bool enabled general enabled 0
if [ $enabled -eq 0 ]; then
$LOGGER service not enabled in /etc/config/$FS
$LOGGER service not enabled in /etc/config/$NAME
exit 1
fi
config_get fs_user general user $FS
config_get fs_group general group $FS
config_get user general user $NAME
config_get group general group $NAME
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
config_get_bool log_stderr general log_stderr 1
config_get_bool log_stdout general log_stdout 1
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"
config_get dir_cache directories cache /tmp/$NAME/cache
config_get dir_db directories db /tmp/$NAME/db
config_get dir_log directories log /tmp/$NAME/log
config_get dir_recordings directories recordings /tmp/$NAME/recordings
config_get dir_storage directories storage /tmp/$NAME/storage
config_get dir_temp directories temp /tmp/$NAME/temp
for dir in "$dir_cache" "$dir_db" "$dir_localstate" \
"$dir_log" "$dir_recordings" "$dir_run" "$dir_storage" \
"$dir_temp"
do
[ -n "$dir" ] && {
[ ! -e "$dir" ] && {
mkdir -p "$dir"
chown "$fs_user":"$fs_group" "$dir"
chown "$user":"$group" "$dir"
chmod 750 "$dir"
}
done
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
config_get options general options
procd_open_instance
# starting with full path seems cleaner judging by 'ps' output
procd_set_param command $PROG
procd_set_param command $COMMAND
# need to specify all or none of -conf, -log, and -db
procd_append_param command \
-cache "$fs_dir_cache" \
-conf "$fs_dir_etc" \
-db "$fs_dir_db" \
-g "$fs_group" \
-log "$fs_dir_log" \
-recordings "$fs_dir_recordings" \
-run "$fs_dir_run" \
-storage "$fs_dir_storage" \
-temp "$fs_dir_temp" \
-u "$fs_user" \
$OPTIONS \
-nc \
-nf
-cache "$dir_cache" \
-conf "$dir_etc" \
-db "$dir_db" \
-g "$group" \
-log "$dir_log" \
-recordings "$dir_recordings" \
-run "$dir_run" \
-storage "$dir_storage" \
-temp "$dir_temp" \
-u "$user" \
$options \
-c
# forward stderr to logd
procd_set_param stderr 1
procd_set_param stderr $log_stderr
# same for stdout
procd_set_param stdout $log_stdout
procd_close_instance
}
stop_service() {
local retval
local mypid
local TIMEOUT=30
local timeout=$TIMEOUT
pgrep $FS &> /dev/null
[ $? -ne 0 ] && exit 0
[ -f "$fs_dir_run"/${FS}.pid ]
retval=$?
# init script could find itself in a scenario where FS was started
# very recently, so make it wait a while for a pid file to appear
while [ $retval -ne 0 -a $timeout -gt 0 ]; do
sleep 1
[ -f "$fs_dir_run"/${FS}.pid ]
retval=$?
timeout=$(($timeout-1))
done
[ $retval -eq 0 ] || {
$LOGGER PID file does not exist
exit 1
}
mypid=$(cat "$fs_dir_run"/${FS}.pid)
[ "$mypid" -gt 1 ] 2> /dev/null || {
$LOGGER PID file contains garbage
exit 1
}
timeout=$TIMEOUT
kill $mypid 2>/dev/null
pgrep $FS | grep -w $mypid &>/dev/null
retval=$?
while [ $retval -eq 0 -a $timeout -gt 0 ]; do
sleep 10
pgrep $FS | grep -w $mypid &>/dev/null
retval=$?
[ $retval -eq 0 ] && kill $mypid 2>/dev/null
timeout=$(($timeout-10))
done
[ $retval -ne 1 ] && {
$LOGGER application seems to hang
$LOGGER sending SIGKILL
kill -SIGKILL $mypid 2>/dev/null
sleep 3
pgrep $FS | grep -w $mypid &>/dev/null
retval=$?
}
[ $retval -ne 1 ] && {
$LOGGER failed to stop $FS
exit 1
}
}

View file

@ -0,0 +1,19 @@
--- a/src/switch_console.c
+++ b/src/switch_console.c
@@ -1053,10 +1053,12 @@ static void *SWITCH_THREAD_FUNC console_
while (running) {
int32_t arg = 0;
- if (getppid() == 1) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "We've become an orphan, no more console for us.\n");
- break;
- }
+ // Parent PID is 1 when started by procd - so FS is not an orphan.
+ // Plus we still want the output.
+ //if (getppid() == 1) {
+ // switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "We've become an orphan, no more console for us.\n");
+ // break;
+ //}
switch_core_session_ctl(SCSC_CHECK_RUNNING, &arg);
if (!arg) {