Skip to content

Instantly share code, notes, and snippets.

@midu
Created May 25, 2012 18:27
Show Gist options
  • Select an option

  • Save midu/2789687 to your computer and use it in GitHub Desktop.

Select an option

Save midu/2789687 to your computer and use it in GitHub Desktop.
cpost command

CPost commands

This scripts assumes you have a standard setup of platform. You'll also need make if you don't have it already (brew install make).

RVM users

This will not work with rvm because rvm is a shady piece of software that does things in a very non-standard way and it was faster for me to switch to rbenv than make it work with rvm.

Install

Download and put wherever you want the Makefile and challengepost.zsh files. Update the variables on top of these two files if needed.

Add

source 'path/to/challengepost.zsh'

To your shell profile/env file. And source it.

Example for zsh:

echo "source 'path/to/challengepost.zsh'" >> $HOME/.zshenv
source $HOME/.zshenv

Available commands

See the usage to see a description of all the available commands.

cpost usage

usage: cpost [mysql|redis|sunspot|memcached|nginx|unicorn]
       cpost [stop_mysql|stop_redis|stop_sunspot|stop_memcached|stop_nginx|stop_unicorn]
       cpost [COMMAND]

cpost COMMANDS:
    cpost | cpost all                 starts the whole environment
    cpost stop                        stops the entire environment
    cpost mysql|stop_mysql            starts/stops mysql server
    cpost redis|stop_redis            starts/stops redis server
    cpost sunspot|stop_sunspot        starts/stops sunspot
    cpost memcached|stop_memcached    starts/stops memcached server
    cpost nginx|stop_nginx            starts/stops nginx server
    cpost unicorn|stop_unicorn        starts/stops uniron server
bin='cpost'
makefile_path='~/path/to/Makefile'
function cpostusage() {
echo "usage: $bin [mysql|redis|sunspot|memcached|nginx|unicorn]"
echo " $bin [stop_mysql|stop_redis|stop_sunspot|stop_memcached|stop_nginx|stop_unicorn]"
echo " $bin [COMMAND]"
echo
echo "$bin COMMANDS:"
echo " cpost | cpost all starts the whole environment"
echo " cpost stop stops the entire environment"
echo " cpost mysql|stop_mysql starts/stops mysql server"
echo " cpost redis|stop_redis starts/stops redis server"
echo " cpost sunspot|stop_sunspot starts/stops sunspot"
echo " cpost memcached|stop_memcached starts/stops memcached server"
echo " cpost nginx|stop_nginx starts/stops nginx server"
echo " cpost unicorn|stop_unicorn starts/stops uniron server"
}
cpost() {
make -f $makefile_path $1
OUT=$?
[ $OUT -eq 0 ] || cpostusage
}
SHELL := /bin/zsh
PLATFORM_PATH := /web/platform
SOLR_PID_PATH := /web/platform/solr/pids/development/sunspot-solr-development.pid
HOME_URL := http://home.dev
all: nginx mysql redis sunspot memcached unicorn
open $(HOME_URL)
stop: stop_nginx stop_mysql stop_redis stop_sunspot stop_memcached stop_unicorn
mysql:
mysql.server start
stop_mysql:
-mysql.server stop
redis: stop_redis
redis-server ~/.redis/redis.conf
stop_redis:
pidof -k redis-server
sunspot: stop_sunspot
cd $(PLATFORM_PATH) && bundle exec rake sunspot:solr:start RAILS_ENV=development
stop_sunspot:
-cd $(PLATFORM_PATH) && [ -f $(SOLR_PID_PATH) ] && bundle exec rake sunspot:solr:stop RAILS_ENV=development
memcached:
memcached &
stop_memcached:
pidof -k memcached
nginx: stop_nginx
sudo nginx -c $(PLATFORM_PATH)/config/nginx/nginx.conf
stop_nginx:
-sudo nginx -c $(PLATFORM_PATH)/config/nginx/nginx.conf -s stop
unicorn: stop_unicorn
cd $(PLATFORM_PATH) && bundle exec unicorn -c config/unicorn/unicorn.rb -D
stop_unicorn:
-kill -s TERM `cat $(PLATFORM_PATH)/log/unicorn*.pid`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment