A lot of people talk about duty in Treasure Island, especially that upstanding representative of English order, Captain Smollett. Obviously, the pirates have a flexible notion of duty, what with the fundamental pirate value being "get rich quick." More interesting is the way that slightly less high-minded good guys like Doctor Livesey and Jim approach duty. They seem to have a situational notion of what duty entails: they stay loyal to their friends but don't necessarily feel bound to follow specific orders. Ultimately Jim helps everyone by being a deserter, and Doctor Livesey saves the life of a murderer, Long John Silver. We think Captain Smollett would not approve, but this practical approach to duty helps the good guys survive in the novel.
By representing Squire Trelawney's three servants as loyal even at the expense of their own lives, Treasure Island suggests that the ideal servant is willing to sacrifice everything for his master.
Even though Captain Smollett, Squire Trelawney, Doctor Livesey, and Jim Hawkins hold different ideals about duty, they all resolve that the end justifies the means by the novel's conclusion.