A new method to determine stability of bacterial ecosystems