In the classic civil-military relations literature, the focus is on coups and how to prevent them. Later generations of literature focused more on how democracies control their militaries and then how to get the civilians to work with the military on the ground in places like Afghanistan--whole of government.
Anyhow, this vox piece suggests that Iraqi Prime Minister Maliki replaced Sunni commanders of Iraqi army units with Shia commanders precisely because he was concerned about the potential of coups. That makes complete sense--using ethnic ties to build loyalties is a normal strategy for preventing coups. However, it also may make the military less effective. Indeed, recent work has demonstrated that coup prevention efforts can be decent to good at preventing coups, but raise the risk of civil war.
The question, then, for leaders of regimes of somewhat dubious stability is which poison to pick--the risk of a coup or a risk of a civil war? For the country, it is almost always better to risk a coup than a civil war since coups are often not so violent (it depends on who is willing to shoot, and faits accompli often mean no shooting at all) AND civil wars are often accompanied not just by collateral damage but mass killings.
However, since we almost always assume self-centered leaders who worry mostly/entirely about their own political positions, the question is: should the leader worry about coup or civil war? In many cases, coups should be the biggest concern, but in a country that has already faced a civil war (that never really stopped), perhaps the civil war concern should have occupied more of Maliki's attention/decision calculus.
Events are proving that