Add log function to ensure consistent output. Enhance regeneration of photo index files.
This commit is contained in:
parent
fcb091a164
commit
b4d9bae246
42
run.sh
42
run.sh
@ -21,6 +21,11 @@ function usage {
|
|||||||
exit $1
|
exit $1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function log {
|
||||||
|
message="$1"
|
||||||
|
echo -e "`date` - $message"
|
||||||
|
}
|
||||||
|
|
||||||
## Parameters ##
|
## Parameters ##
|
||||||
|
|
||||||
while getopts ':p:h' opt; do
|
while getopts ':p:h' opt; do
|
||||||
@ -43,11 +48,11 @@ cd $DIR
|
|||||||
|
|
||||||
sudo=""
|
sudo=""
|
||||||
if [[ $LOGNAME != "root" ]]; then
|
if [[ $LOGNAME != "root" ]]; then
|
||||||
echo "`date` - Using sudo since user is '$LOGNAME'."
|
log "Using sudo since user is '$LOGNAME'."
|
||||||
sudo="sudo"
|
sudo="sudo"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "`date` - Check if any system dependencies need installed."
|
log "Check if any system dependencies need installed."
|
||||||
if [[ ! `which php` ]]; then
|
if [[ ! `which php` ]]; then
|
||||||
echo "- Installing PHP"
|
echo "- Installing PHP"
|
||||||
$sudo apt-get install -y php-cli
|
$sudo apt-get install -y php-cli
|
||||||
@ -62,7 +67,7 @@ if [[ ! `which npm` ]]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Directories and allowed page types are executable, others are not.
|
# Directories and allowed page types are executable, others are not.
|
||||||
echo "`date` - Fix any strange file permissions."
|
log "Fix any strange file permissions."
|
||||||
find ./pages/ | while read file; do
|
find ./pages/ | while read file; do
|
||||||
if [[ $file == *".php" || $file == *".sh" || -d $file ]]; then
|
if [[ $file == *".php" || $file == *".sh" || -d $file ]]; then
|
||||||
mode=755
|
mode=755
|
||||||
@ -72,30 +77,43 @@ find ./pages/ | while read file; do
|
|||||||
chmod -c $mode $file
|
chmod -c $mode $file
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "`date` - Check if any node modules need updated/installed."
|
log "Check if any node modules need updated/installed."
|
||||||
npm install
|
npm install
|
||||||
|
|
||||||
# Reset generated index files.
|
# Reset generated index files.
|
||||||
echo "`date` - Removing old index files."
|
log "Removing old index files."
|
||||||
find files/photos/ -name "*".html -print -delete
|
find files/photos/ -name "*".html -print -delete
|
||||||
{
|
{
|
||||||
|
count=1
|
||||||
http_code=0
|
http_code=0
|
||||||
|
port="${ports%% *}"
|
||||||
|
if [[ -z $port ]]; then
|
||||||
|
port="8080"
|
||||||
|
fi
|
||||||
|
photos_uri=":$port/photos/"
|
||||||
while [[ $http_code != "200" ]]; do
|
while [[ $http_code != "200" ]]; do
|
||||||
sleep 1
|
log "Sleeping for '$count' while waiting for $photos_uri to come up."
|
||||||
echo "`date` - Checking if /photos/ is ready yet."
|
sleep $count
|
||||||
http_code="`curl --silent --fail --w '\n%{http_code}' localhost:8080/photos | tail -n 1`"
|
log "Checking if $photos_uri is available."
|
||||||
echo "`date` - Check for /photos/ responded with '$http_code'."
|
http_code="`curl --silent --fail --w '\n%{http_code}' localhost$photos_uri | tail -n 1`"
|
||||||
|
log "Check for $photos_uri responded with '$http_code'."
|
||||||
|
if (( $count >= 10 )); then
|
||||||
|
log "Giving up on loading $photos_uri after '$count' attempts."
|
||||||
|
break
|
||||||
|
else
|
||||||
|
count=$(( count + 1 ))
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
echo "`date` - Finished loading /photos/."
|
log "Finished checking for /photos/."
|
||||||
} &
|
} &
|
||||||
|
|
||||||
## Main ##
|
## Main ##
|
||||||
|
|
||||||
echo "`date` - Start website API."
|
log "Start website API."
|
||||||
node ./main.js $ports
|
node ./main.js $ports
|
||||||
status=$?
|
status=$?
|
||||||
|
|
||||||
## Finish ##
|
## Finish ##
|
||||||
|
|
||||||
echo "`date` - Exiting with status '$status'."
|
log "Exiting with status '$status'."
|
||||||
exit $status
|
exit $status
|
||||||
|
Loading…
x
Reference in New Issue
Block a user