freeswitch: rework init & hotplug

This adds a term_timeout uci option which can be used to change the
default timeout that procd uses while waiting for freeswitch to exit
once the TERM signal is sent. freeswitch may take a bit longer to exit,
so adding this option is likely appreciated. By default procd's default
is used, though.

Logging is updated in init script and hotplug script. The used facility
is changed from user to daemon, for instance.

An issue was fixed in the parsing of the ntpq output. In case a positive
offset was printed the parsing failed. Apparently ntpq is now adding a
'+', so this is now accounted for.

Signed-off-by: Sebastian Kemper <sebastian_ml@gmx.net>
This commit is contained in:
Sebastian Kemper 2021-03-26 22:22:18 +01:00
parent a34590f057
commit 601188d0ff
3 changed files with 33 additions and 17 deletions

View File

@ -4,6 +4,7 @@ config freeswitch 'general'
option log_stderr '1' option log_stderr '1'
option log_stdout '1' option log_stdout '1'
option options '-nonat -np' option options '-nonat -np'
#option term_timeout '10' # seconds to wait after sending TERM signal
config freeswitch 'directories' config freeswitch 'directories'
option cache '/tmp/freeswitch/cache' option cache '/tmp/freeswitch/cache'

View File

@ -4,8 +4,9 @@ NAME=freeswitch
COMMAND=/etc/init.d/$NAME COMMAND=/etc/init.d/$NAME
LOGGER="/usr/bin/logger -t $NAME-hotplug" LOGGER="/usr/bin/logger -t $NAME-hotplug"
LOG_ERR="$LOGGER -p user.err --" LOG_ERR="$LOGGER -p daemon.err --"
LOG_NOTICE="$LOGGER -p user.notice --" LOG_INFO="$LOGGER -p daemon.info --"
LOG_WARN="$LOGGER -p daemon.warn --"
[ "$ACTION" = ifup ] || exit 0 [ "$ACTION" = ifup ] || exit 0
@ -18,7 +19,7 @@ config_get interface hotplug interface
pidof $NAME &> /dev/null pidof $NAME &> /dev/null
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
$LOG_NOTICE stopping $NAME $LOG_INFO stopping $NAME
$COMMAND stop &> /dev/null $COMMAND stop &> /dev/null
fi fi
@ -43,7 +44,7 @@ config_get mount_point hotplug mount_point
while [ -n "$notReady" -a $tmp_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 $tmp_timeout s $LOG_INFO "$mnt" not yet mounted, timeout in $tmp_timeout s
sleep 5 sleep 5
tmp_timeout=$(($tmp_timeout-5)) tmp_timeout=$(($tmp_timeout-5))
fi fi
@ -61,7 +62,7 @@ config_get mount_point hotplug mount_point
$LOG_ERR not starting $NAME $LOG_ERR not starting $NAME
exit 1 exit 1
else else
$LOG_NOTICE "$mnt" mounted $LOG_INFO "$mnt" mounted
fi fi
} }
@ -87,7 +88,7 @@ config_get_bool ntpd hotplug ntpd 0
while [ -n "$notReady" -a $tmp_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 $tmp_timeout s $LOG_INFO system time not in sync yet, timeout in $tmp_timeout s
sleep 5 sleep 5
tmp_timeout=$(($tmp_timeout-5)) tmp_timeout=$(($tmp_timeout-5))
fi fi
@ -97,20 +98,20 @@ config_get_bool 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_ERR failed to extract stratum from ntpd $LOG_WARN failed to extract stratum from ntpd
notReady="unable to extract stratum" notReady="unable to extract stratum"
else else
$LOG_NOTICE ntpd stratum $result $LOG_INFO ntpd stratum $result
if [ $result -lt 16 ] 2> /dev/null; then if [ $result -lt 16 ] 2> /dev/null; then
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_ERR failed to extract offset from ntpd $LOG_WARN 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 "-"
result=$(echo $result | grep -o '[0-9]*') result=$(echo $result | grep -o '[0-9]*')
$LOG_NOTICE ntpd to system time offset \+\/\- $result ms $LOG_INFO ntpd to system time offset \+\/\- $result ms
# If offset < 100 ms consider system time in sync # If offset < 100 ms consider system time in sync
[ $result -lt 100 ] || notReady="system time not in sync yet" [ $result -lt 100 ] || notReady="system time not in sync yet"
fi fi
@ -125,7 +126,7 @@ config_get_bool ntpd hotplug ntpd 0
$LOG_ERR not starting $NAME $LOG_ERR not starting $NAME
exit 1 exit 1
else else
$LOG_NOTICE system time in sync $LOG_INFO system time in sync
fi fi
} }
@ -134,7 +135,7 @@ $COMMAND start &> /dev/null
sleep 1 sleep 1
pidof $NAME &>/dev/null pidof $NAME &>/dev/null
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
$LOG_NOTICE started $NAME due to \"ifup "$INTERFACE"\" event $LOG_INFO started $NAME due to \"ifup "$INTERFACE"\" event
else else
$LOG_ERR start of $NAME due to \"ifup "$INTERFACE"\" event failed $LOG_ERR start of $NAME due to \"ifup "$INTERFACE"\" event failed
exit 1 exit 1

View File

@ -10,7 +10,10 @@ USE_PROCD=1
NAME=freeswitch NAME=freeswitch
COMMAND=/usr/bin/$NAME COMMAND=/usr/bin/$NAME
LOGGER="/usr/bin/logger -p user.err -s -t $NAME --" LOGGER="/usr/bin/logger -s -t $NAME"
LOG_ERR="$LOGGER -p daemon.err --"
LOG_WARN="$LOGGER -p daemon.warn --"
LOG_INFO="$LOGGER -p daemon.info --"
start_service() { start_service() {
dir_etc=/etc/$NAME dir_etc=/etc/$NAME
@ -21,7 +24,7 @@ start_service() {
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/$NAME $LOG_ERR service not enabled in /etc/config/$NAME
exit 1 exit 1
fi fi
@ -37,6 +40,14 @@ start_service() {
config_get options general options config_get options general options
config_get term_timeout general term_timeout default
if [ default = "$term_timeout" ]; then
$LOG_INFO using procd\'s default term_timeout
elif ! [ 0 -lt "$term_timeout" ] 2>/dev/null; then
$LOG_ERR invalid term_timeout in /etc/config/$NAME
exit 1
fi
for i in "$dir_localstate" "$dir_run"; do for i in "$dir_localstate" "$dir_run"; do
if ! [ -e "$i" ]; then if ! [ -e "$i" ]; then
mkdir -m 0750 -p "$i" mkdir -m 0750 -p "$i"
@ -47,8 +58,8 @@ start_service() {
command -v su >/dev/null command -v su >/dev/null
ret=$? ret=$?
if [ 0 != "$ret" ]; then if [ 0 != "$ret" ]; then
$LOGGER utility \"su\" not available $LOG_WARN utility \"su\" not available
$LOGGER will not attempt to create directories $LOG_WARN will not attempt to create directories
else else
for i in "$dir_cache" \ for i in "$dir_cache" \
"$dir_db" \ "$dir_db" \
@ -84,5 +95,8 @@ start_service() {
procd_set_param stderr $log_stderr procd_set_param stderr $log_stderr
# same for stdout # same for stdout
procd_set_param stdout $log_stdout procd_set_param stdout $log_stdout
if ! [ default = "$term_timeout" ]; then
procd_set_param term_timeout "$term_timeout"
fi
procd_close_instance procd_close_instance
} }