#!/usr/bin/env bash

adduser --disabled-password --gecos "" pipedream
passwd -d pipedream && \
usermod -aG sudo pipedream

slurm_dir="/slurm"
mkdir -p ${slurm_dir}
chmod 400 ${slurm_dir}
chmod 0400 ${key_path}
chown -R pipedream:pipedream ${slurm_dir}

if [[ -z "$@" ]]; then
    # DO NOT ENABLE THREADING. Each process has a cache and assumes single-threaded access.
    # Also set header size to max uint16 to accept large query parameters.
    exec uwsgi --http-socket 0.0.0.0:80 \
               --drop-after-init \
               --uid root \
               --gid root \
               --master \
               --buffer-size 65535 \
               --processes ${UWSGI_NUM_PROCESSES:-8} \
               --need-app --module pipedream_accounting.wsgi:app
else
    exec $@
fi
