Section 27A. Except as hereinafter provided, no person shall shut off, disconnect, obstruct, remove or destroy, or cause or permit to be shut off, disconnected, obstructed, removed or destroyed, any part of any sprinkler system, water main, hydrant or other device used for fire protection or carbon monoxide detection and alarm in any building owned, leased or occupied by such person or under his control or supervision, without first procuring a written permit so to do from the head of the fire department of the city or town wherein such building is situated, which permit such head is hereby authorized to issue subject to such terms and conditions as, in his judgment, protection against fire and the preservation of the public safety may require. This section shall not prevent the temporary shutting off or disconnection or partial removal of such a system, main, hydrant or other device for the purpose of making necessary repairs or preventing freezing or other property damage; provided, however, that the head of the fire department is notified immediately of such emergency action. The head of the fire department shall also be notified when the system, main, hydrant or other device is placed back in service. Violation of this section shall be punished by imprisonment for not more than one year or by a fine of not more than one thousand dollars, or both. The supreme judicial and superior courts shall have jurisdiction in equity to enforce compliance with the provisions of this section.