net/mwan3: remove pid file use pgrep to get pid
If mwan3track will not stop immediately after sending the kill signal, the clean_up handler will delete the pid file later while the new mwan3track is already running. This could result in a situation that mwan3track is running more then once because the old mwan3track service could not be killed, because the pid file is missing. Using pgrep to kill all mwan3track for the tracked interface and not using pid file should fix this issue. Signed-off-by: Florian Eckert <fe@dev.tdt.de>
This commit is contained in:
parent
0ecc08784c
commit
1fd3f85d4f
4 changed files with 14 additions and 29 deletions
|
@ -390,10 +390,7 @@ mwan3_track()
|
|||
}
|
||||
config_list_foreach $1 track_ip mwan3_list_track_ips
|
||||
|
||||
if [ -e /var/run/mwan3track-$1.pid ] ; then
|
||||
kill $(cat /var/run/mwan3track-$1.pid) &> /dev/null
|
||||
fi
|
||||
|
||||
kill $(pgrep -f "mwan3track $1") &> /dev/null
|
||||
if [ -n "$track_ips" ]; then
|
||||
[ -x /usr/sbin/mwan3track ] && /usr/sbin/mwan3track $1 $2 $track_ips &
|
||||
fi
|
||||
|
@ -401,19 +398,14 @@ mwan3_track()
|
|||
|
||||
mwan3_track_signal()
|
||||
{
|
||||
local pid status
|
||||
local pid
|
||||
|
||||
if [ -f "/var/run/mwan3track-${1}.pid" ]; then
|
||||
pid="$(cat "/var/run/mwan3track-${1}.pid")"
|
||||
status="$(pgrep -f mwan3track | grep "${pid}")"
|
||||
if [ "${status}" != "" ]; then
|
||||
pid="$(pgrep -f "mwan3track $1")"
|
||||
if [ "${pid}" != "" ]; then
|
||||
kill -USR1 "${pid}"
|
||||
else
|
||||
$LOG warn "Unable to send signal USR1 to mwan3track on interface $1 with pid ${pid}"
|
||||
fi
|
||||
else
|
||||
$LOG warn "Unable to find \"/var/run/mwan3track-${1}.pid\" file for mwan3track on interface $1"
|
||||
fi
|
||||
}
|
||||
|
||||
mwan3_set_policy()
|
||||
|
|
|
@ -34,17 +34,13 @@ get_mwan3_status() {
|
|||
local iface="${1}"
|
||||
local iface_select="${2}"
|
||||
local running="0"
|
||||
local pid=""
|
||||
local status=""
|
||||
local pid
|
||||
|
||||
if [ "${iface}" = "${iface_select}" ] || [ "${iface_select}" = "" ]; then
|
||||
if [ -f "${MWAN3_PID_FILE}-${iface}.pid" ]; then
|
||||
pid="$(cat "${MWAN3_PID_FILE}-${iface}.pid")"
|
||||
status="$(pgrep -f mwan3track | grep "${pid}")"
|
||||
if [ "${status}" != "" ]; then
|
||||
pid="$(pgrep -f "mwan3track $iface_selected")"
|
||||
if [ "${pid}" != "" ]; then
|
||||
running="1"
|
||||
fi
|
||||
fi
|
||||
|
||||
json_add_object "${iface}"
|
||||
json_add_string "score" "$(cat "$MWAN3_STATUS_DIR/${iface}/SCORE")"
|
||||
|
|
|
@ -42,9 +42,7 @@ ifdown()
|
|||
|
||||
ACTION=ifdown INTERFACE=$1 /sbin/hotplug-call iface
|
||||
|
||||
if [ -e /var/run/mwan3track-$1.pid ] ; then
|
||||
kill $(cat /var/run/mwan3track-$1.pid)
|
||||
fi
|
||||
kill $(pgrep -f "mwan3track $1") &> /dev/null
|
||||
}
|
||||
|
||||
ifup()
|
||||
|
|
|
@ -10,8 +10,9 @@ IFDOWN_EVENT=0
|
|||
|
||||
clean_up() {
|
||||
$LOG notice "Stopping mwan3track for interface \"${INTERFACE}\""
|
||||
rm "/var/run/mwan3track-${INTERFACE}.pid" &> /dev/null
|
||||
if [ "$(pgrep -f "mwan3track ${INTERFACE}")" = "" ]; then
|
||||
rm -rf "/var/run/mwan3track/${INTERFACE}" &> /dev/null
|
||||
fi
|
||||
if [ -z "$(ls -A "/var/run/mwan3track")" ]; then
|
||||
rm -rf "/var/run/mwan3track"
|
||||
fi
|
||||
|
@ -31,7 +32,6 @@ main() {
|
|||
|
||||
INTERFACE=$1
|
||||
DEVICE=$2
|
||||
echo "$$" > /var/run/mwan3track-$1.pid
|
||||
mkdir -p /var/run/mwan3track/$1
|
||||
trap clean_up SIGINT SIGTERM
|
||||
trap if_down SIGUSR1
|
||||
|
@ -103,7 +103,6 @@ main() {
|
|||
if [ $score -eq $up ]; then
|
||||
$LOG notice "Interface $1 ($2) is online"
|
||||
env -i ACTION=ifup INTERFACE=$1 DEVICE=$2 /sbin/hotplug-call iface
|
||||
rm /var/run/mwan3track-$1.pid
|
||||
rm -rf "/var/run/mwan3track/${1}" &> /dev/null
|
||||
exit 0
|
||||
fi
|
||||
|
|
Loading…
Reference in a new issue