Created
October 19, 2012 23:13
-
-
Save jmervine/3921235 to your computer and use it in GitHub Desktop.
script/server_unicorn, because webrick is slow
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
#!/usr/bin/env bash | |
################################################################################ | |
# Author: Joshua Mervine <joshua@mervine.net> | |
# Date: 2012-10-19 | |
# | |
################################################################################ | |
# set up optional variables | |
################################################################################ | |
test "$UNICORN_ROOT" || UNICORN_ROOT="$(pwd)" | |
test "$UNICORN_HOST" || UNICORN_HOST="0.0.0.0" | |
test "$UNICORN_PORT" || UNICORN_PORT="3000" | |
test "$UNICORN_RB" || UNICORN_RB="/tmp/unicorn.rb" | |
if ! test "$UNICORN_WORKERS" | |
then | |
if [[ $( uname ) == "Darwin" ]] | |
then | |
cpus="$( sysclt -a 2>/dev/null | grep "core_count" )" | |
else | |
cpus="$( ( cat /proc/cpuinfo 2>/dev/null ) | grep "^processor" | wc -l )" | |
fi | |
if [[ $cpus == "0" ]] | |
then | |
# this handles non *nix OSs | |
UNICORN_WORKERS="1" | |
else | |
# don't want to use pull all your system resources | |
UNICORN_WORKERS="$( expr $cpus - 1 )" | |
fi | |
fi | |
################################################################################ | |
# set up debug mode check | |
################################################################################ | |
test "$DEBUG" && set -x | |
################################################################################ | |
# create temp unicorn config | |
################################################################################ | |
if ! echo "" > $UNICORN_RB | |
then | |
echo "Permission denied: $UNICORN_RB" | |
echo " I can't continue with unicorn configs." | |
exit 1 | |
fi | |
echo "timeout 60" >> $UNICORN_RB | |
echo "worker_processes $UNICORN_WORKERS" >> $UNICORN_RB | |
echo "listen \"$UNICORN_HOST:$UNICORN_PORT\"" >> $UNICORN_RB | |
echo "preload_app true" >> $UNICORN_RB | |
################################################################################ | |
# start unicorn | |
################################################################################ | |
cd $UNICORN_ROOT | |
exec bundle exec unicorn -c $UNICORN_RB |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment