1540s, "condition of being a lunatic," formed in English from lunatic + -cy. Originally in reference to intermittent periods of insanity, such as were believed to be triggered by the moon's cycle. The Old English equivalent was monaðseocnes "month-sickness."[lunacy etymology, lunacy origin, 英语词源]
"An automatic fire alarm, burglar alarm, etc.; specifically a ship's alarm which transmits a distress signal by radio when triggered", Late 19th cent.; earliest use found in The Chicago Tribune.