chiark / gitweb /
warnings.now files should exist and be empty
[chiark-utils.git] / backup / takedown
1 #!/bin/sh
2 # takedown
3 # Entry point for cron to take the system down for backups
4 #
5 # This file is part of chiark backup, a system for backing up GNU/Linux and
6 # other UN*X-compatible machines, as used on chiark.greenend.org.uk.
7 #
8 # chiark backup is:
9 #  Copyright (C) 1997-1998,2000-2001 Ian Jackson <ian@chiark.greenend.org.uk>
10 #  Copyright (C) 1999 Peter Maydell <pmaydell@chiark.greenend.org.uk>
11 #
12 # This is free software; you can redistribute it and/or modify it under the
13 # terms of the GNU General Public License as published by the Free Software
14 # Foundation; either version 2, or (at your option) any later version.
15 #
16 # This is distributed in the hope that it will be useful, but WITHOUT ANY
17 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 # FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
19 # details.
20 #
21 # You should have received a copy of the GNU General Public License along
22 # with this program; if not, write to the Free Software Foundation, Inc.,
23 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
25 # Expects a single (possibly empty) argument X which is used to select
26 # a file /etc/chiark-backup/warnings.X. This file will contain lines like:
27 # T 300 "in 10 minutes"
28 # T 240 "in 5 minutes"
29 # T 45 "in 1 minute"
30 # T 15 "in 15 seconds"
31 # configuring the frequency of warning messages. If you call the 
32 # files 'warnings.soon', 'warnings.now' and 'warnings.' then
33 # you can invoke this as:
34 #   takedown                     lots of warnings
35 #   takedown soon                not so many warnings
36 #   takedown now                 no warning at all
37
38 set -e
39 cd /etc/chiark-backup
40
41 host="`hostname`" || true
42
43 T () {
44         (
45                 exec wall <<END &
46  *** WARNING - SYSTEM GOING DOWN FOR BACKUPS ***
47  $host will shut down automatically $2.
48
49 END
50         ) &
51         sleep $1
52 }
53
54 . "warnings.$1"
55
56 (
57         exec wall <<END &
58  *** WARNING - SYSTEM GOING DOWN FOR BACKUPS ***
59
60   $host is shutting down IMMEDIATELY.
61
62 END
63 ) &
64 sleep 1
65
66 # We assume that runlevel 5 is set up suitably for doing backups
67 # (ie non-essential services turned off in an effort to get the
68 # tape to stream.)
69 telinit 5