The Talmud brings a Mishnah teaching that men who left their Sabbath boundary (techum) to rescue someone are allowed to return to their place. The Gemara notes that they were allowed to bring their weapons back home as well, even after the danger ended. This is a source for a modern allowance for EMTs and ambulance drivers to return home after they take someone to the hospital on Shabbat.
The Gemara explains the parameters of defensive war on Shabbat: if non Jews besieged the town for mere extortion or thievery, the Jews may not go out to fight against them with weapons, nor may they desecrate Shabbat in any other way due to them, but rather they must wait until after Shabbat. However, if there is concern that the gentiles will attack and harm people, the Jews may go out against them with their weapons, and they may desecrate Shabbat due to them. But regarding a town that is located near the border, even if the gentiles did not come threatening lives, but even to steal hay and straw, Jews may go out against them with their weapons, and they may desecrate Shabbat due to them.
The Gemara mentions this was the rule not only in Israel itself but even in Bavel, where Jews were a minority and had limited self rule. It is important to note that for practically all of human history it was normal and expected, and often required, for men to be armed to defend their families and cities. Today’s (fairly) safe situation in western nations is a historical anomaly and should not be expected to be permanent.
The deeper wisdom here is that a man needs to be ready to enforce his borders, his boundaries. The danger of allowing other people to walk over you cannot be understated. If you give an inch, they will take a mile. However, you need to be aware of what your borders are so you know what it vital to defend. Some boundaries are hard and some are softer. Some may be merely preferences but not impact your life and mission. You can’t react aggressively to everything that might offend you, you would look very insecure. Decide what is vital to your own well being and do not compromise those items.
The Gemara brings an illustration of the rules of war on Shabbat:
Rabbi Dostai of Biri expounded: What is the meaning of that which is written: “And they told David, saying: Behold, the Philistines are fighting against Ke’ila, and robbing the threshing floors” (I Samuel 23:1). It was taught: Ke’ila was a town located near the border, and the Philistines came only with regard to matters of hay and straw, as it is written: “And they rob the threshing floors.” And in the next verse it is written: “Therefore David inquired of the Lord, saying: Shall I go and smite these Philistines? And the Lord said to David: Go and smite the Philistines, and save Ke’ila” (I Samuel 23:2), which indicates that war may be waged in a border town on Shabbat, even with regard to monetary matters. The Gemara refutes this proof by asking: What is David’s dilemma? If you say that he had a legal question and was in doubt whether it was permitted or prohibited to fight the Philistines on Shabbat, the court of Samuel from Rama was then in existence, and rather than inquire by way of the Urim VeTummim he should have inquired of the Great Sanhedrin. Rather, he asked God: Will he succeed or will he not succeed in his war?
Even though it was only a financial loss, since Keilit was a border city, it was necessary to go to war to drive off the philistines. We see from here that the bumper sticker wisdom “war is not the answer” is correct, but for the wrong reason. War is not the answer. It is the question. The answer is that sometimes war is absolutely necessary to protect your values, your family, your tribe. This is also the relevant inquiry for a man enforcing his boundaries in life. You must first decide what your key values are and where your boundaries lie.