I am using an old machine as a webserver to host a static, code-generated site (the site serves HTML documentation, JS, PDFs and images). The old machine, along with development PC are on a home network, and connected to a single modem.
General advice that addresses the questions below would be appreciated:
1. How can the bash script below be extended deploy to the old machine on my network?
2. Do any iptables
rules need to created? (especially wrt. to #3)
3. How can the script be extended in future to be used in a production environment and/or allow access to the site outside the home network?
#! /bin/bash
# deploy.sh
# Note: This script must be run as root or sudo, assumes the user
# $WEBSERVER is created, and that thttpd is installed.
DEVELOP_ENV="/home/me/www" # localhost www dir
STAGING_ENV="half_broken_server/www" # target host www dir to deploy to
WEBSERVER="thttpd" # webserver user
function usage {
printf "deploy [options...] [STAGING|DEVELOP]\n"
}
if [[ "$1" == "STAGING" ]]; then
# prompt before deploying to staging
read -p "Deploy to staging server?" -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Abort"
exit 1
fi
echo "TODO: Ask StackExchange for help with this part"
elif [[ "$1" == "DEVELOP" ]]; then
if [ -d dist ]; then
# make www directory if it does not exist
if [ ! -d `dirname $DEV_ENV` ]; then
mkdir -p $DEVELOP_ENV
fi
# copy all files to be served from dist
cp -rf dist/* $DEVELOP_ENV
fi
# grant read-only perms to local network users
chmod -R 744 $DEVELOP_ENV
# restart the thttpd webserver process (if it is running)
killall thttpd
$WEBSERVER -u $WEBSERVER -d $DEVELOP_ENV
echo "Deployment sucessful!"
else
usage
fi
The bash script copies files from a dir called dist
to one of DEVELOP
or STAGING
environments so that on a local network content will be served from this dir and accessed at myuser@hostname
or just hostname/
per /etc/host
config.
Additional Details
The files being served are entirely code-generated (
HTML
/CSS
/JS
) fromC
,Lua
andBash
, andMake
and are constantly changing during buildsThe webserver is thttpd, running on a base installation of
Debian Wheezy
Preferred: standard
Unix
utilities (e.g.scp
,rsync
) over other deployment frameworks (e.g.Fabric
,Chef
,Vagrant
) or standard libraries from one of the languages mentioned aboveThe webserver is for personal project work, and is not expected to be used by others