chiark / gitweb /
From Peter Maydell (/u2/pmaydell/iwjbackup/) as per <E156bwm-0005xq-00@watchdragon...
[chiark-utils.git] / backup / takedown
1 #!/bin/sh
2 #
3 # Take the system down for backups and then bring it back up.
4 # Expects a single (possibly empty) argument X which is used to select
5 # a file /etc/backup/warnings.X. This file will contain lines like:
6 # T 300 "in 10 minutes"
7 # T 240 "in 5 minutes"
8 # T 45 "in 1 minute"
9 # T 15 "in 15 seconds"
10 # configuring the frequency of warning messages. If you call the 
11 # files 'warnings.soon', 'warnings.now' and 'warnings.' then
12 # you can invoke this as:
13 #   takedown                     lots of warnings
14 #   takedown soon                not so many warnings
15 #   takedown now                 no warning at all
16
17 set -e
18 cd /etc/backup
19
20 host="`hostname`" || true
21
22 T () {
23         (
24                 exec wall <<END &
25  *** WARNING - SYSTEM GOING DOWN FOR BACKUPS ***
26  $host will shut down automatically $2.
27
28 END
29         ) &
30         sleep $1
31 }
32
33 . "warnings.$1"
34
35 (
36         exec wall <<END &
37  *** WARNING - SYSTEM GOING DOWN FOR BACKUPS ***
38
39   $host is shutting down IMMEDIATELY.
40
41 END
42 ) &
43 sleep 1
44
45 # We assume that runlevel 5 is set up suitably for doing backups
46 # (ie non-essential services turned off in an effort to get the
47 # tape to stream.)
48 telinit 5