Use application:stop(cowboy) instead of cowboy:stop().