Skip to content

Commit

Permalink
#355: Refactor and fix crash loop.
Browse files Browse the repository at this point in the history
  • Loading branch information
FranSlot committed Apr 5, 2024
1 parent 4eb197b commit 3f42ba0
Showing 1 changed file with 54 additions and 37 deletions.
91 changes: 54 additions & 37 deletions RAP4USER/run-student-prototype.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,59 @@
# Exit immediately if a command exits with a non-zero status
set -e

# Put content of stdin to file script.adl
if [[ -n $RAP_DEPLOYMENT && $RAP_DEPLOYMENT == "Kubernetes" ]]; then
# Kubernetes
echo "$1" | base64 -d > /out.zip

main="$2"
else
# Docker-compose
read -r line

# Split the line into input1 and input2
zip="${line%% *}" # Everything before the first space
main="${line#* }" # Everything after the first space

echo -n $zip | base64 -d > /out.zip
fi

# Print script for debugging purposes
unzip /out.zip -d /out

entry=$(echo -n $main | base64 -d)

# First generate Ampersand proto from student script
ampersand proto /out/$entry \
--proto-dir=/var/www \
--verbose

chown -R www-data:www-data /var/www/data /var/www/generics

if [[ -n $RAP_DEPLOYMENT && $RAP_DEPLOYMENT == "Kubernetes" ]]; then
# Kubernetes: Start Apache webserver to run/serve prototype (foreground)
docker-php-entrypoint apache2-foreground
else
# Docker-compose: Start Apache webserver to run/serve prototype (background)
docker-php-entrypoint apache2-foreground &

# Sleep/wait 3600 sec
# Functions
decode_input(){
if [[ -n $RAP_DEPLOYMENT && $RAP_DEPLOYMENT == "Kubernetes" ]]; then
echo "$1" | base64 -d > /out.zip

main="$2"
else
read -r line

# Split the line into input1 and input2
zip="${line%% *}" # Everything before the first space
main="${line#* }" # Everything after the first space

echo -n $zip | base64 -d > /out.zip
fi
}

unzip_content(){
unzip /out.zip -d /out
}

set_entry(){
entry=$(echo -n $main | base64 -d)
}

generate_prototype() {
ampersand proto "/out/$entry" --proto-dir=/var/www --verbose
}

set_permissions() {
chown -R www-data:www-data /var/www/data /var/www/generics
}

start_apache() {
if [[ -n $RAP_DEPLOYMENT && $RAP_DEPLOYMENT == "Kubernetes" ]]; then
docker-php-entrypoint apache2-foreground
else
docker-php-entrypoint apache2-foreground &
sleep 3600
fi
}

# Code run on startup
# We check if there are any args, to prevent the pod from crashing and restarting ad infinitum when there are no arguments given (like when using the pod to pre-pull the image).
# If none are given just sleep for 3600 secs (1 hour).
if [ $# -eq 0 ]; then
echo "No arguments supplied"
sleep 3600
else
decode_input "$1" "$2"
unzip_content
set_entry
generate_prototype
set_permissions
start_apache
fi

0 comments on commit 3f42ba0

Please sign in to comment.