Skip to content

Commit

Permalink
Merge pull request #187 from atlas-bi/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherpickering committed Jun 20, 2023
2 parents 72aca35 + 73d6f79 commit 80d14f7
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 21 deletions.
4 changes: 4 additions & 0 deletions src/_includes/installer/check_commands.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@ check_file() {
fmt_red "File $1 must be created before running this script. ${GREEN}See https://atlas.bi/docs/service/install" >&2
exit 1
fi
}

exporter() {
echo $1 | tee -a .env .env.local >/dev/null
}
17 changes: 11 additions & 6 deletions src/_includes/installer/hub/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ check_command pm2
check_command nginx
check_command lsof
check_command grep
check_command poetry
check_file config_cust.py
check_file "/etc/nginx/**/$APP.conf"

Expand Down Expand Up @@ -50,7 +51,7 @@ export FLASK_ENV=production
export FLASK_DEBUG=0

fmt_yellow "Installing node packages and building static resources.."
npm install --loglevel silent --no-fund --no-audit
npm install --loglevel error --no-fund --no-audit
.venv/bin/flask --app=web assets build


Expand All @@ -62,8 +63,6 @@ cp web/model.py scheduler/model.py
.venv/bin/flask --app=web db upgrade
.venv/bin/flask --app=web cli seed



# Set a few process names.
APP_PROCESS="$APP-$PORT"
RUNNER_PROCESS="$APP-runner-$RUNNER_PORT"
Expand All @@ -72,9 +71,9 @@ SCHEDULER_PROCESS="$APP-scheduler-$SCHEDULER_PORT"

fmt_yellow "Starting new services.."

APP_CMD=".venv/bin/gunicorn --worker-class=gevent --workers 3 --threads 30 --timeout 999999999 --access-logfile $(pwd)/logs/access.log --error-logfile $(pwd)/logs/error.log --capture-output --bind unix:web.sock --umask 007 web:app"
SCHEDULER_CMD=".venv/bin/gunicorn --worker-class=gevent --workers 1 --threads 30 --timeout 999999999 --access-logfile $(pwd)/logs/access.log --error-logfile $(pwd)/logs/error.log --capture-output --bind unix:scheduler.sock --umask 007 scheduler:app"
RUNNER_CMD=".venv/bin/gunicorn --worker-class=gevent --worker-connections=1000 --workers $(nproc --all) --threads 30 --timeout 999999999 --access-logfile $(pwd)/logs/access.log --error-logfile $(pwd)/logs/error.log --capture-output --bind unix:runner.sock --umask 007 runner:app"
APP_CMD=".venv/bin/gunicorn --worker-class=gevent --workers 3 --threads 30 --timeout 999999999 --access-logfile $(pwd)/logs/access.log --error-logfile $(pwd)/logs/error.log --capture-output --bind 0.0.0.0:$PORT --umask 007 web:app"
SCHEDULER_CMD=".venv/bin/gunicorn --worker-class=gevent --workers 1 --threads 30 --timeout 999999999 --access-logfile $(pwd)/logs/access.log --error-logfile $(pwd)/logs/error.log --capture-output --bind 0.0.0.0:$SCHEDULER_PORT --umask 007 scheduler:app"
RUNNER_CMD=".venv/bin/gunicorn --worker-class=gevent --worker-connections=1000 --workers $(nproc --all) --threads 30 --timeout 999999999 --access-logfile $(pwd)/logs/access.log --error-logfile $(pwd)/logs/error.log --capture-output --bind 0.0.0.0:$RUNNER_PORT --umask 007 runner:app"

echo $APP_CMD

Expand Down Expand Up @@ -129,6 +128,12 @@ echo ${YELLOW}Back folders can be manually removed. ${BLUE}rm -r $(pwd)/backup-*
echo ""

cat <<EOF
${CYAN}Current Configuration
${YELLOW}Web process was started with ${BLUE}pm2 start "$APP_CMD" --name="$APP_PROCESS"
${YELLOW}Scheduler process was started with ${BLUE}pm2 start "$SCHEDULER_CMD" --name="$SCHEDULER_PROCESS"
${YELLOW}Runner process was started with ${BLUE}pm2 start "$RUNNER_CMD" --name="$RUNNER_PROCESS"
${CYAN}Updating App Settings
${YELLOW}1. Update user configuration file ${BLUE}nano $(pwd)/config_cust.py
Expand Down
1 change: 1 addition & 0 deletions src/_includes/installer/service/cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ configure(){
pm2 list | grep -oP "atlas-service-((quirrel|meili)-)?\d+" | uniq | grep -oP "\d+" | uniq | while IFS=$'\n' read DIRECTORY; do
if [ -d "$DIRECTORY" ]; then
cp .env $DIRECTORY
cat .env.local >> .env
fi
done

Expand Down
45 changes: 30 additions & 15 deletions src/_includes/installer/service/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,40 +49,47 @@ APP_PROCESS="$APP-$PORT"
QUIRREL_PROCESS="$APP-quirrel-$QUIRREL_PORT"
MEILI_PROCESS="$APP-meili-$MEILI_PORT"

exporter WEB_PORT=$PORT
exporter QUIRREL_PORT=$QUIRREL_PORT
exporter MEILI_PORT=$MEILI_PORT

exporter APP_PROCESS=$APP_PROCESS
exporter QUIRREL_PROCESS=$QUIRREL_PROCESS
exporter MEILI_PROCESS=$MEILI_PROCESS

# Download meilisearch.
fmt_yellow "Installing meilisearch.."
curl -L https://install.meilisearch.com | sh


fmt_yellow "Starting new services.."

export PASSPHRASES=$QUIRREL_PROCESS
export DISABLE_TELEMETRY=1
export SESSION_SECRET=$APP_PROCESS
exporter PASSPHRASES=$QUIRREL_PROCESS
exporter DISABLE_TELEMETRY=1
exporter SESSION_SECRET=$APP_PROCESS

# Start quirrel and get a token.
PORT=$QUIRREL_PORT pm2 start node --name="$QUIRREL_PROCESS" -- node_modules/quirrel/dist/cjs/src/api/main.js
dotenv -v PORT=$QUIRREL_PORT -- pm2 start node --name="$QUIRREL_PROCESS" -- node_modules/quirrel/dist/cjs/src/api/main.js

# Set quirrel env vars.
export QUIRREL_TOKEN=$(curl --retry 5 --retry-delay 3 --retry-all-errors --connect-timeout 10 --user ignored:$QUIRREL_PROCESS -X PUT "localhost:$QUIRREL_PORT/tokens/prod")
export QUIRREL_API_URL=http://localhost:$QUIRREL_PORT
exporter QUIRREL_TOKEN=$(curl --retry 5 --retry-delay 3 --retry-all-errors --connect-timeout 10 --user ignored:$QUIRREL_PROCESS -X PUT "localhost:$QUIRREL_PORT/tokens/prod")
exporter QUIRREL_API_URL=http://localhost:$QUIRREL_PORT

# Load quirrel cron jobs.
npm run quirrel:ci

# Add a few env vars to get meilisearch running
export MEILI_NO_ANALYTICS=true
export MEILI_DB_PAT=$(pwd)/$PORT/data.ms/
export MEILI_ENV=production
export MEILI_MASTER_KEY=$MEILI_PROCESS
export MEILISEARCH_URL=http://localhost:$MEILI_PORT
export MEILI_HTTP_ADDR=localhost:$MEILI_PORT
exporter MEILI_NO_ANALYTICS=true
exporter MEILI_DB_PAT=$(pwd)/$PORT/data.ms/
exporter MEILI_ENV=production
exporter MEILI_MASTER_KEY=$MEILI_PROCESS
exporter MEILISEARCH_URL=http://localhost:$MEILI_PORT
exporter MEILI_HTTP_ADDR=localhost:$MEILI_PORT

# Start web process.
PORT=$PORT pm2 start npm -i -1 --name="$APP_PROCESS" -- run start
dotenv -v PORT=$PORT -- pm2 start npm -i -1 --name="$APP_PROCESS" -- run start

# Start meili process.
pm2 start meilisearch --name="$MEILI_PROCESS"
dotenv -- pm2 start meilisearch --name="$MEILI_PROCESS"

fmt_blue "Done setting up."
cd ..
Expand Down Expand Up @@ -127,6 +134,14 @@ echo ""
fmt_blue "Next Steps"

cat <<EOF
${CYAN}Current Configuration
${YELLOW}$(cat $PORT/.env.local)
${YELLOW}Web process was started with ${BLUE}dotenv -v PORT=$PORT -- pm2 start npm -i -1 --name="$APP_PROCESS" -- run start
${YELLOW}Quirrel process was started with ${BLUE}dotenv -v PORT=$QUIRREL_PORT -- pm2 start node --name="$QUIRREL_PROCESS" -- node_modules/quirrel/dist/cjs/src/api/main.js
${YELLOW}Meilisearch process was started with ${BLUE}dotenv -- pm2 start meilisearch --name="$MEILI_PROCESS"
${CYAN}Updating App Settings
${YELLOW}1. Update user configuration file ${BLUE}nano $(pwd)/.env
Expand Down

0 comments on commit 80d14f7

Please sign in to comment.