trap TERM/INT and save snapshot on shutdown