freeswitch-stable: cleanup hotplug script
- clean up variable names - replace pgrep with pidof - remove LOG_WARN and use LOG_ERR instead Signed-off-by: Sebastian Kemper <sebastian_ml@gmx.net>
This commit is contained in:
parent
0e4d42b262
commit
92bdfa634d
1 changed files with 38 additions and 40 deletions
|
@ -1,52 +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
|
||||||
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=
|
||||||
|
@ -59,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
|
||||||
|
@ -67,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 ] || {
|
||||||
|
@ -78,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=
|
||||||
|
@ -98,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
|
||||||
|
@ -106,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 "-"
|
||||||
|
@ -123,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
|
||||||
|
@ -131,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
|
||||||
|
|
Loading…
Reference in a new issue