Automatic Wpa Supplicant restart

If wifi connection used by your Linux box is not stable and goes up&down, with wpa_supplicant requiring some manual restart you could use a simple script that does it for you. Below you can find a script i'm using on a RaspberryPi 3 with Raspian installed.
#!/bin/sh

WLAN=wlan0

DEAD=$(service wpa_supplicant status 2>/dev/null | grep -i dead)
YESIP=$( ip addr show $WLAN | grep "inet\b" | awk '{print $2}' | cut -d/ -f1 )
CMD=$( ps -eo args | grep wpa_suppl | grep -v grep )

if [ "$YESIP" == "" ]; then 
    DEAD="DEAD"
else 
    ping 8.8.8.8 -c 5 >/dev/null 2>/dev/null 
    if [ "$?" != "0" ]; then 
        DEAD="DEAD" 
    else 
        DEAD="" 
    fi
fi

if [ "$DEAD" != "" ]; then 
    pkill -9 wpa_supplicant 
    $CMD &
fi
Remember to use a value for WLAN corresponding to you wifi interface.
The shell script alone doesn't give you a fully automatic and periodic check&restart ... to have it you should use crontab and schedule script invocation (user: root!) every 15 minutes (or every time you need it).