diff options
-rw-r--r-- | lib/beam/common.in | 23 | ||||
-rwxr-xr-x | lib/beam/ldap.sh | 2 |
2 files changed, 18 insertions, 7 deletions
diff --git a/lib/beam/common.in b/lib/beam/common.in index bc724c7..e8389f9 100644 --- a/lib/beam/common.in +++ b/lib/beam/common.in @@ -42,25 +42,37 @@ logit() { } abend() { ec=$1 shift error $@ + beam_unlock exit $ec } beam_lock() { if [ -r $backup_pidfile ]; then - pid=$(head -n 1 $backup_pidfile) - if [ -z "$pid" ]; then - abend 1 "pidfile $backup_pidfile exists but is unreadable or empty" - fi - abend 1 "another beam process (pid $pid) is still running; exiting" + if [ ! -r $PIDFILE ]; then + abend 1 "another beam is probably running: $backup_pidfile exists, but is not readable" + else + pid=$(head -n 1 $backup_pidfile) + if [ -z "$pid" ]; then + abend 1 "failed to read PID from $backup_pidfile" + else + if kill -0 $pid 2>/dev/null; then + abend 1 "another beam (pid $pid) is still running; exiting" + else + error "removing stale pidfile $backup_pidfile" + rm $backup_pidfile || abend 1 "failed to remove stale pidfile $backup_pidfile" + fi + fi + fi fi echo $$ > $backup_pidfile || exit 1 epilogue_hook="$epilogue_hook beam_unlock" + trap 'beam_unlock' INT QUIT TERM } beam_unlock() { rm -f $backup_pidfile } @@ -150,13 +162,12 @@ beam_exec() { $beam_rsh "$@" fi } runhook() { local hook_list - eval hook_list=\$$1 for hook in $hook_list do $hook done } diff --git a/lib/beam/ldap.sh b/lib/beam/ldap.sh index 40b9a4b..714b249 100755 --- a/lib/beam/ldap.sh +++ b/lib/beam/ldap.sh @@ -77,13 +77,13 @@ ldap_backup() { dbno=\$${1}_database_number \ dbsuf=\$${1}_database_suffix if [ -n "$dbno" ]; then options="$options -n$dbnum" elif [ -n "$dbsuf" ]; then - options="$options -b$slapcat" + options="$options -b$dbsuf" fi eval uri=\"\$${1}_uri\" if [ -n "$uri" ]; then options="$options -H\"$uri\"" fi |