expand readme, add service files

parent 17ddf5bc
......@@ -27,11 +27,94 @@ We use Flask-AppConfig, as such various config values can be found in
**Remember to update the `SECRET_KEY`, use some random value before using
this app in production!**
### ReCaptcha
This application can make use of ReCaptcha for all forms (including admin
login). Generate a the ReCaptacha keys and add these to the `default_config.py`
file.
### Webserver Setup
To run this app in a production environment one needs to proxy the Python driven process
through a webserver. For this I use Nginx together with uWSGI to handle the Python process.
In this example, I have cloned the app into `/srv/http/lb/codefuboard`. Additionally I created
a system user `codefu` which will _run_ the app. The uWSGI configuration for this is below:
```ini
[uwsgi]
strict = true
plugins = python
chdir = /srv/http/lb/codefuboard
module = wsgi
callable = app
master = true
processes = 4
threads = 2
vacuum = true ; Delete sockets during shutdown
single-interpreter = true
die-on-term = true
need-app = true
enable-threads = true
buffer-size = 65535
lazy = true
chmod-socket = 775
socket = /srv/http/lb/run/%n.sock
pidfile = /srv/http/lb/run/.pid
disable-logging = false
log-4xx = true
log-5xx = true
logto = /srv/http/lb/log/%n.log
uid = codefu
gid = codefu
```
I then setup Nginx with the following server configuration:
```nginx
server {
server_name <SERVER DOMAIN>;
#charset koi8-r;
#access_log logs/host.access.log main;
root /srv/http/lb;
error_log /srv/http/lb/log/error.log;
access_log /srv/http/lb/log/access.log;
location / {
try_files $uri @context;
}
location /leaderboard/ {
rewrite ^/leaderboard/(.*)$ /lb/$1 permanent;
}
location @context {
include uwsgi_params;
uwsgi_pass unix:/srv/http/lb/run/lb.sock;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
```
### Database
The app was initially built supporting pickledb as its db-backend. This proved
not to scale well at all in production. So I moved it to use Redis together with
MsgPack. The latter can encode most Python structures into strings, making it easy
to store complex structures in Redis.
Todo
====
- fix the HUGE variability of runtime measurements!
- support notion of students and teams
- teams need to pre-register?
- admin panel?
- to modify db mainly (external scripts?)
[Unit]
Description=CodeFu watcher
After=network-online.target
[Service]
ExecStart=/home/codefu/watch-codefu.sh
Restart=always
RestartSec=2
User=codefu
Group=codefu
[Install]
WantedBy=multi-user.target
#!/usr/bin/env bash
SBATCH="/cm/shared/apps/slurm/17.11.12/bin/sbatch"
inotifywait -m /home/codefu/codefu/jobs -e create -e moved_to |
while read path action file; do
echo "detected change ($action) in $path$file..."
sleep 5 # really?!
if [ -e "$path$file/.type-cseq" ]; then
echo "launching sbatch for C-seq"
if $SBATCH -D "$path$file" -J "codefu c $file" /home/codefu/git/codefuboard/scripts/run-c-opt.sh "$file"; then
touch "$path$file/.RUNNING"
else
echo "Unable to launch SBATCH script!" >> "${path}${file}/log"
touch "$path$file/.ERROR"
fi
elif [ -e "$path$file/.type-omp" ]; then
echo "launching sbatch for OMP"
if $SBATCH -D "$path$file" -J "codefu omp $file" /home/codefu/git/codefuboard/scripts/run-openmp.sh "$file"; then
touch "$path$file/.RUNNING"
else
echo "Unable to launch SBATCH script!" >> "${path}${file}/log"
touch "$path$file/.ERROR"
fi
elif [ -e "$path$file/.type-mpi" ]; then
echo "launching sbatch for MPI"
if $SBATCH -D "$path$file" -J "codefu mpi $file" /home/codefu/git/codefuboard/scripts/run-mpi.sh "$file"; then
touch "$path$file/.RUNNING"
else
echo "Unable to launch SBATCH script!" >> "${path}${file}/log"
touch "$path$file/.ERROR"
fi
elif [ -e "$path$file/.type-openclcpu" ]; then
echo "launching sbatch for OpenCL CPU"
if $SBATCH -D "$path$file" -J "codefu clcpu $file" /home/codefu/git/codefuboard/scripts/run-opencl-cpu.sh "$file"; then
touch "$path$file/.RUNNING"
else
echo "Unable to launch SBATCH script!" >> "${path}${file}/log"
touch "$path$file/.ERROR"
fi
elif [ -e "$path$file/.type-openclgpu" ]; then
echo "launching sbatch for OpenCL GPU"
if $SBATCH -D "$path$file" -J "codefu clgpu $file" /home/codefu/git/codefuboard/scripts/run-opencl-gpu.sh "$file"; then
touch "$path$file/.RUNNING"
else
echo "Unable to launch SBATCH script!" >> "${path}${file}/log"
touch "$path$file/.ERROR"
fi
fi
done
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment