Skip to content

Instantly share code, notes, and snippets.

Created April 21, 2015 04:48
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save adamstegman/76d9cb40a8a3d92ea0e6 to your computer and use it in GitHub Desktop.
gem server launch agent
#!/usr/local/bin/bash -l
set -eo pipefail
declare -a GEM_SERVER_PIDS
function server_port {
port_last_3="`echo "${ruby_version}" | sed 's/^ruby-\([0-9]\)\.\([0-9]\)\.\([0-9]\).*$/\1\2\3/'`"
echo "8${port_last_3}"
function cleanup {
# allow failures during cleanup, just let the script exit
set +e
for pid in ${GEM_SERVER_PIDS[@]}; do
echo "Reaping child ${pid}..."
kill "${pid}"
trap cleanup EXIT
rubies="`chruby | tr -d '*' | awk '{print $1}'`"
while read -r ruby; do
port="`server_port "${ruby}"`"
echo "Launching Ruby ${ruby} at localhost:${port}..."
chruby "${ruby}"
gem server -p "${port}" &
echo "Launched ${pid}"
done <<< "${rubies}"
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment