|
1 | | -#!/usr/bin/env sh |
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set -euo pipefail |
| 4 | + |
| 5 | +. "$(dirname "${BASH_SOURCE[0]}")/../../scripts/lib.sh" |
2 | 6 |
|
3 | 7 | # Create S3 dirs |
4 | | -mkdir -p /srv/philomena/priv/static/system/images/thumbs |
5 | | -mkdir -p /srv/philomena/priv/s3/philomena |
6 | | -ln -sf /srv/philomena/priv/static/system/images/thumbs /srv/philomena/priv/s3/philomena/images |
7 | | -ln -sf /srv/philomena/priv/static/system/images /srv/philomena/priv/s3/philomena/adverts |
8 | | -ln -sf /srv/philomena/priv/static/system/images /srv/philomena/priv/s3/philomena/avatars |
9 | | -ln -sf /srv/philomena/priv/static/system/images /srv/philomena/priv/s3/philomena/badges |
10 | | -ln -sf /srv/philomena/priv/static/system/images /srv/philomena/priv/s3/philomena/tags |
| 8 | +step mkdir -p /srv/philomena/priv/static/system/images/thumbs |
| 9 | +step mkdir -p /srv/philomena/priv/s3/philomena |
| 10 | +step ln -sf /srv/philomena/priv/static/system/images/thumbs /srv/philomena/priv/s3/philomena/images |
| 11 | +step ln -sf /srv/philomena/priv/static/system/images /srv/philomena/priv/s3/philomena/adverts |
| 12 | +step ln -sf /srv/philomena/priv/static/system/images /srv/philomena/priv/s3/philomena/avatars |
| 13 | +step ln -sf /srv/philomena/priv/static/system/images /srv/philomena/priv/s3/philomena/badges |
| 14 | +step ln -sf /srv/philomena/priv/static/system/images /srv/philomena/priv/s3/philomena/tags |
11 | 15 |
|
12 | 16 | # For compatibility with musl libc |
13 | 17 | export CARGO_FEATURE_DISABLE_INITIAL_EXEC_TLS=1 |
14 | 18 | export CARGO_HOME=/srv/philomena/.cargo |
15 | 19 |
|
16 | 20 | background() { |
| 21 | + # Log the execution with (bg-jobs) prefix to differentiate it from the main process |
| 22 | + export TASK="bg-jobs" |
| 23 | + |
17 | 24 | while :; do |
18 | | - mix run -e 'Philomena.Release.update_channels()' > /dev/null |
19 | | - mix run -e 'Philomena.Release.verify_artist_links()' > /dev/null |
20 | | - mix run -e 'Philomena.Release.update_stats()' > /dev/null |
21 | | - mix run -e 'Philomena.Release.clean_moderation_logs()' > /dev/null |
22 | | - mix run -e 'Philomena.Release.generate_autocomplete()' > /dev/null |
| 25 | + step mix run -e 'Philomena.Release.update_channels()' > /dev/null |
| 26 | + step mix run -e 'Philomena.Release.verify_artist_links()' > /dev/null |
| 27 | + step mix run -e 'Philomena.Release.update_stats()' > /dev/null |
| 28 | + step mix run -e 'Philomena.Release.clean_moderation_logs()' > /dev/null |
| 29 | + step mix run -e 'Philomena.Release.generate_autocomplete()' > /dev/null |
23 | 30 |
|
24 | 31 | sleep 300 |
25 | 32 | done |
26 | 33 | } |
27 | 34 |
|
28 | 35 | # Always install assets |
29 | 36 | ( |
30 | | -cd /srv/philomena/assets |
31 | | -npm install |
| 37 | + step cd /srv/philomena/assets |
| 38 | + step npm install |
32 | 39 | ) |
33 | 40 |
|
34 | 41 | # Always install mix dependencies |
35 | | -(cd /srv/philomena && mix deps.get) |
| 42 | +( |
| 43 | + step cd /srv/philomena |
| 44 | + step mix deps.get |
| 45 | +) |
36 | 46 |
|
37 | 47 | # Sleep to allow OpenSearch to finish initializing |
38 | 48 | # if it's not done doing whatever it does yet |
39 | | -echo -n "Waiting for OpenSearch" |
| 49 | +info "Waiting for OpenSearch" |
40 | 50 |
|
41 | | -until wget --no-check-certificate -qO - http://opensearch:9200; do |
42 | | - echo -n "." |
| 51 | +until step wget --no-check-certificate -qO - http://opensearch:9200; do |
43 | 52 | sleep 2 |
44 | 53 | done |
45 | 54 |
|
46 | | -echo |
47 | | - |
48 | 55 | # Try to create the database if it doesn't exist yet |
49 | | -createdb -h postgres -U postgres philomena_dev && mix ecto.setup_dev && mix reindex_all |
| 56 | +if step createdb -h postgres -U postgres philomena_dev; then |
| 57 | + step mix ecto.setup_dev |
| 58 | + step mix reindex_all |
| 59 | +fi |
50 | 60 |
|
51 | 61 | # Explicitly compile deps to avoid racing |
52 | | -mix compile |
| 62 | +step mix compile |
53 | 63 |
|
54 | 64 | # Run background jobs |
55 | 65 | background & |
56 | 66 |
|
| 67 | +info "Starting the server" |
| 68 | + |
57 | 69 | # Run the application |
58 | 70 | START_WORKER=true exec mix phx.server |
0 commit comments