diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..7e78c36e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +releases/ diff --git a/VERSION b/VERSION deleted file mode 100644 index 22ecddcb..00000000 --- a/VERSION +++ /dev/null @@ -1,4 +0,0 @@ ---- -:major: 0 -:minor: 0 -:patch: 0 diff --git a/bin/bdsm b/bin/bdsm index 029df12a..4bc3ef6c 100755 --- a/bin/bdsm +++ b/bin/bdsm @@ -1,6 +1,9 @@ -#!/bin/bash +#!/usr/bin/env bash # Author: Wayne E. Seguin +# All Rights Reserved + +VERSION=0.0.1 # # Environment @@ -83,28 +86,35 @@ setup() { # deploy() { log "info" "Deploying..." - update_repository && - update_current && - configure && - symlink && - cleanup - if [[ -f "$current_dir/.post_deploy" ]] ; then - chmod +x "$current_dir/.post_deploy" - $current_dir/.post_deploy - fi - + ( + 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/$application." + 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 @@ -128,7 +138,7 @@ update_current() { mv $current_dir $HOME/previous/$timestamp fi log "Installing new release to $current_dir" - rsync -ag --exclude=".git/*" $shared_path/$application/ $current_dir; + rsync -ag --exclude=".git/*" $shared_path/$project/ $current_dir; } configure() { @@ -142,29 +152,30 @@ configure() { log "Setting up persistent config files:" for config_file in $(ls $shared_path/config/*.conf); do - log " - $config_file" - rm -f $current_dir/config/$config_file - ln -nfs $shared_path/config/$config_file $current_dir/config/$config_file + 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 - log " - $config_file" - rm -f $current_dir/config/$config_file - ln -nfs $shared_path/config/$config_file $current_dir/config/$config_file + 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" - shared_dirs="log public/assets pids files" - for shared_dir in $shared_dirs ; do - if [ -d $shared_path/$shared_dir ] ; then - log " - $shared_dir" - rm -rf $current_dir/$shared_dir - ln -nfs $shared_path/$shared_dir $current_dir/$shared_dir + 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 " $shared_path/$shared_dir does not exist, skipping." + log " $shared_path/$dir does not exist, skipping." fi done } @@ -233,18 +244,18 @@ migrate() { console() { cd $current_dir - if [[ -f script/console ]] ; then - ruby script/console - fi + if [[ -f script/console ]] ; then ruby script/console ; fi } dbconsole() { cd $current_dir - if [[ -f script/console ]] ; then - ruby script/dbconsole - fi + if [[ -f script/console ]] ; then ruby script/dbconsole ; fi } +restart() { eval "${server} restart" ; } +start() { eval "${server} start" ; } +stop() { eval "${server} stop" ; } + # # Unicorn # @@ -356,7 +367,7 @@ while [ $# -gt 0 ] ; do token="$1" ; shift case "$token" in - nginx|apache|sphinx|solr|unicorn|mongrel|thin|passenger) + nginx|apache|sphinx|solr|unicorn|mongrel|thin|passenger|setup) server=$token action=${action:-$token} ;; @@ -369,13 +380,9 @@ while [ $# -gt 0 ] ; do action=$token ;; - --trace) - trace_flag=1 ; debug_flag=1 ; set -x - ;; - - --debug) - debug_flag=1 - ;; + --trace) trace_flag=1 ; debug_flag=1 ; set -x ;; + --debug) debug_flag=1 ;; + --version) action="version" ;; *) if [[ -z "$action" ]] ; then @@ -405,8 +412,7 @@ function version { _author="Wayne E. Seguin" _author_email="wayneeseguin@gmail.com" _website="http://bdsm.beginrescueend.com/" - _version="0.0.1" - #_version="$(cat $bdsm_path/lib/VERSION.yml | tail -n 3 | sed 's/^.*: //g' | tr "\n" '.' | sed 's/\.$//')" + _version="$VERSION" echo -e "bdsm ${_version} ${_website} by ${_author} (${_author_email})" } @@ -446,13 +452,18 @@ Notes: if [[ "$trace_flag" = 1 ]] ; then set -x ; else set +x ; fi result=0 case "$action" in - unicorn) unicorn ;; - mongrel) unicorn ;; - thin) unicorn ;; - sphinx) sphinx ;; - restart) unicorn ;; - deploy) deploy ;; - *) usage ;; + setup) setup ;; + console) console ;; + dbconsole) dbconsole ;; + logtail) logtail ;; + version) version ;; + unicorn) unicorn ;; + mongrel) mongrel ;; + thin) thin ;; + sphinx) sphinx ;; + restart) restart ;; + deploy) deploy ;; + *) usage ;; esac result=$? exit $result diff --git a/bin/console b/bin/console deleted file mode 100755 index 23298816..00000000 --- a/bin/console +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -# Author: Wayne E. Seguin - -bdsm migrate $* - diff --git a/bin/dbconsole b/bin/dbconsole deleted file mode 100755 index 23298816..00000000 --- a/bin/dbconsole +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -# Author: Wayne E. Seguin - -bdsm migrate $* - diff --git a/bin/deploy b/bin/deploy deleted file mode 100755 index d3a8638b..00000000 --- a/bin/deploy +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash -# -# Author: Wayne E. Seguin -# Version: 0.0.6 -# -bdsm deploy "$*" diff --git a/bin/logtail b/bin/logtail deleted file mode 100755 index 2fa38993..00000000 --- a/bin/logtail +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -bdsm logtail "$*" - diff --git a/bin/migrate b/bin/migrate deleted file mode 100755 index 277b6695..00000000 --- a/bin/migrate +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -# Author: Wayne E. Seguin - -bdsm migrate $* - diff --git a/bin/restart b/bin/restart deleted file mode 100755 index 3f059fd7..00000000 --- a/bin/restart +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -# Author: Wayne E. Seguin -# Version: 0.0.2 - -bdsm restart $* -