diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2013-03-21 13:34:51 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2013-03-21 13:34:51 +0200 |
commit | 6c6ab3125da430bdaafb9bacc88c32279a961525 (patch) | |
tree | ef8f4005504a8545eaab5b111890649ba0302d2c | |
parent | 194f4b1204d6e49ba0af7dd761f8c794ba37c035 (diff) | |
download | beam-6c6ab3125da430bdaafb9bacc88c32279a961525.tar.gz beam-6c6ab3125da430bdaafb9bacc88c32279a961525.tar.bz2 |
Prevent reentrant invocations. Minor bugfix.
At startup a pid file is checked. If it exists, another beam
process is assumed to be running and start up is aborted. Otherwise
a new pid file is created. The existing pid is removed before
exiting (by epilogue_hook).
* backup.in (prologue_hook): Prepend beam_lock.
* lib/beam/common.in (backup_pidfile): New global.
(beam_lock,beam_unlock): New functions.
* lib/beam/s3.sh (s3_getmpoint): Fix regexp to take
into account s3backer invocation without --vhost.
-rw-r--r-- | backup.in | 1 | ||||
-rw-r--r-- | lib/beam/common.in | 17 | ||||
-rw-r--r-- | lib/beam/s3.sh | 12 |
3 files changed, 26 insertions, 4 deletions
@@ -122,6 +122,7 @@ backup() { | |||
122 | } | 122 | } |
123 | 123 | ||
124 | umask ${backup_umask:-077} | 124 | umask ${backup_umask:-077} |
125 | prologue_hook="beam_lock $prologue_hook" | ||
125 | 126 | ||
126 | if [ -n "$backup_logfile" ]; then | 127 | if [ -n "$backup_logfile" ]; then |
127 | runhook openlog_hook | 128 | runhook openlog_hook |
diff --git a/lib/beam/common.in b/lib/beam/common.in index 1be075e..7e69640 100644 --- a/lib/beam/common.in +++ b/lib/beam/common.in | |||
@@ -30,6 +30,7 @@ backup_archive_dir= | |||
30 | backup_snapshot_dir= | 30 | backup_snapshot_dir= |
31 | backup_verbose= | 31 | backup_verbose= |
32 | backup_logfile="/var/log/backup" | 32 | backup_logfile="/var/log/backup" |
33 | backup_pidfile="/var/run/beam.pid" | ||
33 | backup_tmp_dir=/tmp | 34 | backup_tmp_dir=/tmp |
34 | 35 | ||
35 | error() { | 36 | error() { |
@@ -47,6 +48,22 @@ abend() { | |||
47 | exit $ec | 48 | exit $ec |
48 | } | 49 | } |
49 | 50 | ||
51 | beam_lock() { | ||
52 | if [ -r $backup_pidfile ]; then | ||
53 | pid=$(head -n 1 $backup_pidfile) | ||
54 | if [ -z "$pid" ]; then | ||
55 | abend "pidfile $backup_pidfile exists but is unreadable or empty" | ||
56 | fi | ||
57 | abend "another beam process (pid $backup_pid) is still running; exiting" | ||
58 | fi | ||
59 | echo $$ > $backup_pidfile || exit 1 | ||
60 | epilogue_hook="$epilogue_hook beam_unlock" | ||
61 | } | ||
62 | |||
63 | beam_unlock() { | ||
64 | rm -f $backup_pidfile | ||
65 | } | ||
66 | |||
50 | tarcode() { | 67 | tarcode() { |
51 | case $1 in | 68 | case $1 in |
52 | 0) logit "success";; | 69 | 0) logit "success";; |
diff --git a/lib/beam/s3.sh b/lib/beam/s3.sh index de71456..d2fcfe6 100644 --- a/lib/beam/s3.sh +++ b/lib/beam/s3.sh | |||
@@ -26,9 +26,16 @@ test -z "$backup_mp" && backup_mp_s3=/mnt/s3 | |||
26 | s3_getmpoint() | 26 | s3_getmpoint() |
27 | { | 27 | { |
28 | case $1 in | 28 | case $1 in |
29 | # Sample mount output, split into several lines: | ||
30 | # a) With --vhost: | ||
31 | # http://BUCKETNAME.s3.amazonaws.com/ on /mnt/s3backer type fuse.s3backer | ||
32 | # (rw,nosuid,nodev,allow_other,default_permissions) | ||
33 | # b) Without --vhost: | ||
34 | # http://s3.amazonaws.com/BUCKETNAME/ on /mnt/s3backer type fuse.s3backer | ||
35 | # (rw,nosuid,nodev,allow_other,default_permissions) | ||
29 | backer) | 36 | backer) |
30 | mount -tfuse.s3backer | | 37 | mount -tfuse.s3backer | |
31 | awk '/https?:\/\/'$backup_bucket_name'/ { print $3 }';; | 38 | awk '/https?:\/\/.*'$backup_bucket_name'/ { print $3 }';; |
32 | s3) | 39 | s3) |
33 | s=$(mount | grep "^${backup_mp_s3backer}/file" | awk '{ print $3 }') | 40 | s=$(mount | grep "^${backup_mp_s3backer}/file" | awk '{ print $3 }') |
34 | if [ -z "$s" ]; then | 41 | if [ -z "$s" ]; then |
@@ -50,9 +57,6 @@ s3_mount() { | |||
50 | test -d $backup_mp_s3backer || mkdir $backup_mp_s3backer | 57 | test -d $backup_mp_s3backer || mkdir $backup_mp_s3backer |
51 | test -d $backup_mp_s3 || mkdir $backup_mp_s3 | 58 | test -d $backup_mp_s3 || mkdir $backup_mp_s3 |
52 | 59 | ||
53 | # Sample mount output, split into several lines: | ||
54 | # http://finox-backup-fs.s3.amazonaws.com/ on /mnt/s3backer type fuse.s3backer | ||
55 | # (rw,nosuid,nodev,allow_other,default_permissions) | ||
56 | set -- $(s3_getmpoint backer) | 60 | set -- $(s3_getmpoint backer) |
57 | if test -z "$1"; then | 61 | if test -z "$1"; then |
58 | $dry_run s3backer $backup_s3backer_options \ | 62 | $dry_run s3backer $backup_s3backer_options \ |