Generate all content in public/ before server starts.
Introduces a delay first time the server is started, but makes all resources available to jammit. Can be disabled by flag in config/server.sh. Hopefully silences jammit's messages about application.css et. al. not found
This commit is contained in:
parent
287b79ab17
commit
df31de2898
2 changed files with 28 additions and 2 deletions
|
|
@ -11,3 +11,7 @@ export RAILS_ENV='development'
|
||||||
|
|
||||||
# See thin -h for possible values.
|
# See thin -h for possible values.
|
||||||
DEFAULT_THIN_ARGS="-p $THIN_PORT -e $RAILS_ENV"
|
DEFAULT_THIN_ARGS="-p $THIN_PORT -e $RAILS_ENV"
|
||||||
|
|
||||||
|
# Set to 'no' to disable server dry-run at first start
|
||||||
|
# creating generated files in public/ folder.
|
||||||
|
#INIT_PUBLIC='no'
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,25 @@ cd $( dirname $realpath)/..
|
||||||
|
|
||||||
[ -e config/server.sh ] && source config/server.sh
|
[ -e config/server.sh ] && source config/server.sh
|
||||||
|
|
||||||
|
function init_public
|
||||||
|
# Create all dynamically generated files in public/ folder
|
||||||
|
{
|
||||||
|
bundle exec thin \
|
||||||
|
-d --pid log/thin.pid --address localhost --port $THIN_PORT \
|
||||||
|
start
|
||||||
|
for ((i = 0; i < 20; i += 1)) do
|
||||||
|
sleep 2
|
||||||
|
wget -q -O tmp/server.html http://localhost:$THIN_PORT && \
|
||||||
|
rm tmp/server.html && break
|
||||||
|
done
|
||||||
|
bundle exec thin --pid log/thin.pid stop
|
||||||
|
if [ -e tmp/server.html ]; then
|
||||||
|
echo "Cannot get index.html from web server (aborted)" >&2
|
||||||
|
return 2
|
||||||
|
fi
|
||||||
|
bundle exec jammit
|
||||||
|
}
|
||||||
|
|
||||||
# Scan for -p, find out what port thin is about to use.
|
# Scan for -p, find out what port thin is about to use.
|
||||||
args="$DEFAULT_THIN_ARGS $@"
|
args="$DEFAULT_THIN_ARGS $@"
|
||||||
prev_arg=''
|
prev_arg=''
|
||||||
|
|
@ -49,8 +68,11 @@ if [ ! -e public/source.tar.gz ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Precache jammit assets
|
# Precache jammit assets
|
||||||
if [ -w public ]; then
|
if [[ -w public && ! -e public/stylesheets/application.css ]]; then
|
||||||
bundle exec jammit
|
if [ "$INIT_PUBLIC" != 'no' ]; then
|
||||||
|
echo "Making first-time server initialization."
|
||||||
|
init_public
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
if [ ! -e 'public/assets/main.js.gz' ]; then
|
if [ ! -e 'public/assets/main.js.gz' ]; then
|
||||||
echo 'Jammit precache error (now or at install)' >&2
|
echo 'Jammit precache error (now or at install)' >&2
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue