
Chapter 2
As David nears death, he admonishes Solomon to always follow God's way, and the law of Moses, and so insure the throne of Israel is occupied by a descendant of David. Always. Forever.
Then some more instruction: David tells Solomon of the things Joab did that were against David. Tells him to do as he likes with Joab, but not to let the old man just die in peace, not after the things he's done. Also, David tells Solomon about Shimei, who ran along cursing David up and down as he fled from Jerusalem and Absalom. David promised Shimei that he wouldn't harm him. But now he asks Solomon to take care of it.
10 Then David slept with his fathers and was buried in the city of David. [1Ki 2:10 ESV]
After this Adonijah comes to Bathsheba and asks her to get Solomon to give him Abishag, who kept David warm, for his wife. She agrees to do so. When she does, Solomon is so angry that he has Adonijah killed that very day.
Per MSB, possession of the royal harem was a sign of kingship. So Adonijah had asked this to make it look like he was after all, the proper King to succeed David. Abishag as wife would give him a claim to the throne, and possibly be enough to organize a revolt against Solomon. Bathsheba doesn't see the treachery. But when she talks to Solomon, he sees the plan immediately. He considers the very asking of it a violation of the oath of loyalty Adonijah had given to save his life earlier, and pronounces a formal sentence of death on Adonijah.
Then Solomon banishes Abiathar - who had been loyal to Adonijah - fulfilling the curse on the house of Eli (1 Sam 2:30 and following).
Joab hears of all this, and runs to the tent of meeting and grabs hold of the horns of the altar. Apparently a version of sanctuary, because Adonijah had done the very same. So Joab turns out to be a coward, unable to face justice for all his deeds.
Solomon has Benaiah kill Joab right there while he holds onto the altar. God does not protect the guilty. Solomon says Joab must die for killing two men who were better than him - Abner and Amasa. Now that this is done, the blood of those two will be on the house of Joab, no longer on the house of David. So the king is responsible for the acts of his officers.
Then Solomon declared Benaiah over the army, and made Zadok high priest instead of Abiathar.
Last...Shimei is summoned before Solomon. Solomon tells Shimei to build himself a house in Jerusalem, and to never leave for any reason, because if he does, he will die. Shimei agrees. Three years later some of Shimei's servants escape, and he goes to Gath and brings them back. Solomon hears of it, and Shimei is put to death.