Whenever the existence of a nuisance is shown in an action brought under this article to the satisfaction of the court or judge thereof, either by verified complaint or affidavit, and the court or judge is satisfied that the owner of the property has received written notice of the existence of the nuisance, signed by the complainant or the district attorney at least two weeks prior to the filing of the complaint, the court or judge shall allow a temporary writ of injunction to abate and prevent the continuance or recurrence of the nuisance. On granting such writ the court or judge shall require an undertaking on the part of the applicant to the effect that the applicant will pay to the party enjoined such damages, not exceeding an amount to be specified, as the opposing party may sustain by reason of the injunction, if the court finally decides that the applicant was not entitled to the injunction.