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 PRG_NAME:=freeswitch
PKG_NAME:=$(PRG_NAME)-stable PKG_NAME:=$(PRG_NAME)-stable
PKG_VERSION:=1.8.2 PKG_VERSION:=1.8.2
PKG_RELEASE:=1 PKG_RELEASE:=2
PKG_MAINTAINER:=Sebastian Kemper <sebastian_ml@gmx.net> PKG_MAINTAINER:=Sebastian Kemper <sebastian_ml@gmx.net>
PKG_SOURCE:=$(PRG_NAME)-$(PKG_VERSION).tar.xz 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_SCRIPTS_DIR)
$(INSTALL_DIR) $(1)$(FS_STABLE_SOUNDS_DIR) $(INSTALL_DIR) $(1)$(FS_STABLE_SOUNDS_DIR)
$(INSTALL_DIR) $(1)$(FS_STABLE_SYSCONF_DIR)/config $(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_SYSCONF_DIR)/init.d
$(INSTALL_DIR) $(1)$(FS_STABLE_TLS_DIR) $(INSTALL_DIR) $(1)$(FS_STABLE_TLS_DIR)
$(INSTALL_BIN) ./files/$(PRG_NAME).init \ $(INSTALL_BIN) ./files/$(PRG_NAME).init \
$(1)$(FS_STABLE_SYSCONF_DIR)/init.d/$(PRG_NAME) $(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 \ $(INSTALL_CONF) ./files/$(PRG_NAME).config \
$(1)$(FS_STABLE_SYSCONF_DIR)/config/$(PRG_NAME) $(1)$(FS_STABLE_SYSCONF_DIR)/config/$(PRG_NAME)
endef endef
@ -425,49 +428,27 @@ endef
define Package/$(PKG_NAME)/postinst define Package/$(PKG_NAME)/postinst
#!/bin/sh #!/bin/sh
if [ -z "$${IPKG_INSTROOT}" ]; then 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
echo "o-------------------------------------------------------------------o" echo "o-------------------------------------------------------------------o"
echo "| FreeSWITCH note |" echo "| FreeSWITCH note |"
echo "o-------------------------------------------------------------------o" echo "o-------------------------------------------------------------------o"
echo "| Edit /etc/config/freeswitch to change basic init configuration. |" 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 "o-------------------------------------------------------------=^_^=-o"
echo echo
fi [ -f /etc/hotplug.d/iface/99-freeswitch ] && {
exit 0 echo "o-------------------------------------------------------------------o"
endef echo "| WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING |"
echo "o-------------------------------------------------------------------o"
define Package/$(PKG_NAME)-misc-hotplug echo "| Please remove freeswitch-stable-misc-hotplug. The hotplug script |"
$(call Package/$(PKG_NAME)/Default) echo "| is now part of the main freeswitch-stable package. Please run: |"
TITLE:=Hotplug script echo "| |"
DEPENDS:=$(PKG_NAME) echo "| opkg remove freeswitch-stable-misc-hotplug |"
PKGARCH:=all echo "o-------------------------------------------------------------=^_^=-o"
endef echo
}
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
fi fi
exit 0 exit 0
endef endef
@ -939,7 +920,6 @@ endef
$(eval $(call BuildPackage,$(PKG_LIBFTDM))) $(eval $(call BuildPackage,$(PKG_LIBFTDM)))
$(eval $(call BuildPackage,$(PKG_NAME))) $(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-perl-esl))
$(eval $(call BuildPackage,$(PKG_NAME)-misc-python-esl)) $(eval $(call BuildPackage,$(PKG_NAME)-misc-python-esl))
$(eval $(call BuildPackage,$(PKG_NAME)-misc-timezones)) $(eval $(call BuildPackage,$(PKG_NAME)-misc-timezones))

View file

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

View file

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

View file

@ -7,150 +7,88 @@ USE_PROCD=1
#PROCD_DEBUG=1 #PROCD_DEBUG=1
FS=freeswitch NAME=freeswitch
LOGGER="/usr/bin/logger -p user.err -s -t $FS" COMMAND=/usr/bin/$NAME
# used in both start_service() and stop_service() LOGGER="/usr/bin/logger -p user.err -s -t $NAME"
fs_dir_run=/var/run/$FS
start_service() { start_service() {
local change_perm
local dir local dir
local enabled local enabled
local fs_user local user
local fs_group local group
local fs_dir_cache local log_stderr
local fs_dir_db local log_stdout
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 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 config_get_bool enabled general enabled 0
if [ $enabled -eq 0 ]; then if [ $enabled -eq 0 ]; then
$LOGGER service not enabled in /etc/config/$FS $LOGGER service not enabled in /etc/config/$NAME
exit 1 exit 1
fi fi
config_get fs_user general user $FS config_get user general user $NAME
config_get fs_group general group $FS config_get group general group $NAME
config_get fs_dir_cache directories cache /tmp/$FS/cache config_get_bool log_stderr general log_stderr 1
config_get fs_dir_db directories db /tmp/$FS/db config_get_bool log_stdout general log_stdout 1
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" \ config_get dir_cache directories cache /tmp/$NAME/cache
"$fs_dir_log" "$fs_dir_recordings" "$fs_dir_run" "$fs_dir_storage" \ config_get dir_db directories db /tmp/$NAME/db
"$fs_dir_temp" 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 do
[ -n "$dir" ] && { [ ! -e "$dir" ] && {
mkdir -p "$dir" mkdir -p "$dir"
chown "$fs_user":"$fs_group" "$dir" chown "$user":"$group" "$dir"
chmod 750 "$dir" chmod 750 "$dir"
} }
done done
config_get_bool change_perm general change_perm 0 config_get options general options
[ $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 procd_open_instance
# starting with full path seems cleaner judging by 'ps' output # 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 # need to specify all or none of -conf, -log, and -db
procd_append_param command \ procd_append_param command \
-cache "$fs_dir_cache" \ -cache "$dir_cache" \
-conf "$fs_dir_etc" \ -conf "$dir_etc" \
-db "$fs_dir_db" \ -db "$dir_db" \
-g "$fs_group" \ -g "$group" \
-log "$fs_dir_log" \ -log "$dir_log" \
-recordings "$fs_dir_recordings" \ -recordings "$dir_recordings" \
-run "$fs_dir_run" \ -run "$dir_run" \
-storage "$fs_dir_storage" \ -storage "$dir_storage" \
-temp "$fs_dir_temp" \ -temp "$dir_temp" \
-u "$fs_user" \ -u "$user" \
$OPTIONS \ $options \
-nc \ -c
-nf
# forward stderr to logd # 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 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) {