Ensure Beaver Log Shipping is Running

I have a love hate relationship with the beaver log shipper and ensuring that it is in fact running on all of my machines (and not in a defunct or partially running state)

I have finally whipped up a script to take care of this issue and thought i’d share it for anyone that cares.


# Name: beaver_ensure_running.sh
# Author: Steve Stonebraker
# Date: 9/18/2013
# https://raw.github.com/ssstonebraker/braker-scripts/master/working-scripts/beaver_ensure_running.sh
# When running in crontab please make sure you set it up like this
# SHELL=/bin/bash
# PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
# */1 * * * * /bin/bash beaver_ensure_running.sh

readarray -t PIDS < <(exec pgrep -x beaver)

function stop_beaver {
    /usr/sbin/service beaver stop
    sleep 5s  ## Optionally wait for processes to stop.
    kill -s SIGTERM "${PIDS[@]}" ## Perhaps force another signal to them if it doesn't work with defuncts.
    sleep 5s  ## Optionally wait for processes to stop.
    kill -s SIGKILL "${PIDS[@]}" ## Perhaps force another signal to them if it doesn't work with defuncts.
if [[ ${#PIDS[@]} -eq 0 ]]; then
    echo "No beaver process was found."
elif [[ ${#PIDS[@]} -eq 1 ]]; then
    echo "Processes found: ${PIDS[*]}"
    echo "Only one beaver process found."
elif ps -fp "${PIDS[@]}" | fgrep -F '<defunct>' >/dev/null; then
    echo "Processes found: ${PIDS[*]}"
    echo "Defunct beaver process found."
    echo "Processes found: ${PIDS[*]}"
[[ $START == true ]] && /usr/sbin/service beaver start

Special shout out to http://stackoverflow.com/questions/18855676/pgrep-defunct-process-to-restart-service

1 comment to Ensure Beaver Log Shipping is Running

  • Jasmine

    Hi! This is great, and works for me. I keep having this problem with my beaver service as well!

    Just a note for others, if you are running an older version of bash you may receive the error,
    ` beaver.sh: line 5: readarray: command not found `
    Just replace,
    `readarray -t PIDS < <(exec pgrep -x beaver)` with `PIDS=( $(exec pgrep -x beaver) )`

    Also, depending on the init script… I had a hang when stopping the service, due trying to kill the so executing a kill -9 “{PIDS[@]}” in replacement seems to work.


Leave a Reply

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>