Skip to content

Instantly share code, notes, and snippets.

@joequery
Created January 13, 2012 15:49

Revisions

  1. joequery revised this gist Jan 19, 2012. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion gistfile1.sh
    Original file line number Diff line number Diff line change
    @@ -34,7 +34,6 @@ function start_unicorn(){
    then
    echo "Unicorn file not found"
    else
    echo "Starting unicorn...(CTRL-C to stop service)"
    bundle exec unicorn_rails -c $unicornFile -E production -D
    fi
    }
  2. joequery revised this gist Jan 19, 2012. 1 changed file with 55 additions and 0 deletions.
    55 changes: 55 additions & 0 deletions gistfile1.sh
    Original file line number Diff line number Diff line change
    @@ -38,3 +38,58 @@ function start_unicorn(){
    bundle exec unicorn_rails -c $unicornFile -E production -D
    fi
    }

    # Create a symbolic link to a config file in the sites-enabled dir
    # arg1: basename of config file in sites-available dir
    # Ex: 'nginx_enable railsapp1.com'
    function nginx_enable(){
    confFile=$1
    fullFilePath=/etc/nginx/sites-available/$confFile
    symLinkPath=/etc/nginx/sites-enabled/$confFile

    # First test to see that the file exists
    if [ ! -e $fullFilePath ]
    then
    printf "%s not found..." "$fullFilePath"
    printf "Aborted!\n"
    else
    # If symlink already exists, delete it so the new configuration
    # will take effect.
    if [ -e $symLinkPath ]
    then
    printf "Old symbolic link removed...\n"
    sudo rm $symLinkPath
    fi

    sudo ln -s $fullFilePath $symLinkPath

    # Confirm the symlink was created
    if [ -e $symLinkPath ]
    then
    printf "$confFile enabled.\n"
    fi
    fi
    }

    # Destroy a symbolic link in the sites-enabled directory.
    # arg1: basename of symbolic link to
    # Ex: 'nginx_disable railsapp1.com'
    function nginx_disable(){
    symLink=$1
    symLinkPath=/etc/nginx/sites-enabled/$symLink

    # First test to see that the link exists
    if [ ! -e $symLinkPath ]
    then
    printf "$symLink is not currently enabled. Exiting.\n"
    else
    # If the link does exist, delete it.
    sudo rm $symLinkPath

    # Confirm the symlink was destroyed
    if [ ! -e $symLinkPath ]
    then
    printf "$symLink disabled.\n"
    fi
    fi
    }
  3. joequery revised this gist Jan 13, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.sh
    Original file line number Diff line number Diff line change
    @@ -34,7 +34,7 @@ function start_unicorn(){
    then
    echo "Unicorn file not found"
    else
    echo "Starting unicorn..."
    echo "Starting unicorn...(CTRL-C to stop service)"
    bundle exec unicorn_rails -c $unicornFile -E production -D
    fi
    }
  4. joequery created this gist Jan 13, 2012.
    40 changes: 40 additions & 0 deletions gistfile1.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    # Kill and restart nginx
    function restart_nginx(){
    pids=$(pidof nginx)
    if [[ -n $pids ]];
    then
    sudo kill -9 $pids
    sudo service nginx restart
    fi
    }

    # Kill unicorn
    function kill_unicorn(){
    ps aux | grep 'unicorn' | awk '{print $2}' | xargs sudo kill -9
    }

    # test unicorn process
    function test_unicorn(){
    # If config/unicorn.rb doesn't exist, don't bother running anything.
    unicornFile=config/unicorn.rb
    if [ ! -e $unicornFile ];
    then
    echo "Unicorn file not found"
    else
    echo "Starting unicorn..."
    bundle exec unicorn_rails -c $unicornFile -E production
    fi
    }

    # run unicorn process as a daemon
    function start_unicorn(){
    # If config/unicorn.rb doesn't exist, don't bother running anything.
    unicornFile=config/unicorn.rb
    if [ ! -e $unicornFile ];
    then
    echo "Unicorn file not found"
    else
    echo "Starting unicorn..."
    bundle exec unicorn_rails -c $unicornFile -E production -D
    fi
    }