Created
June 28, 2014 19:55
-
-
Save marek-saji/8ddb31b8dff2605bdbf4 to your computer and use it in GitHub Desktop.
Script for spinning up a vagrant box with rsync-auto and starting screen(1) with dev server. Both files live in project's subdirectory.
This file contains hidden or 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
# vim: ft=screen | |
altscreen on | |
# Set the caption on the bottom line | |
caption always "%{= kw}%-w%{= bW}%n %t%{-}%+w %-= %c %y-%m-%d, @%H" | |
# Use nethack-style messages | |
nethack on | |
source $HOME/.screenrc | |
chdir /vagrant | |
# Attach screen with server if not running, | |
# start new one otherwise (and hide caption) | |
screen 0 sh -c 'screen -x server || { ( sleep 1 ; screen -S server -X caption splitonly ; ) & screen -S server sh -c "node_modules/gulp/bin/gulp.js dev ; exec bash" ; }' | |
screen 1 sh -c 'while mysql ; do : ; done ; exec bash' | |
screen 2 sh -c "type git 2>&1 >/dev/null && test -d .git && git status ; printf '\n`Ctrl-A, D`, when you are done\n\n' ; exec bash" | |
select 0 | |
title server | |
select 1 | |
title mysql | |
select 2 |
This file contains hidden or 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
#!/bin/sh | |
BOX_NAME=dev | |
set -e | |
cry () | |
{ | |
if [ "0" = "${HAPPY_ENDING}" ] | |
then | |
export HAPPY_ENDING=1 | |
if ( which zenity 2>&1 >/dev/null ) | |
then | |
CMD="zenity --question --text" | |
else | |
CMD="xmessage -buttons yes:0,no:1" | |
fi | |
if ${CMD} "Put to sleep?" | |
then | |
vagrant suspend ${BOX_NAME} | |
fi | |
fi | |
} | |
kill_children () | |
{ | |
PPID=$1 | |
for CHILD_PID in $( ps -opid= --sort=start_time --ppid=${PPID} ) | |
do | |
if [ ${CHILD_PID} != ${PPID} ] | |
then | |
sh -c "sleep 0.1 ; kill -9 ${CHILD_PID}" & | |
kill_children ${CHILD_PID} | |
fi | |
done | |
} | |
trap 'cry ; kill_children $$' INT TERM QUIT EXIT HUP | |
cd "$( dirname "$0" )/.." | |
if ! vagrant list-commands | grep -q ^gatling-rsync-auto | |
then | |
vagrant plugin install vagrant-gatling-rsync | |
fi | |
vagrant up ${BOX_NAME} | |
if grep -q rsync Vagrantfile | |
then | |
vagrant rsync ${BOX_NAME} | |
echo > ~/.cache/vagrant-${BOX_NAME}-rsync-auto.log | |
sh -c ' | |
while true | |
do | |
sleep 3 | |
notify-send \ | |
--icon=info \ | |
--app-name=${BOX_NAME} \ | |
--hint=int:transient:1 \ | |
-- "Spinning up rsync-auto" | |
vagrant gatling-rsync-auto ${BOX_NAME} 2>&1 >> ~/.cache/vagrant-${BOX_NAME}-rsync-auto.log || : | |
sleep 3 | |
if vagrant status ${BOX_NAME} | grep -q running | |
then | |
notify-send \ | |
--icon=error \ | |
--app-name=${BOX_NAME} \ | |
--hint=int:transient:1 \ | |
-- "rsync-auto crashed, restarting in 3s" | |
else | |
notify-send \ | |
--icon=info \ | |
--app-name=${BOX_NAME} \ | |
--hint=int:transient:1 \ | |
-- "rsync-auto crashed, NOT restarting" | |
fi | |
done | |
' & | |
fi | |
node_modules/.bin/start-selenium >> ~/.cache/vagrant-${BOX_NAME}-selenium.log 2>&1 & | |
export HAPPY_ENDING=0 | |
vagrant ssh ${BOX_NAME} -c " | |
LC_ALL=$LANG | |
screen -Dr ${BOX_NAME} || screen -S ${BOX_NAME} -c /vagrant/dev/.screenrc | |
" | |
export HAPPY_ENDING=1 | |
printf 'Will suspend in (Ctrl-C to abort) 3' | |
sh -c 'printf … ; sleep 1 ; printf " 2…" ; sleep 1 ; printf " 1.\n"' & | |
sleep 3 && vagrant suspend ${BOX_NAME} || : |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment