gem server launch agent
#!/usr/local/bin/bash -l | |
set -eo pipefail | |
declare -a GEM_SERVER_PIDS | |
function server_port { | |
ruby_version="${1}" | |
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}" | |
done | |
} | |
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}" & | |
pid=$! | |
GEM_SERVER_PIDS+=(${pid}) | |
echo "Launched ${pid}" | |
done <<< "${rubies}" | |
wait |
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>Label</key> | |
<string>org.ruby-lang.rdoc</string> | |
<key>ProgramArguments</key> | |
<array> | |
<string>/usr/local/bin/gem-servers</string> | |
</array> | |
<key>KeepAlive</key> | |
<true/> | |
<key>StandardOutPath</key> | |
<string>/var/log/gem-servers.out.log</string> | |
<key>StandardErrorPath</key> | |
<string>/var/log/gem-servers.err.log</string> | |
</dict> | |
</plist> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment