The phrase originated in 1800, in regards to tribute (ransom) requests from Barbary pirates.It is by Charles Cotesworth Pinckney.
Charles Cotesworth “C. C.” Pinckney (February 25, 1746 – August 16, 1825), was an early American statesman of South Carolina, Revolutionary War veteran, and delegate to the Constitutional Convention. He was twice nominated by the Federalist Party as their presidential candidate
The Barbary pirates were raiding American vessels and holding Americans for ransom..... The US Marines put a stop to it.... in the Marine hymn that is what is referred to by the line...."Shores of Tripoli"
In this case the quote was in support of military action