If the thermostat is running wild (will not shut off) the oil will overheat causing the hi-limit to trip out and shut everything off. By resetting the hi-limit and relighting the pilot and it stays lit, then you know the thermostat is not good. To replace the thermostat follow the same instructions for replacing the hi-limit.
Commercial Fryer Buying Guide