Created
December 28, 2011 18:34
-
-
Save mattf/1529067 to your computer and use it in GitHub Desktop.
memcached managed from Condor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmd = memcached.sh | |
args = -m $$(Memory) | |
log = memcached.log | |
kill_sig = SIGTERM | |
# Want chirp functionality | |
+WantIOProxy = TRUE | |
should_transfer_files = if_needed | |
when_to_transfer_output = on_exit | |
queue |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# condor_chirp in /usr/libexec/condor | |
export PATH=$PATH:/usr/libexec/condor | |
PORT_FILE=$TMP/.ports | |
# When we get SIGTERM, which Condor will send when | |
# we are kicked, kill off memcached. | |
function term { | |
rm -f $PORT_FILE | |
kill %1 | |
} | |
# Spawn memcached, and make sure we can shut it down cleanly. | |
trap term SIGTERM | |
# memcached will write port information to env(MEMCACHED_PORT_FILENAME) | |
env MEMCACHED_PORT_FILENAME=$PORT_FILE memcached -p -1 "$@" & | |
# We might have to wait for the port | |
while [ ! -s $PORT_FILE ]; do sleep 1; done | |
# The port file's format is: | |
# TCP INET: 56697 | |
# TCP INET6: 47318 | |
# UDP INET: 34453 | |
# UDP INET6: 54891 | |
sed -i -e 's/ /_/' -e 's/\(.*\): \(.*\)/\1=\2/' $PORT_FILE | |
source $PORT_FILE | |
rm -f $PORT_FILE | |
# Record the port number where everyone can see it | |
condor_chirp set_job_attr MemcachedEndpoint \"$HOSTNAME:$TCP_INET\" | |
condor_chirp set_job_attr TCP_INET $TCP_INET | |
condor_chirp set_job_attr TCP_INET6 $TCP_INET6 | |
condor_chirp set_job_attr UDP_INET $UDP_INET | |
condor_chirp set_job_attr UDP_INET6 $UDP_INET6 | |
# While memcached is running, collect and report back stats | |
while kill -0 %1; do | |
# Collect stats and chirp them back into the job ad | |
echo stats | nc localhost $TCP_INET | \ | |
grep -v -e END -e version | tr '\r' '\0' | \ | |
awk '{print "stat_"$2,$3}' | \ | |
while read -r stat; do | |
condor_chirp set_job_attr $stat | |
done | |
sleep 30 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment