diff options
Diffstat (limited to 'net/freeswitch-stable/files/freeswitch.hotplug')
| -rw-r--r-- | net/freeswitch-stable/files/freeswitch.hotplug | 94 |
1 files changed, 44 insertions, 50 deletions
diff --git a/net/freeswitch-stable/files/freeswitch.hotplug b/net/freeswitch-stable/files/freeswitch.hotplug index 4a6a2c1..68fc3b0 100644 --- a/net/freeswitch-stable/files/freeswitch.hotplug +++ b/net/freeswitch-stable/files/freeswitch.hotplug @@ -1,53 +1,51 @@ #!/bin/sh -FS=freeswitch -DEFAULT=/etc/default/$FS -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 -[ -f $DEFAULT ] && . $DEFAULT +. /lib/functions.sh +config_load $NAME -[ -n "$FS_HOTPLUG_INTERFACE" ] || exit 0 +config_get interface hotplug interface -[ "$INTERFACE" = "$FS_HOTPLUG_INTERFACE" ] || exit 0 +[ "$INTERFACE" = "$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 -[ "$FS_HOTPLUG_TIMEOUT" -gt 0 ] 2> /dev/null || unset FS_HOTPLUG_TIMEOUT -TIMEOUT="${FS_HOTPLUG_TIMEOUT:-60}" +config_get timeout hotplug timeout 60 + +[ "$timeout" -gt 0 ] 2> /dev/null || unset timeout +timeout="${timeout:-60}" -# Mount condition, idea lifted from OpenWrt wiki -[ -n "$FS_HOTPLUG_MOUNTPOINT" ] && { +config_get mount_point hotplug mount_point - if ! [ -d "$FS_HOTPLUG_MOUNTPOINT" ]; then - $LOG_ERR "$FS_HOTPLUG_MOUNTPOINT" not a valid mount point +# Mount condition, idea lifted from OpenWrt Wiki +[ -n "$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= @@ -60,7 +58,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 $NAME exit 1 else $LOG_NOTICE "$mnt" mounted @@ -68,8 +66,10 @@ TIMEOUT="${FS_HOTPLUG_TIMEOUT:-60}" } +config_get_bool ntpd hotplug ntpd 0 + # ntpd condition -[ -n "$FS_HOTPLUG_NTPD" ] && { +[ $ntpd -eq 1 ] && { type ntpq &> /dev/null [ $? -eq 0 ] || { @@ -77,24 +77,19 @@ TIMEOUT="${FS_HOTPLUG_TIMEOUT:-60}" exit 1 } - pgrep ntpd &> /dev/null || { + pidof ntpd &> /dev/null || { $LOG_ERR ntpd not running exit 1 } 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 - } + 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= @@ -102,7 +97,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_ERR failed to extract stratum from ntpd notReady="unable to extract stratum" else $LOG_NOTICE ntpd stratum $result @@ -110,7 +105,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_ERR failed to extract offset from ntpd notReady="unable to extract offset" else # "-0" looks stupid, so remove "-" @@ -126,22 +121,21 @@ 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 $NAME exit 1 else - $LOG_NOTICE System time in sync + $LOG_NOTICE system time in sync fi } -/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 |
