#!/bin/bash
taskwrapper --name oplog-dump --cmd /usr/local/bin/oplogdump --gearman-host $GEARMAN_HOST --gearman-port $GEARMAN_PORT

#!/bin/bash
gearcmd --name oplog-dump --cmd /usr/local/bin/oplogdump --host $GEARMAN_HOST --port $GEARMAN_PORT &
pid=$!
# When we get a SIGTERM kill the child process and call wait. Note that we need wait both here
# and the line below because of the semantics of the kill syscall. As I understand it, wait returns
# the next time the state of the child process changes. Receiving a SIGTERM qualifies as a change
# of state, so if we don't have a wait after `kill $pid` then we will complete the trap handler
# and our call to `wait` below will complete. By calling `wait` after we kill the subprocess we wait
# for the next process state change which is the actual process termination.
trap "kill $pid && wait" SIGTERM SIGINT
# Wait so that this script keeps running
wait

Update run as worker to pass SIGTERM correctly to subprocess
Update run as worker to pass SIGTERM correctly to subprocess

The reason we weren't gracefully shutting down before is that bash
won't forward SIGTERMs to processes that are running in the foreground.
