Skip to content
Browse files

Began splitting bdsm out into multiple scripts.

  • Loading branch information...
1 parent c43edef commit 6fa5dc373007ed5257434b4506c455d415225c33 @wayneeseguin wayneeseguin committed Nov 19, 2009
Showing with 685 additions and 410 deletions.
  1. +1 −0 .gitignore
  2. +67 −410 bin/bdsm
  3. 0 config/db
  4. +11 −0 install
  5. +49 −0 scripts/color
  6. +34 −0 scripts/db
  7. +115 −0 scripts/deploy
  8. +65 −0 scripts/fetch
  9. +32 −0 scripts/initialize
  10. +14 −0 scripts/log
  11. +3 −0 scripts/logtail
  12. +16 −0 scripts/match
  13. +41 −0 scripts/mongrel
  14. +3 −0 scripts/nginx
  15. 0 scripts/pancake
  16. +15 −0 scripts/passenger
  17. +42 −0 scripts/rack
  18. +30 −0 scripts/rails
  19. +37 −0 scripts/setup
  20. 0 scripts/sinatra
  21. +41 −0 scripts/thin
  22. +26 −0 scripts/thinking_sphinx
  23. +43 −0 scripts/unicorn
View
1 .gitignore
@@ -1 +1,2 @@
releases/
+release
View
477 bin/bdsm
@@ -3,391 +3,87 @@
# Author: Wayne E. Seguin
# All Rights Reserved
-VERSION=0.0.1
+VERSION=0.0.2
-#
-# Environment
-#
-cleanup_variables() {
- :
-}
-
-load_profile() { if [[ -f $HOME/.bash_profile ]] ; then source $HOME/.bash_profile ; fi ; }
-
-load_bdsmrc() { if [[ -f "$HOME/.bdsmrc" ]] ; then source "$HOME/.bdsmrc" ; fi ; }
-
-
-load_defaults() {
- :
-}
-
-initialize() {
- if [ -z "$project" ] ; then
- # TODO: Improve this line vv
- if [ -d $HOME/current ] ; then
- project=$(whoami)
- else
- echo -e "\$project was not specified."
- exit 1
- fi
- fi
- result=0
- user=$(whoami)
- remote=${remote:-"origin"}
- branch=${branch:-"master"}
- framework=${framework:-"rails"}
- keep_releases=${keep_releases:-"10"}
- timestamp="$(date +%m.%d.%Y-%H:%M:%S)"
- current_dir="${current_dir:-$HOME/current}"
- shared_path="${shared_path:-$HOME/shared}"
- project_dir="${project_dir:-$HOME}"
- current_dir="${current_dir:-$project_dir/current}"
- RAILS_ENV="${RAILS_ENV:-"production"}" ; export RAILS_ENV
- old_releases="$(ls -t | awk "NR > $keep_releases { print \$0 }")"
-
- if [ -f ".${project}rc" ] ; then source ".${project}rc" ; fi
-
- trap 'cleanup_variables ; rm -rf "/tmp/bdsm/$$" >/dev/null 2>&1' 0 1 2 3 15
-}
-
-#
-# Setup
-#
-setup() {
- if [[ "root" = $(whoami) ]] ; then
- echo "Must be run as the project user."
- exit 1
- fi
- for dir in config log pids sockets "public/assets" tmp ; do
- mkdir -p "$HOME/shared/$dir"
- done
- touch $HOME/shared/config/database.yml
- touch $HOME/.bash_profile
-
- if ! awk "/^project/" "$HOME/.bash_profile" ; then
- echo "project=\"$(user)\" ; export project" >> $HOME/.bash_profile
- fi
- if ! awk "/^environment/" "$HOME/.bash_profile" ; then
- echo "environment=\"production\" ; export environment" >> $HOME/.bash_profile
- fi
- if ! awk "/^RAILS_ENV/" "$HOME/.bash_profile" ; then
- echo "RAILS_ENV=\"\$environment\" ; export RAILS_ENV" >> $HOME/.bash_profile
- fi
- if ! awk '/current\/\.rvmrc/' "$HOME/.bash_profile" ; then
- echo 'if [[ -d $HOME/current ]] && [[ -f $HOME/current/.rvmrc ]] ; then source $HOME/current/.rvmrc ; fi' >> $HOME/.bash_profile
- fi
- if ! awk '/scripts\/rvm/' "$HOME/.bash_profile" ; then
- echo 'if [[ -s $HOME/.rvm/scripts/rvm ]] ; then source $HOME/.rvm/scripts/rvm ; fi' >> $HOME/.bash_profile
- fi
-}
-
-#
-# Deploy
-#
-deploy() {
- log "info" "Deploying..."
- (
- hook "before_deploy" &&
- update_repository &&
- hook "after_repository_update" &&
- update_current &&
- hook "after_update_current" &&
- configure &&
- hook "after_configure" &&
- symlink &&
- hook "after_symlink" &&
- cleanup &&
- hook "after_deploy"
- )
- result=$?
- log "info" "Deploy started at $timestamp and completed at $(date +%m.%d.%Y-%H:%M:%S)"
- exit $result
-}
-
-hook() {
- if [[ -f "$current_dir/.$1" ]] ; then source "$current_dir/.$1" ; fi
-}
-
-update() {
- update_repository && update_current
- return $?
-}
-
-update_repository() {
- log "Updating local repository in $shared_path/$project."
- cd "$shared_path/$project" > /dev/null 2>&1
- current_branch=$(git branch | awk '/\* /{print $2}')
- # TODO: Improve error handling
- if [ "$current_branch" != "$branch" ] ; then
- log "Switching to branch $branch from $current_branch"
- git checkout -b $branch --track $remote/$branch
- fi
- git pull $remote $branch
-
- if [ -f .gitmodules ] ; then
- log "Updating submodules."
- git submodule init 2>/dev/null
- git submodule update
- fi
-}
-
-update_current() {
- if [ -d $current_dir ] ; then
- log "Moving aside previous release."
- mkdir -p $HOME/previous
- mv $current_dir $HOME/previous/$timestamp
- fi
- log "Installing new release to $current_dir"
- rsync -ag --exclude=".git/*" $shared_path/$project/ $current_dir;
-}
-
-configure() {
- cd $shared_path/config
- log "Setting up persistent yaml files:"
- for yaml_file in *.yml; do
- log " - $yaml_file"
- rm -f $current_dir/config/$yaml_file
- ln -nfs $shared_path/config/$yaml_file $current_dir/config/$yaml_file
- done
-
- log "Setting up persistent config files:"
- for config_file in $(ls $shared_path/config/*.conf); do
- file_name=$(basename $config_file)
- log " - $file_name"
- rm -f $current_dir/config/$file_name
- ln -nfs $shared_path/config/$file_name $current_dir/config/$file_name
- done
-
- log "Setting up persistent ruby config files:"
- for config_file in $(ls $shared_path/config/*.rb); do
- file_name=$(basename $config_file)
- log " - $file_name"
- rm -f $current_dir/config/$file_name
- ln -nfs $shared_path/config/$file_name $current_dir/config/$file_name
- done
-}
-
-symlink() {
- log "Setting up persistent directories"
- for dir in log public/assets pids files ; do
- if [ -d $shared_path/$dir ] ; then
- log " - $dir"
- rm -rf $current_dir/$dir
- ln -nfs $shared_path/$dir $current_dir/$dir
- else
- log "<i> $shared_path/$dir does not exist, skipping."
- fi
- done
-}
-
-cleanup() {
- log "Removing old releases..."
- cd $HOME/previous
- for release in $old_releases ; do
- if [ -d $release ] ; then
- log " - $release"
- rm -rf $release
- else
- log "info" "Skipping ~/previous/$release as the directory does not exist."
- fi
- done
- cd
-}
-
-#
-# Sphinx
-#
-sphinx() {
- sphinx_config_file="$current_dir/config/$environment.sphinx.conf"
- if [ -f $sphinx_config_file ] ; then
- case "$1" in
- stop) sphinx_stop ;;
- start) sphinx_start ;;
- index) sphinx_index ;;
- restart)
- sphinx_stop
- sphinx_index
- sphinx_start
- ;;
- esac
- else
- echo "$sphinx_config_file is missing, sphinx '$1' will not be performed."
- fi
-}
-sphinx_index() { cd $current_dir ; rake thinking_sphinx:index ; }
-sphinx_stop() { cd $current_dir ; rake thinking_sphinx:stop ; }
-sphinx_start() { cd $current_dir ; rake thinking_sphinx:start ; }
-
-log() {
- if [ ! -z "$2" ] ; then level=$1 ; shift ; else level="info" ; fi ; message=$1
- case "$level" in
- debug) shift ;
- ((debug_flag)) && echo -e "$(tput setaf 5)<d>$(tput sgr0) $message $(tput setaf 5)</d> $(tput sgr0) "
- ;;
- info) shift ; echo -e "$(tput setaf 2)<i>$(tput sgr0) $message $(tput setaf 2)</i> $(tput sgr0) " ;;
- warn) shift ; echo -e "$(tput setaf 3)<w>$(tput sgr0) $message $(tput setaf 3)</w> $(tput sgr0) " ;;
- error) shift ; echo -e "$(tput setaf 1)<e>$(tput sgr0) $message $(tput setaf 1)</e> $(tput sgr0) " ;;
- fail) shift ; echo -e "$(tput setaf 1)<f>$(tput sgr0) $message $(tput setaf 1)</f> $(tput sgr0) " ; return 1 ;;
- *) echo -e "$message"
- esac
-}
-
-logtail() { tail -f $project_dir/shared/log/*.log ; }
-
-#
-# Rails
-#
-migrate() {
- cd $current_dir
- rake db:migrate --trace
+function version {
+ _author="Wayne E. Seguin"
+ _author_email="wayneeseguin@gmail.com"
+ _website="http://bdsm.beginrescueend.com/"
+ _version="$VERSION"
+ echo -e "bdsm ${_version} ${_website} by ${_author} (${_author_email})"
}
-console() {
- cd $current_dir
- if [[ -f script/console ]] ; then ruby script/console ; fi
-}
+function usage {
-dbconsole() {
- cd $current_dir
- if [[ -f script/console ]] ; then ruby script/dbconsole ; fi
-}
+ version
-restart() { eval "${server} restart" ; }
-start() { eval "${server} start" ; }
-stop() { eval "${server} stop" ; }
+ echo -e "
-#
-# Unicorn
-#
-unicorn() {
- master_pid="$(ps auxww | grep '[u]nicorn' | grep 'master' | awk '/'${project}'/{print $2}')"
+CLI
- cd $current_dir
- if [[ "$start_flag" -eq 1 ]] ; then
- unicorn_rails -c $current_dir/config/unicorn.rb -E $RAILS_ENV -D
- if [[ "$master_pid" -gt 0 ]] ; then
- sleep 1 ; kill -QUIT $master_pid
- fi
- return $?
- elif [[ "$master_pid" -le 0 ]] ; then
- echo "unicorn is not running for $project yet."
- return 1
- elif [[ "$stop_flag" -eq 1 ]] || [[ "$graceful_flag" -eq 1 ]] ; then
- kill -QUIT $master_pid
- elif [[ "$restart_flag" -eq 1 ]] ; then
- kill -USR2 $master_pid
- sleep 1
- kill -QUIT $master_pid
- elif [[ "$pause_flag" -eq 1 ]] ; then
- kill -WINCH $master_pid
- elif [[ "$unpause_flag" -eq 1 ]] ; then
- kill -WINCH $master_pid
- elif [[ "$kill_flag" -eq 1 ]] ; then
- kill -TERM $master_pid
- elif [[ "$increase_flag" -eq 1 ]] ; then
- kill -TTOU $master_pid
- elif [[ "$decrease_flag" -eq 1 ]] ; then
- kill -TTOU $master_pid
- elif [[ "$logs_flag" -eq 1 ]] ; then
- kill -USR1 $master_pid
- elif [[ "$reload_flag" -eq 1 ]] ; then
- kill -HUP $master_pid
- else
- :
- fi
- return $?
-}
+ bdsm deploy
+ bdsm install [server]
+ bdsm setup [server] ((--force))
+ bdsm stop [server]
+ bdsm start [server]
+ bdsm restart [server]
+ bdsm reload [server]
+ bdsm migrate
+ bdsm tail # Tail all logs in shared/log/*.log
+ bdsm console
+ bdsm dbconsole
-#
-# Passenger
-#
-passenger() {
- case "$1" in
- start) ;;
- stop) ;;
- restart)
- # Default is passenger
- log "Restarting Passenger Application."
- mkdir -p $project_dir/tmp
- touch $project_dir/tmp/restart.txt
- log "Restart triggered."
- ;;
- esac
-}
+Notes:
-#
-# Mongrel
-#
-mongrel() {
- cd $current_dir
- if [ -f ".bdsmrc" ] ; then source .bdsmrc ; fi
- if [ -f ".${project}rc" ] ; then source ".${project}rc" ; fi
+ [project] is required
+ - if non root, otherwise defaults to the current user name if not set
- master_pid="$(ps auxww | grep '[m]ongrel' | awk '/'${project}'/{print $2}')"
- if [[! -z "$master_pid"]] && [[ $master_pid -gt 0 ]] ; then
- mongrel restart
- else # start
- mongrel start
- fi
+ [project|environment|repository]
+ - may be exported as environment varaibles
+ - or set in the ~/.bdsmrc
+ - or specified as for example --project X
- cd $project_dir
- case "$1" in
- #trap "TERM" { log "TERM signal received."; stop }
- #trap "USR1" {log "USR1 received, toggling $mongrel_debug_client to #{!$mongrel_debug_client}"; $mongrel_debug_client = !$mongrel_debug_client }
- # restart
- #trap "USR2" { log "USR2 signal received."; stop(true) }
+ prerequisites:
+ - git
+ - curl
+ - ruby OR prereqs for rvm (preferred)
- stop|graceful) kill -TERM $master_pid ;;
- kill) kill -INT $master_pid ;;
- logs) kill -USR1 $master_pid ;;
- restart) kill -USR1 $master_pid ;;
- increase) mongrel_adjust "increase" ;;
- decrease) mongrel_adjust "decrease" ;;
- start)
+ http://bdsm.beginrescueend.com/
+ https://www.pivotaltracker.com/projects/26822
- ;;
- restart) mongrel start && sleep 1 && mongrel stop ;;
- esac
+" | ${PAGER:-less}
}
-mongrel_start() { mongrel -c $project_dir/config/mongrel.rb -E $RAILS_ENV -D ; }
-mongrel_stop() { : ; }
-mongrel_stop() { : ; }
-mongrel_adjust() { : ; }
-
-thin() { echo "thin has not yet been implemented." ; }
-rack() { echo "rack has not yet been implemented." ; }
-
-#
# Setup
-#
-cleanup_variables
-load_profile
-load_bdsmrc
-initialize
-load_defaults
+prefix="${prefix:-/usr/local/}"
+if [[ -f $HOME/.bash_profile ]] ; then source "$HOME/.bash_profile" ; fi
+if [[ -f "$HOME/.bdsmrc" ]] ; then source "$HOME/.bdsmrc" ; fi
+source $prefix/bdsm/scripts/initialize
# parse args
while [ $# -gt 0 ] ; do
token="$1" ; shift
case "$token" in
- nginx|apache|sphinx|solr|unicorn|mongrel|thin|passenger|setup)
- server=$token
- action=${action:-$token}
+ migrate|logtail|console|dbconsole|deploy)
+ action=$token
;;
- start|stop|graceful|restart|reload|install|uninstall|pause|unpause|kill|increase|decrease|logs)
- eval "${token/--/}_flag=1"
+ nginx|apache|thinking_sphinx|solr|unicorn|mongrel|thin|passenger|setup)
+ server="$token"
+ action="${action:-$token}"
;;
- migrate|logtail|console|dbconsole|deploy)
- action=$token
+ start|stop|graceful||reload|install|uninstall|pause|unpause|kill|increase|decrease|logs)
+ eval "export ${token/--/}_flag=1"
;;
- --trace) trace_flag=1 ; debug_flag=1 ; set -x ;;
- --debug) debug_flag=1 ;;
- --version) action="version" ;;
+ --project) export project="$1" ;;
+ --environment) export environment="$1" ;;
+ --repo|repository) export repository="$1" ;;
+ --trace) export trace_flag=1 ; export debug_flag=1 ; set -x ;;
+ --debug) export debug_flag=1 ;;
+ --version) action="version" ;;
*)
if [[ -z "$action" ]] ; then
@@ -396,10 +92,10 @@ while [ $# -gt 0 ] ; do
else
if [[ -d "/data/$token" ]] ; then
project="$token"
- project_dir="/data/$token"
+ project_path="/data/$token"
elif [[ -d "/home/$token" ]] ; then
project="$token"
- project_dir="/home/$token"
+ project_path="/home/$token"
else
# determine sanity of project
action="error"
@@ -413,63 +109,24 @@ done
if [ ! -z "$error_message" ] ; then exit 1 ; fi
-function version {
- _author="Wayne E. Seguin"
- _author_email="wayneeseguin@gmail.com"
- _website="http://bdsm.beginrescueend.com/"
- _version="$VERSION"
- echo -e "bdsm ${_version} ${_website} by ${_author} (${_author_email})"
-}
-
-function usage {
-
- version
-
- echo -e "
-
-CLI
-
- bdsm deploy [project]
- bdsm install [server|project]
- bdsm setup [server|project] ((--force))
- bdsm stop [server|project]
- bdsm start [server|project]
- bdsm restart [server|project]
- bdsm reload [server|project]
- bdsm migrate [project]
- bdsm tail [project] # Tail all logs in shared/log/*.log
- bdsm console [project]
- bdsm dbconsole [project]
-
-Notes:
-
- [project] is required if root, otherwise use the current user name
-
- http://bdsm.beginrescueend.com/
- https://www.pivotaltracker.com/projects/26822
-
-" | ${PAGER:-less}
-}
-
#
# Main Logic
#
if [[ "$trace_flag" = 1 ]] ; then set -x ; else set +x ; fi
result=0
case "$action" in
- setup) setup ;;
- console) console ;;
- dbconsole) dbconsole ;;
- logtail) logtail ;;
- version) version ;;
- unicorn) unicorn ;;
- mongrel) mongrel ;;
- thin) thin ;;
- sphinx) sphinx ;;
- restart) restart ;;
- deploy) deploy ;;
- *) usage ;;
+ setup) $scripts_path/setup ;;
+ console) $scripts_path/rails console ;;
+ dbconsole) $scripts_path/rails dbconsole ;;
+ logtail) $scripts_path/logtail ;;
+ version) version ;;
+ unicorn) $scripts_path/unicorn ;;
+ mongrel) $scripts_path/mongrel ;;
+ thin) $scripts_path/thin ;;
+ thinking_sphinx) $scripts_path/thinking_sphinx ;;
+ deploy) $scripts_path/deploy ;;
+ *) usage ;;
esac
result=$?
-exit $result
+exit $result
View
0 config/db
No changes.
View
11 install
@@ -0,0 +1,11 @@
+#!/usr/bin/env bash
+
+prefix="${prefix:-/usr/local}"
+
+for dir in bin scripts ; do
+ mkdir -p "${prefix}/bdsm/${dir}"
+ cp -R ./$dir/ "/usr/local/bdsm/$dir"
+done
+
+ln -nfs "${prefix}/bdsm/bin/bdsm" "${prefix}/bin/bdsm/bin/bdsm"
+
View
49 scripts/color
@@ -0,0 +1,49 @@
+#!/usr/bin/env bash
+
+case "$1" in
+ # regular colors
+ black) tput setaf 0 ;;
+ red) tput setaf 1 ;;
+ green) tput setaf 2 ;;
+ yellow) tput setaf 3 ;;
+ blue) tput setaf 4 ;;
+ magenta) tput setaf 5 ;;
+ cyan) tput setaf 6 ;;
+ white) tput setaf 7 ;;
+
+ # emphasized (bolded) colors
+ eblack) tput bold ; tput setaf 0 ;;
+ ered) tput bold ; tput setaf 1 ;;
+ egreen) tput bold ; tput setaf 2 ;;
+ eyellow) tput bold ; tput setaf 3 ;;
+ eblue) tput bold ; tput setaf 4 ;;
+ emagenta) tput bold ; tput setaf 5 ;;
+ ecyan) tput bold ; tput setaf 6 ;;
+ ewhite) tput bold ; tput setaf 7 ;;
+
+ # underlined colors
+ ublack) set smul unset rmul ; tput setaf 0 ;;
+ ured) set smul unset rmul ; tput setaf 1 ;;
+ ugreen) set smul unset rmul ; tput setaf 2 ;;
+ uyellow) set smul unset rmul ; tput setaf 3 ;;
+ ublue) set smul unset rmul ; tput setaf 4 ;;
+ umagenta) set smul unset rmul ; tput setaf 5 ;;
+ ucyan) set smul unset rmul ; tput setaf 6 ;;
+ uwhite) set smul unset rmul ; tput setaf 7 ;;
+
+ # background colors
+ bblack) tput setab 0 ;;
+ bred) tput setab 1 ;;
+ bgreen) tput setab 2 ;;
+ byellow) tput setab 3 ;;
+ bblue) tput setab 4 ;;
+ bmagenta) tput setab 5 ;;
+ bcyan) tput setab 6 ;;
+ bwhite) tput setab 7 ;;
+
+ # Defaults
+ default) tput setaf 9 ;;
+ bdefault) tput setab 9 ;;
+ none) tput sgr0 ;;
+ *) tput sgr0 # Reset
+esac
View
34 scripts/db
@@ -0,0 +1,34 @@
+#!/usr/bin/env bash
+
+if [[ -f "$1" ]] ; then
+ database_file="$1" ; shift
+ if [[ ! -f "$database_file" ]] ; then
+ mkdir -p $(dirname $database_file)
+ touch $database_file
+ fi
+else
+ echo "usage: $0 database key [value]"
+ exit 1
+fi
+
+key="$1" ; shift
+if [[ -z "$key" ]] ; then
+ echo "usage: $0 database key [value]"
+ exit 1
+else
+ value="$*"
+ if [[ "unset" = "$value" ]] || [[ "delete" = "$value" ]] ; then
+ sed -i.tmp "s#^$key=.*\$##" $database_file
+ else
+ if [[ -z "$value" ]] ; then # get
+ awk -F= '/^'"$key"'=/{print $2}' $database_file
+ else # set
+ if [[ -z "$(awk -F= "/^'"$key"'=/{print $2}" $database_file)" ]] ; then # append
+ echo "$key=$value" >> $database_file
+ else # overwrite
+ sed -i.tmp "s#^$key=.*\$#$key=$value#" $database_file
+ fi
+ fi
+ fi
+fi
+
View
115 scripts/deploy
@@ -0,0 +1,115 @@
+#!/usr/bin/env bash
+
+#
+# Deploy
+#
+deploy() {
+ log "info" "Deploying..."
+ (
+ hook "before_deploy" &&
+ update_repository &&
+ hook "after_repository_update" &&
+ update_current &&
+ hook "after_update_current" &&
+ configure &&
+ hook "after_configure" &&
+ symlink &&
+ hook "after_symlink" &&
+ cleanup &&
+ hook "after_deploy"
+ )
+ result=$?
+ log "info" "Deploy started at $timestamp and completed at $(date +%m.%d.%Y-%H:%M:%S)"
+ exit $result
+}
+
+hook() {
+ if [[ -f "$current_path/.$1" ]] ; then source "$current_path/.$1" ; fi
+}
+
+update() {
+ update_repository && update_current
+ return $?
+}
+
+update_repository() {
+ log "Updating local repository in $shared_path/$project."
+ builtin cd "$shared_path/$project" > /dev/null 2>&1
+ current_branch=$(git branch | awk '/\* /{print $2}')
+ # TODO: Improve error handling
+ if [ "$current_branch" != "$branch" ] ; then
+ log "Switching to branch $branch from $current_branch"
+ git checkout -b $branch --track $remote/$branch
+ fi
+ git pull $remote $branch
+
+ if [ -f .gitmodules ] ; then
+ log "Updating submodules."
+ git submodule init 2>/dev/null
+ git submodule update
+ fi
+}
+
+update_current() {
+ if [ -d $current_path ] ; then
+ log "Moving aside previous release."
+ mkdir -p $HOME/previous
+ mv $current_path $HOME/previous/$timestamp
+ fi
+ log "Installing new release to $current_path"
+ rsync -ag --exclude=".git/*" $shared_path/$project/ $current_path;
+}
+
+configure() {
+ builtin cd $shared_path/config
+ log "Setting up persistent yaml files:"
+ for yaml_file in *.yml; do
+ log " - $yaml_file"
+ rm -f $current_path/config/$yaml_file
+ ln -nfs $shared_path/config/$yaml_file $current_path/config/$yaml_file
+ done
+
+ log "Setting up persistent config files:"
+ for config_file in $(ls $shared_path/config/*.conf); do
+ file_name=$(basename $config_file)
+ log " - $file_name"
+ rm -f $current_path/config/$file_name
+ ln -nfs $shared_path/config/$file_name $current_path/config/$file_name
+ done
+
+ log "Setting up persistent ruby config files:"
+ for config_file in $(ls $shared_path/config/*.rb); do
+ file_name=$(basename $config_file)
+ log " - $file_name"
+ rm -f $current_path/config/$file_name
+ ln -nfs $shared_path/config/$file_name $current_path/config/$file_name
+ done
+}
+
+symlink() {
+ log "Setting up persistent directories"
+ for dir in log public/assets pids files ; do
+ if [ -d $shared_path/$dir ] ; then
+ log " - $dir"
+ rm -rf $current_path/$dir
+ ln -nfs $shared_path/$dir $current_path/$dir
+ else
+ log "<i> $shared_path/$dir does not exist, skipping."
+ fi
+ done
+}
+
+cleanup() {
+ log "Removing old releases..."
+ builtin cd $HOME/previous
+ for release in $old_releases ; do
+ if [ -d $release ] ; then
+ log " - $release"
+ rm -rf $release
+ else
+ log "info" "Skipping ~/previous/$release as the directory does not exist."
+ fi
+ done
+ cd
+}
+
View
65 scripts/fetch
@@ -0,0 +1,65 @@
+#!/usr/bin/env bash
+
+fetch_command=$(which curl)
+if [[ $? -ne 0 ]] ; then
+ $scripts_path/log "fail" "rvm requires curl, which does not seem to exist in your path :("
+ exit 1
+else
+ fetch_command="$fetch_command -O -L --create-dirs -C - " # -s for silent
+fi
+
+pushd "$archives_path" > /dev/null 2>&1
+
+if [[ -z "$1" ]] ; then $scripts_path/log "fail" "BUG: $0 called without an argument :/" ; exit 1 ; fi
+
+archive=$(basename "$1") ; downlaod=1
+
+(( $debug_flag )) && $scripts_path/log "debug" "Fetching $archive"
+
+# Check first if we have the correct archive
+if [[ -e "$archive" ]] && [[ -e "$archive.md5" ]] ; then
+ (( $debug_flag )) && $scripts_path/log "debug" "Found archive and its md5, testing correctness"
+ if [[ $(md5sum --status -c "$archive.md5") -gt 0 ]] ; then
+ (( $debug_flag )) && $scripts_path/log "debug" "Archive is bad, downloading"
+ download=1
+ else
+ (( $debug_flag )) && $scripts_path/log "debug" "Archive is good, not downloading"
+ download=0
+ result=0
+ fi
+else
+ (( $debug_flag )) && $scripts_path/log "debug" "No archive or no MD5, downloading"
+ download=1
+fi
+if [[ $download -gt 0 ]] ; then
+ eval $fetch_command "$1"
+ result=$?
+ if [[ $result -gt 0 ]] ; then
+ retry=0
+ if [[ $result -eq 78 ]] ; then
+ $scripts_path/log "error" "The requested url does not exist: '$1'"
+ elif [[ $result -eq 18 ]] ; then
+ $scripts_path/log "error" "Partial file. Only a part of the file was transferred. Removing partial and re-trying."
+ rm -f "$archive"
+ retry=1
+ elif [[ $result -eq 33 ]] ; then
+ (( $debug_flag )) && $scripts_path/log "debug" "Server does not support 'range' command, removing '$archive'"
+ rm -f "$archive"
+ retry=1
+ else
+ $scripts_path/log "error" "There was an error, please check $log_path/*.error.log"
+ fi
+
+ if [[ $retry -eq 1 ]] ; then
+ eval $fetch_command "$1"
+ result=$?
+ if [[ $result -gt 0 ]] ; then
+ $scripts_path/log "error" "There was an error, please check $log_path/*.error.log"
+ fi
+ fi
+
+ fi
+ popd > /dev/null 2>&1
+fi
+
+exit $result
View
32 scripts/initialize
@@ -0,0 +1,32 @@
+#!/usr/bin/env bash
+
+result=0
+user=$(whoami)
+if [ -z "$project" ] ; then
+# TODO: Improve this line vv
+ if [ -d $HOME/shared/$user ] ; then
+ project=$user
+ else
+ echo -e "\$project was not specified."
+ exit 1
+ fi
+fi
+remote=${remote:-"origin"}
+branch=${branch:-"master"}
+framework=${framework:-"rails"}
+keep_releases=${keep_releases:-"10"}
+timestamp="$(date +%m.%d.%Y-%H:%M:%S)"
+
+project_path="${project_path:-$HOME}"
+shared_path="${shared_path:-$project_path/shared}"
+current_path="${current_path:-$project_path/current}"
+RAILS_ENV="${RAILS_ENV:-"production"}" ; export RAILS_ENV
+old_releases="$(ls -t | awk "NR > $keep_releases { print \$0 }")"
+
+if [ -f ".${project}rc" ] ; then source ".${project}rc" ; fi
+if [ -f ".rvmrc" ] ; then source ".rvmrc" ; fi
+
+trap 'cleanup_variables ; rm -rf "/tmp/bdsm/$$" >/dev/null 2>&1' 0 1 2 3 15
+
+export user project remote branch framework keep_releases timestamp project_path current_path shared_path RAILS_ENV old_releases
+
View
14 scripts/log
@@ -0,0 +1,14 @@
+#!/usr/bin/env bash
+
+if [[ ! -z "$2" ]] ; then level=$1 ; shift ; else level="info" ; fi
+message=$1
+case "$level" in
+ debug) shift ; echo -e "$(tput setaf 5)<d>$(tput sgr0) $message $(tput setaf 5)</d> $(tput sgr0) " ;;
+ info) shift ; echo -e "$(tput setaf 2)<i>$(tput sgr0) $message $(tput setaf 2)</i> $(tput sgr0) " ;;
+ warn) shift ; echo -e "$(tput setaf 3)<w>$(tput sgr0) $message $(tput setaf 3)</w> $(tput sgr0) " ;;
+ error) shift ; echo -e "$(tput setaf 1)<e>$(tput sgr0) $message $(tput setaf 1)</e> $(tput sgr0) " ;;
+ fail) shift ; echo -e "$(tput setaf 1)<f>$(tput sgr0) $message $(tput setaf 1)</f> $(tput sgr0) " ;;
+ *) echo -e "$message"
+esac
+
+exit 0
View
3 scripts/logtail
@@ -0,0 +1,3 @@
+#!/usr/bin/env bash
+
+exec tail -f $project_path/shared/log/*.log
View
16 scripts/match
@@ -0,0 +1,16 @@
+#!/usr/bin/env bash
+
+if [[ -z "$1" ]] || [[ -z "$2" ]] ; then
+ exit 1
+fi
+
+if [[ ! -z "$BASH_VERSION" ]] && [[ ${BASH_VERSION:0:1} -gt 2 ]] ; then
+ [[ "$1" =~ $2 ]]
+ exit $?
+else
+ if [ ! -z "$(echo "$1" | awk "/${2}/")" ] ; then
+ exit 0
+ else
+ exit 1
+ fi
+fi
View
41 scripts/mongrel
@@ -0,0 +1,41 @@
+#!/usr/bin/env bash
+
+#
+# Mongrel
+#
+builtin cd $current_path
+if [ -f ".bdsmrc" ] ; then source .bdsmrc ; fi
+if [ -f ".${project}rc" ] ; then source ".${project}rc" ; fi
+
+master_pid="$(ps auxww | grep '[m]ongrel' | awk '/'${project}'/{print $2}')"
+if [[! -z "$master_pid"]] && [[ $master_pid -gt 0 ]] ; then
+ mongrel restart
+else # start
+ mongrel start
+fi
+
+builtin cd $project_path
+case "$1" in
+ #trap "TERM" { log "TERM signal received."; stop }
+ #trap "USR1" {log "USR1 received, toggling $mongrel_debug_client to #{!$mongrel_debug_client}"; $mongrel_debug_client = !$mongrel_debug_client }
+ # restart
+ #trap "USR2" { log "USR2 signal received."; stop(true) }
+
+ stop|graceful) kill -TERM $master_pid ;;
+ kill) kill -INT $master_pid ;;
+ logs) kill -USR1 $master_pid ;;
+ restart) kill -USR1 $master_pid ;;
+ increase) mongrel_adjust "increase" ;;
+ decrease) mongrel_adjust "decrease" ;;
+ start)
+
+ ;;
+ restart) mongrel start && sleep 1 && mongrel stop ;;
+esac
+
+mongrel_start() { mongrel -c $project_path/config/mongrel.rb -E $RAILS_ENV -D ; }
+mongrel_stop() { : ; }
+mongrel_stop() { : ; }
+mongrel_adjust() { : ; }
+
+
View
3 scripts/nginx
@@ -0,0 +1,3 @@
+#!/usr/bin/env bash
+
+
View
0 scripts/pancake
No changes.
View
15 scripts/passenger
@@ -0,0 +1,15 @@
+#
+# Passenger
+#
+case "$1" in
+ start) ;;
+ stop) ;;
+ restart)
+ # Default is passenger
+ log "Restarting Passenger Application."
+ mkdir -p $project_dir/tmp
+ touch $project_dir/tmp/restart.txt
+ log "Restart triggered."
+ ;;
+esac
+
View
42 scripts/rack
@@ -0,0 +1,42 @@
+#!/usr/bin/env bash
+
+#
+# Rack - use unicorn? rackup?
+#
+
+master_pid="$(ps auxww | grep '[u]nicorn' | grep 'master' | awk '/'${project}'/{print $2}')"
+
+builtin cd $current_path
+if [[ "$start_flag" -eq 1 ]] ; then
+ unicorn -c $current_path/config/unicorn.rb -E $RAILS_ENV -D
+ if [[ "$master_pid" -gt 0 ]] ; then
+ sleep 1 ; kill -QUIT $master_pid
+ fi
+ return $?
+elif [[ "$master_pid" -le 0 ]] ; then
+ echo "unicorn is not running for $project yet."
+ return 1
+elif [[ "$stop_flag" -eq 1 ]] || [[ "$graceful_flag" -eq 1 ]] ; then
+ kill -QUIT $master_pid
+elif [[ "$restart_flag" -eq 1 ]] ; then
+ kill -USR2 $master_pid
+ sleep 5
+ kill -QUIT $master_pid
+elif [[ "$pause_flag" -eq 1 ]] ; then
+ kill -WINCH $master_pid
+elif [[ "$unpause_flag" -eq 1 ]] ; then
+ kill -WINCH $master_pid
+elif [[ "$kill_flag" -eq 1 ]] ; then
+ kill -TERM $master_pid
+elif [[ "$increase_flag" -eq 1 ]] ; then
+ kill -TTOU $master_pid
+elif [[ "$decrease_flag" -eq 1 ]] ; then
+ kill -TTOU $master_pid
+elif [[ "$logs_flag" -eq 1 ]] ; then
+ kill -USR1 $master_pid
+elif [[ "$reload_flag" -eq 1 ]] ; then
+ kill -HUP $master_pid
+else
+ :
+fi
+ return $?
View
30 scripts/rails
@@ -0,0 +1,30 @@
+#!/usr/bin/env bash
+
+#
+# Rails
+#
+migrate() {
+ builtin cd $current_path
+ rake db:migrate --trace
+}
+
+console() {
+ builtin cd $current_path
+ if [[ -f script/console ]] ; then ruby script/console ; fi
+}
+
+dbconsole() {
+ builtin cd $current_path
+ if [[ -f script/console ]] ; then ruby script/dbconsole ; fi
+}
+
+restart() { eval "${server} restart" ; }
+start() { eval "${server} start" ; }
+stop() { eval "${server} stop" ; }
+
+bootstrap() {
+ # rake gems:install
+ # rvm gems load
+ # rake db:create
+ # rake db:migrate
+}
View
37 scripts/setup
@@ -0,0 +1,37 @@
+#!/usr/bin/env bash
+
+if [[ "root" = $(whoami) ]] ; then
+ echo "Must be run as the project user."
+ exit 1
+fi
+
+for dir in config log pids sockets "public/assets" tmp ; do
+ mkdir -p "$HOME/shared/$dir"
+done
+
+touch $HOME/shared/config/database.yml
+
+touch $HOME/.bash_profile
+
+if ! awk "/^project/" "$HOME/.bash_profile" ; then
+ echo "project=\"$(user)\" ; export project" >> $HOME/.bdsmrc
+fi
+
+if ! awk "/^environment/" "$HOME/.bash_profile" ; then
+ echo "environment=\"production\" ; export environment" >> $HOME/.bdsmrc
+fi
+
+if ! awk "/^RAILS_ENV/" "$HOME/.bash_profile" ; then
+ echo "RAILS_ENV=\"\$environment\" ; export RAILS_ENV" >> $HOME/.bdsmrc
+fi
+
+if ! awk '/current\/\.rvmrc/' "$HOME/.bash_profile" ; then
+ echo 'if [[ -d $HOME/current ]] && [[ -f $HOME/current/.rvmrc ]] ; then source $HOME/current/.rvmrc ; fi' >> $HOME/.bdsmrc
+fi
+
+if [[ ! -s "$HOME/.rvm/scripts/rvm" ]] ; then
+ git clone git://github.com/wayneeseguin/rvm.git && cd rvm && ./install
+fi
+
+echo -e "$project: &defaults\n adapter: postgresql\n username: $project\n password: '$project'\n database: ${project}_${environment}\n pool: 5\n timeout: 5000" >> $HOME/shared/config/database.yml
+
View
0 scripts/sinatra
No changes.
View
41 scripts/thin
@@ -0,0 +1,41 @@
+#!/usr/bin/env bash
+
+#
+# Thin
+#
+
+builtin cd $current_path
+if [ -f ".bdsmrc" ] ; then source .bdsmrc ; fi
+if [ -f ".${project}rc" ] ; then source ".${project}rc" ; fi
+
+master_pid="$(ps auxww | grep '[m]ongrel' | awk '/'${project}'/{print $2}')"
+if [[! -z "$master_pid"]] && [[ $master_pid -gt 0 ]] ; then
+ thin restart
+else # start
+ thin start
+fi
+
+builtin cd $project_path
+case "$1" in
+ #trap "TERM" { log "TERM signal received."; stop }
+ #trap "USR1" {log "USR1 received, toggling $thin_debug_client to #{!$thin_debug_client}"; $thin_debug_client = !$thin_debug_client }
+ # restart
+ #trap "USR2" { log "USR2 signal received."; stop(true) }
+
+ stop|graceful) kill -TERM $master_pid ;;
+ kill) kill -INT $master_pid ;;
+ logs) kill -USR1 $master_pid ;;
+ restart) kill -USR1 $master_pid ;;
+ increase) thin_adjust "increase" ;;
+ decrease) thin_adjust "decrease" ;;
+ start)
+
+ ;;
+ restart) thin start && sleep 1 && thin stop ;;
+esac
+
+thin_start() { thin -c $project_path/config/thin.rb -E $RAILS_ENV -D ; }
+thin_stop() { : ; }
+thin_stop() { : ; }
+thin_adjust() { : ; }
+
View
26 scripts/thinking_sphinx
@@ -0,0 +1,26 @@
+#!/usr/bin/env bash
+
+#
+# Sphinx
+#
+sphinx() {
+ sphinx_config_file="$current_path/config/$environment.sphinx.conf"
+ if [ -f $sphinx_config_file ] ; then
+ case "$1" in
+ stop) sphinx_stop ;;
+ start) sphinx_start ;;
+ index) sphinx_index ;;
+ restart)
+ sphinx_stop
+ sphinx_index
+ sphinx_start
+ ;;
+ esac
+ else
+ echo "$sphinx_config_file is missing, sphinx '$1' will not be performed."
+ fi
+}
+sphinx_index() { builtin cd $current_path ; rake thinking_sphinx:index ; }
+sphinx_stop() { builtin cd $current_path ; rake thinking_sphinx:stop ; }
+sphinx_start() { builtin cd $current_path ; rake thinking_sphinx:start ; }
+
View
43 scripts/unicorn
@@ -0,0 +1,43 @@
+#!/usr/bin/env bash
+
+#
+# Unicorn
+#
+master_pid="$(ps auxww | grep '[u]nicorn' | grep 'master' | awk '/'${project}'/{print $2}')"
+
+builtin cd $current_path
+
+if [[ "$start_flag" -eq 1 ]] ; then
+ unicorn_rails -c $current_path/config/unicorn.rb -E $RAILS_ENV -D
+ if [[ "$master_pid" -gt 0 ]] ; then
+ sleep 1 ; kill -QUIT $master_pid
+ fi
+ return $?
+elif [[ "$master_pid" -le 0 ]] ; then
+ echo "unicorn is not running for $project yet."
+ return 1
+elif [[ "$stop_flag" -eq 1 ]] || [[ "$graceful_flag" -eq 1 ]] ; then
+ kill -QUIT $master_pid
+elif [[ "$restart_flag" -eq 1 ]] ; then
+ kill -USR2 $master_pid
+ sleep 5
+ kill -QUIT $master_pid
+elif [[ "$pause_flag" -eq 1 ]] ; then
+ kill -WINCH $master_pid
+elif [[ "$unpause_flag" -eq 1 ]] ; then
+ kill -WINCH $master_pid
+elif [[ "$kill_flag" -eq 1 ]] ; then
+ kill -TERM $master_pid
+elif [[ "$increase_flag" -eq 1 ]] ; then
+ kill -TTOU $master_pid
+elif [[ "$decrease_flag" -eq 1 ]] ; then
+ kill -TTOU $master_pid
+elif [[ "$logs_flag" -eq 1 ]] ; then
+ kill -USR1 $master_pid
+elif [[ "$reload_flag" -eq 1 ]] ; then
+ kill -HUP $master_pid
+else
+ :
+fi
+
+exit $?

0 comments on commit 6fa5dc3

Please sign in to comment.
Something went wrong with that request. Please try again.